mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-27 07:12:27 +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
1 changed files with 8 additions and 22 deletions
30
pihole
30
pihole
|
@ -552,8 +552,8 @@ case "${1}" in
|
||||||
"disable" ) ;;
|
"disable" ) ;;
|
||||||
"-d" | "debug" ) ;;
|
"-d" | "debug" ) ;;
|
||||||
"restartdns" ) ;;
|
"restartdns" ) ;;
|
||||||
"-g" | "updateGravity" ) need_root=0;;
|
"-g" | "updateGravity" ) ;;
|
||||||
"reloaddns" ) need_root=0;;
|
"reloaddns" ) ;;
|
||||||
"setpassword" ) ;;
|
"setpassword" ) ;;
|
||||||
"checkout" ) ;;
|
"checkout" ) ;;
|
||||||
"updatechecker" ) ;;
|
"updatechecker" ) ;;
|
||||||
|
@ -562,32 +562,18 @@ case "${1}" in
|
||||||
* ) helpFunc;;
|
* ) helpFunc;;
|
||||||
esac
|
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
|
# 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
|
# which prevents the next trap from working correctly. Set it by running whoami
|
||||||
if [[ -z ${USER} ]]; then
|
if [[ -z ${USER} ]]; then
|
||||||
USER=$(whoami)
|
USER=$(whoami)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Can also be user pihole for other functions
|
# Check if the current user is neither root nor pihole and if the command
|
||||||
if [[ ${USER} != "pihole" && need_root -eq 0 ]];then
|
# requires root. If so, exit with an error message.
|
||||||
if [[ -x "$(command -v sudo)" ]]; then
|
if [[ $EUID -ne 0 && ${USER} != "pihole" && need_root -eq 1 ]];then
|
||||||
exec sudo -u pihole bash "$0" "$@"
|
echo -e " ${CROSS} The Pi-hole command requires root privileges, try:"
|
||||||
exit $?
|
echo -e " ${COL_GREEN}sudo pihole ${@}${COL_NC}"
|
||||||
else
|
exit 1
|
||||||
echo -e " ${CROSS} sudo is needed to run pihole commands. Please run this script as root or install sudo."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Handle redirecting to specific functions based on arguments
|
# Handle redirecting to specific functions based on arguments
|
||||||
|
|
Loading…
Reference in a new issue