mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-07-30 17:14:16 +02:00
Invert need_root logic and check if set/unset
Signed-off-by: Christian König <github@yubiuser.dev> Co-authored-by: Dan Schaper <dan.schaper@pi-hole.net>
This commit is contained in:
parent
29b6252935
commit
05f4ae7719
54
pihole
54
pihole
@ -542,7 +542,7 @@ if [[ $# = 0 ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# functions that do not require sudo power
|
# functions that do not require sudo power
|
||||||
need_root=1
|
need_root=
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
"-h" | "help" | "--help" ) helpFunc;;
|
"-h" | "help" | "--help" ) helpFunc;;
|
||||||
"-v" | "version" ) versionFunc;;
|
"-v" | "version" ) versionFunc;;
|
||||||
@ -552,30 +552,30 @@ case "${1}" in
|
|||||||
"tricorder" ) tricorderFunc;;
|
"tricorder" ) tricorderFunc;;
|
||||||
|
|
||||||
# we need to add all arguments that require sudo power to not trigger the * argument
|
# we need to add all arguments that require sudo power to not trigger the * argument
|
||||||
"allow" | "allowlist" ) need_root=0;;
|
"allow" | "allowlist" ) ;;
|
||||||
"deny" | "denylist" ) need_root=0;;
|
"deny" | "denylist" ) ;;
|
||||||
"--wild" | "wildcard" ) need_root=0;;
|
"--wild" | "wildcard" ) ;;
|
||||||
"--regex" | "regex" ) need_root=0;;
|
"--regex" | "regex" ) ;;
|
||||||
"--allow-regex" | "allow-regex" ) need_root=0;;
|
"--allow-regex" | "allow-regex" ) ;;
|
||||||
"--allow-wild" | "allow-wild" ) need_root=0;;
|
"--allow-wild" | "allow-wild" ) ;;
|
||||||
"-f" | "flush" ) ;;
|
"-f" | "flush" ) need_root=true;;
|
||||||
"-up" | "updatePihole" ) ;;
|
"-up" | "updatePihole" ) need_root=true;;
|
||||||
"-r" | "repair" ) ;;
|
"-r" | "repair" ) need_root=true;;
|
||||||
"-l" | "logging" ) ;;
|
"-l" | "logging" ) need_root=true;;
|
||||||
"uninstall" ) ;;
|
"uninstall" ) need_root=true;;
|
||||||
"enable" ) need_root=0;;
|
"enable" ) ;;
|
||||||
"disable" ) need_root=0;;
|
"disable" ) ;;
|
||||||
"-d" | "debug" ) ;;
|
"-d" | "debug" ) need_root=true;;
|
||||||
"-g" | "updateGravity" ) ;;
|
"-g" | "updateGravity" ) need_root=true;;
|
||||||
"reloaddns" ) ;;
|
"reloaddns" ) need_root=true;;
|
||||||
"reloadlists" ) ;;
|
"reloadlists" ) need_root=true;;
|
||||||
"setpassword" ) ;;
|
"setpassword" ) need_root=true;;
|
||||||
"checkout" ) ;;
|
"checkout" ) need_root=true;;
|
||||||
"updatechecker" ) ;;
|
"updatechecker" ) need_root=true;;
|
||||||
"arpflush" ) ;; # Deprecated, use networkflush instead
|
"arpflush" ) need_root=true;; # Deprecated, use networkflush instead
|
||||||
"networkflush" ) ;;
|
"networkflush" ) need_root=true;;
|
||||||
"-t" | "tail" ) ;;
|
"-t" | "tail" ) need_root=true;;
|
||||||
"api" ) need_root=0;;
|
"api" ) ;;
|
||||||
* ) helpFunc;;
|
* ) helpFunc;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@ -588,8 +588,8 @@ fi
|
|||||||
# Check if the current user is not root and if the command
|
# Check if the current user is not root and if the command
|
||||||
# requires root. If so, exit with an error message.
|
# requires root. If so, exit with an error message.
|
||||||
# Add an exception for the user "pihole" to allow the webserver running gravity
|
# Add an exception for the user "pihole" to allow the webserver running gravity
|
||||||
if [[ ( $EUID -ne 0 && ${USER} != "pihole" ) && need_root -eq 1 ]]; then
|
if [[ ( $EUID -ne 0 && ${USER} != "pihole" ) && -n "${need_root}" ]]; then
|
||||||
echo -e " ${CROSS} The Pi-hole command requires root privileges, try:"
|
echo -e " ${CROSS} This Pi-hole command requires root privileges, try:"
|
||||||
echo -e " ${COL_GREEN}sudo pihole $*${COL_NC}"
|
echo -e " ${COL_GREEN}sudo pihole $*${COL_NC}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user