Print help message if not running as root

This commit is contained in:
James Conroy
2021-12-07 21:55:45 -06:00
parent f807471a17
commit a048de65ca

View File

@@ -17,11 +17,6 @@
MYNAME="${0##*/}"
if ! [ "$(id -u)" = 0 ]; then
echo "${MYNAME}: This command must be run as root"
exit 1
fi
display_help() {
printf "%s" "${MYNAME}"
printf " [%s]" "-h" "-q|--quiet"
@@ -30,11 +25,13 @@ display_help() {
"h" "Show this message." \
"q,--quiet" "suppress the output and return a single status code of overall status"
printf "\nReturn Codes:\n"
printf "\t%s:%s\n" \
printf "\t%s - %s\n" \
"0" "Ok" \
"1" "Error" \
"2" "Starting/Pending"\
"99" "Installing SO"
# exit with code 0, unless passed a number when called
exit "${1:-0}"
}
# Constants
@@ -319,6 +316,19 @@ is_tty() {
return "${__tty}"
}
if ! [ "$(id -u)" = 0 ]; then
echo "${MYNAME}: This command must be run as root"
display_help 1
fi
while getopts ':hq' OPTION; do
case "$OPTION" in
h) display_help 0 ;;
q) QUIET=true ;;
\?) display_help 1 ;;
esac
done
main
exit $EXITCODE