Skip to content

Commit 6690130

Browse files
committed
Verify that 'sudo' is present before assuming we can use it
1 parent 1ca76af commit 6690130

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

format-udf.sh

+13-1
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,24 @@
2424
# setup Bash environment
2525
set -euf -o pipefail
2626

27-
# setup sudo
27+
28+
# handle following scenarios:
29+
# * unprivileged user (i.e. not root, sudo not used)
30+
# * privileged user (i.e. not root, sudo used)
31+
# * root user (i.e. sudo not used)
2832
SUDO=''
2933
if [[ $(id -u) -ne 0 ]]; then
34+
# verify that 'sudo' is present before assuming we can use it
35+
if [[ ! -x $(which sudo 2>/dev/null) ]]; then
36+
echo "[-] Dependencies unmet. Please verify that 'sudo' is installed, executable, and in the PATH." >&2
37+
echo "Alternatively, you may also re-run this script as root." >&2
38+
exit 1
39+
fi
40+
3041
SUDO='sudo'
3142
fi
3243

44+
3345
###############################################################################
3446
# constants
3547
###############################################################################

0 commit comments

Comments
 (0)