From d5fbe1b629c81a58c321148d165e5fb91ac8961a Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Wed, 2 Jan 2019 23:41:04 +0100 Subject: [PATCH] Do not ask admin password just for help documentation It is not a good idea to ask for an admin password just to get the command documentation. "pihole -h" should return the arguments documentation with no need to enter a password. Without the patch I get: $ ./pihole -h Password: It is easy to reproduce by invalidating the sudo password using "sudo -k" before running pihole again. Signed-off-by: Ludovic Rousseau --- pihole | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/pihole b/pihole index d4681752..fff3417d 100755 --- a/pihole +++ b/pihole @@ -23,17 +23,6 @@ source "${colfile}" resolver="pihole-FTL" -# Must be root to use this tool -if [[ ! $EUID -eq 0 ]];then - if [[ -x "$(command -v sudo)" ]]; then - exec sudo bash "$0" "$@" - exit $? - else - echo -e " ${CROSS} sudo is needed to run pihole commands. Please run this script as root or install sudo." - exit 1 - fi -fi - webpageFunc() { source "${PI_HOLE_SCRIPT_DIR}/webpage.sh" main "$@" @@ -430,6 +419,21 @@ if [[ $# = 0 ]]; then helpFunc fi +case "${1}" in + "-h" | "help" | "--help" ) helpFunc;; +esac + +# Must be root to use this tool +if [[ ! $EUID -eq 0 ]];then + if [[ -x "$(command -v sudo)" ]]; then + exec sudo bash "$0" "$@" + exit $? + else + echo -e " ${CROSS} sudo is needed to run pihole commands. Please run this script as root or install sudo." + exit 1 + fi +fi + # Handle redirecting to specific functions based on arguments case "${1}" in "-w" | "whitelist" ) listFunc "$@";;