Skip to content

Commit

Permalink
Simplify sudo check require it always.
Browse files Browse the repository at this point in the history
Check for sudo and prompt If NOT
>Note: Will need sudo privileges to run help messages.
Caveat:

- Breaks in serve_doc can be removed not used or moved to tools for future use.
  • Loading branch information
Tearran authored and igorpecovnik committed Oct 13, 2024
1 parent 5d68010 commit 9be0d05
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions bin/armbian-configng
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ json_file="$lib_dir/config.ng.jobs.json"
# Load The Bash procedure Objects
json_data=$(<"$json_file")

# Check if help or doc otherwise run sudo -E
[[ $EUID != 0 ]] && exec sudo "$0" "$@"
#
# 'whiptail' is a simple dialog box utility that works well with Bash. It doesn't have all the features of some other dialog box utilities, but it does everything we need for this script.
[[ -x "$(command -v whiptail)" ]] && DIALOG="whiptail"
Expand Down Expand Up @@ -76,21 +78,11 @@ case "$1" in
exit 0
;;
"--doc")
if [[ $EUID != 0 ]]; then
generate_readme
exit 0
else
echo "Error: You must run this command as a normal user"
exit 1
fi
generate_readme
exit 0
;;
"--cmd")
INPUTMODE="cmd"
if [[ $EUID != 0 ]]; then
echo "Error: Requires root privileges. Please run as root or use sudo."
exit 1
fi

shift
if [[ -z "$1" || "$1" == "help" ]]; then
see_cmd_list
Expand All @@ -102,10 +94,6 @@ case "$1" in
exit 0
;;
"--api")
if [[ $EUID != 0 ]]; then
echo "Error: The --api option requires root privileges. Please run as root or use sudo."
exit 1
fi
shift
if [[ -z "$1" || "$1" == "help" ]]; then
see_use
Expand Down

0 comments on commit 9be0d05

Please sign in to comment.