From 72a8a498cde45d61cc4407f9068cde3e0f969474 Mon Sep 17 00:00:00 2001 From: Henrik Soerensen Date: Mon, 1 Apr 2024 20:13:04 -0400 Subject: [PATCH] Check early for sudo. In case of uncached credentials the user will be prompted for credentials on startup. --- bin/get-node-status | 22 ++++++++++++++-------- bin/migrate-from-host-setup | 5 +++++ bin/set-telemetry-name | 5 +++++ install.sh | 5 +++++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/bin/get-node-status b/bin/get-node-status index 971b2e6..f87930c 100755 --- a/bin/get-node-status +++ b/bin/get-node-status @@ -1,15 +1,12 @@ #!/bin/bash +is_root=0 + execute_sudo() { - if sudo -v &> /dev/null; then - if [[ $(id -u) -eq 0 ]]; then - bash -c "$*" - else - sudo bash -c "$*" - fi + if [[ ${is_root} -eq 1 ]]; then + bash -c "$*" else - echo "The user does not have sudo privileges. Exiting the program." - exit 1 + sudo bash -c "$*" fi } @@ -73,6 +70,15 @@ if [ -z "${container_id}" ]; then exit 1 fi +if [[ $(id -u) -eq 0 ]]; then + is_root=1 +else + echo "Checking for sudo access, you may be prompted for your password." + if ! sudo -v &> /dev/null; then + abort "User does not have sudo access. Please run this script as a user with sudo access." + fi +fi + declare -A health_checks if [[ $(docker exec -it "${container_id}" bash -c "goal node status") ]]; then diff --git a/bin/migrate-from-host-setup b/bin/migrate-from-host-setup index 19fc724..dcf9d4a 100755 --- a/bin/migrate-from-host-setup +++ b/bin/migrate-from-host-setup @@ -17,6 +17,11 @@ fi if [[ $(id -u) -eq 0 ]]; then is_root=1 +else + echo "Checking for sudo access, you may be prompted for your password." + if ! sudo -v &> /dev/null; then + abort "User does not have sudo access. Please run this script as a user with sudo access." + fi fi echo "This script will assist migrating your node from a host-based setups to Voi Swarm, if your node is already running a Voi or Algorand based setup." diff --git a/bin/set-telemetry-name b/bin/set-telemetry-name index 95426dd..5c8d6d3 100755 --- a/bin/set-telemetry-name +++ b/bin/set-telemetry-name @@ -63,6 +63,11 @@ fi if [[ $(id -u) -eq 0 ]]; then is_root=1 +else + echo "Checking for sudo access, you may be prompted for your password." + if ! sudo -v &> /dev/null; then + abort "User does not have sudo access. Please run this script as a user with sudo access." + fi fi if [[ $1 && $2 ]]; then diff --git a/install.sh b/install.sh index 9f3cede..cc12771 100755 --- a/install.sh +++ b/install.sh @@ -804,6 +804,11 @@ fi if [[ $(id -u) -eq 0 ]]; then is_root=1 +else + echo "Checking for sudo access, you may be prompted for your password." + if ! sudo -v &> /dev/null; then + abort "User does not have sudo access. Please run this script as a user with sudo access." + fi fi # Get Linux OS distribution