Skip to content

Commit

Permalink
Check early for sudo.
Browse files Browse the repository at this point in the history
In case of uncached credentials the user will be prompted for credentials on startup.
  • Loading branch information
hsoerensen committed Apr 2, 2024
1 parent 39ab4cf commit 72a8a49
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
22 changes: 14 additions & 8 deletions bin/get-node-status
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions bin/migrate-from-host-setup
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
5 changes: 5 additions & 0 deletions bin/set-telemetry-name
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 72a8a49

Please sign in to comment.