mirror of
https://github.com/pi-hole/pi-hole
synced 2024-12-22 14:58:08 +00:00
Do not auto-sudo in the pihole command
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
7e91b9ab47
commit
424e825bd9
28
pihole
28
pihole
@ -552,8 +552,8 @@ case "${1}" in
|
||||
"disable" ) ;;
|
||||
"-d" | "debug" ) ;;
|
||||
"restartdns" ) ;;
|
||||
"-g" | "updateGravity" ) need_root=0;;
|
||||
"reloaddns" ) need_root=0;;
|
||||
"-g" | "updateGravity" ) ;;
|
||||
"reloaddns" ) ;;
|
||||
"setpassword" ) ;;
|
||||
"checkout" ) ;;
|
||||
"updatechecker" ) ;;
|
||||
@ -562,33 +562,19 @@ case "${1}" in
|
||||
* ) helpFunc;;
|
||||
esac
|
||||
|
||||
# Must be root to use this tool for most functions
|
||||
if [[ ! $EUID -eq 0 && need_root -eq 1 ]];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
|
||||
|
||||
# In the case of alpine running in a container, the USER variable appears to be blank
|
||||
# which prevents the next trap from working correctly. Set it by running whoami
|
||||
if [[ -z ${USER} ]]; then
|
||||
USER=$(whoami)
|
||||
fi
|
||||
|
||||
# Can also be user pihole for other functions
|
||||
if [[ ${USER} != "pihole" && need_root -eq 0 ]];then
|
||||
if [[ -x "$(command -v sudo)" ]]; then
|
||||
exec sudo -u pihole bash "$0" "$@"
|
||||
exit $?
|
||||
else
|
||||
echo -e " ${CROSS} sudo is needed to run pihole commands. Please run this script as root or install sudo."
|
||||
# Check if the current user is neither root nor pihole and if the command
|
||||
# requires root. If so, exit with an error message.
|
||||
if [[ $EUID -ne 0 && ${USER} != "pihole" && need_root -eq 1 ]];then
|
||||
echo -e " ${CROSS} The Pi-hole command requires root privileges, try:"
|
||||
echo -e " ${COL_GREEN}sudo pihole ${@}${COL_NC}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Handle redirecting to specific functions based on arguments
|
||||
case "${1}" in
|
||||
|
Loading…
Reference in New Issue
Block a user