diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh index 86d18c61..f61db8f6 100644 --- a/advanced/Scripts/blacklist.sh +++ b/advanced/Scripts/blacklist.sh @@ -23,28 +23,9 @@ if [[ $# = 0 ]]; then exit 1 fi -# Check if pihole user, and if not then rerun with sudo. -echo ":::" -runninguser=$(whoami) -if [[ "$runninguser" = "pihole" ]];then - echo "::: You are pihole user." - # Older versions of Pi-hole set $SUDO="sudo" and prefixed commands with it, - # rather than rerunning as sudo. Just in case it turns up by accident, - # explicitly set the $SUDO variable to an empty string. - SUDO="" -else - echo "::: sudo will be used." - # Check if it is actually installed - # If it isn't, exit because the install cannot complete - if [[ $(dpkg-query -s sudo) ]];then - echo "::: Running sudo -u pihole $0 $@" - sudo -u pihole "$0" "$@" - exit $? - else - echo "::: Please install sudo." - exit 1 - fi -fi +source /usr/local/include/pihole/piholeInclude + +rerun_pihole "$0" "$@" #globals blacklist=/etc/pihole/blacklist.txt diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index 5c5c6755..e5c19230 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -10,28 +10,9 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# Check if pihole user, and if not then rerun with sudo. -echo ":::" -runninguser=$(whoami) -if [[ "$runninguser" = "pihole" ]];then - echo "::: You are pihole user." - # Older versions of Pi-hole set $SUDO="sudo" and prefixed commands with it, - # rather than rerunning as sudo. Just in case it turns up by accident, - # explicitly set the $SUDO variable to an empty string. - SUDO="" -else - echo "::: sudo will be used." - # Check if it is actually installed - # If it isn't, exit because the install cannot complete - if [[ $(dpkg-query -s sudo) ]];then - echo "::: Running sudo -u pihole $0 $@" - sudo -u pihole "$0" "$@" - exit $? - else - echo "::: Please install sudo." - exit 1 - fi -fi +source /usr/local/include/pihole/piholeInclude + +rerun_pihole "$0" "$@" #Functions############################################################################################################## piLog="/var/log/pihole.log" diff --git a/advanced/Scripts/piholeLogFlush.sh b/advanced/Scripts/piholeLogFlush.sh index 7e52a467..43bc631b 100755 --- a/advanced/Scripts/piholeLogFlush.sh +++ b/advanced/Scripts/piholeLogFlush.sh @@ -10,27 +10,8 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# Check if pihole user, and if not then rerun with sudo. -echo ":::" -runninguser=$(whoami) -if [[ "$runninguser" = "pihole" ]];then - echo "::: You are pihole user." - # Older versions of Pi-hole set $SUDO="sudo" and prefixed commands with it, - # rather than rerunning as sudo. Just in case it turns up by accident, - # explicitly set the $SUDO variable to an empty string. - SUDO="" -else - echo "::: sudo will be used." - # Check if it is actually installed - # If it isn't, exit because the install cannot complete - if [[ $(dpkg-query -s sudo) ]];then - echo "::: Running sudo -u pihole $0 $@" - sudo -u pihole "$0" "$@" - exit $? - else - echo "::: Please install sudo." - exit 1 - fi -fi +source /usr/local/include/pihole/piholeInclude + +rerun_root "$0" "$@" truncate -s 0 /var/log/pihole.log diff --git a/advanced/Scripts/piholeReloadServices.sh b/advanced/Scripts/piholeReloadServices.sh index 01e5d372..9a511d7e 100644 --- a/advanced/Scripts/piholeReloadServices.sh +++ b/advanced/Scripts/piholeReloadServices.sh @@ -10,27 +10,9 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# Check if root, and if not then rerun with sudo. -echo ":::" -if [[ $EUID -eq 0 ]];then - echo "::: You are root." - # Older versions of Pi-hole set $SUDO="sudo" and prefixed commands with it, - # rather than rerunning as sudo. Just in case it turns up by accident, - # explicitly set the $SUDO variable to an empty string. - SUDO="" -else - echo "::: sudo will be used." - # Check if it is actually installed - # If it isn't, exit because the install cannot complete - if [[ $(dpkg-query -s sudo) ]];then - echo "::: Running sudo $0 $@" - sudo "$0" "$@" - exit $? - else - echo "::: Please install sudo or run this script as root." - exit 1 - fi -fi +source /usr/local/include/pihole/piholeInclude + +rerun_root "$0" "$@" spinner(){ diff --git a/advanced/Scripts/piholeSetPermissions.sh b/advanced/Scripts/piholeSetPermissions.sh index ff1ec36a..5002f21c 100644 --- a/advanced/Scripts/piholeSetPermissions.sh +++ b/advanced/Scripts/piholeSetPermissions.sh @@ -10,27 +10,9 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# Check if root, and if not then rerun with sudo. -echo ":::" -if [[ $EUID -eq 0 ]];then - echo "::: You are root." - # Older versions of Pi-hole set $SUDO="sudo" and prefixed commands with it, - # rather than rerunning as sudo. Just in case it turns up by accident, - # explicitly set the $SUDO variable to an empty string. - SUDO="" -else - echo "::: sudo will be used." - # Check if it is actually installed - # If it isn't, exit because the install cannot complete - if [[ $(dpkg-query -s sudo) ]];then - echo "::: Running sudo $0 $@" - sudo "$0" "$@" - exit $? - else - echo "::: Please install sudo or run this script as root." - exit 1 - fi -fi +source /usr/local/include/pihole/piholeInclude + +rerun_root "$0" "$@" chown --recursive root:pihole /etc/pihole chmod --recursive ug=rwX,o=rX /etc/pihole diff --git a/advanced/Scripts/setupLCD.sh b/advanced/Scripts/setupLCD.sh index 2a5888ad..65a04dab 100644 --- a/advanced/Scripts/setupLCD.sh +++ b/advanced/Scripts/setupLCD.sh @@ -10,27 +10,9 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# Check if root, and if not then rerun with sudo. -echo ":::" -if [[ $EUID -eq 0 ]];then - echo "::: You are root." - # Older versions of Pi-hole set $SUDO="sudo" and prefixed commands with it, - # rather than rerunning as sudo. Just in case it turns up by accident, - # explicitly set the $SUDO variable to an empty string. - SUDO="" -else - echo "::: sudo will be used." - # Check if it is actually installed - # If it isn't, exit because the install cannot complete - if [[ $(dpkg-query -s sudo) ]];then - echo "::: Running sudo $0 $@" - sudo "$0" "$@" - exit $? - else - echo "::: Please install sudo or run this script as root." - exit 1 - fi -fi +source /usr/local/include/pihole/piholeInclude + +rerun_root "$0" "$@" ############ FUNCTIONS ########### # Run this script as root or under sudo diff --git a/advanced/Scripts/updateDashboard.sh b/advanced/Scripts/updateDashboard.sh index edf04896..5f046787 100644 --- a/advanced/Scripts/updateDashboard.sh +++ b/advanced/Scripts/updateDashboard.sh @@ -10,6 +10,10 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. +source /usr/local/include/pihole/piholeInclude + +rerun_pihole "$0" "$@" + WEB_INTERFACE_GIT_URL="https://github.com/pi-hole/AdminLTE.git" WEB_INTERFACE_DIR="/var/www/html/admin" @@ -23,12 +27,6 @@ main() { prerequisites() { - # must be root to update - if [[ $EUID -ne 0 ]]; then - sudo bash "$0" "$@" - exit $? - fi - # web interface must already exist. this is a (lazy) # check to make sure pihole is actually installed. if [ ! -d "$WEB_INTERFACE_DIR" ]; then diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index 2d344234..861879a2 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -23,28 +23,9 @@ if [[ $# = 0 ]]; then exit 1 fi -# Check if pihole user, and if not then rerun with sudo. -echo ":::" -runninguser=$(whoami) -if [[ "$runninguser" = "pihole" ]];then - echo "::: You are pihole user." - # Older versions of Pi-hole set $SUDO="sudo" and prefixed commands with it, - # rather than rerunning as sudo. Just in case it turns up by accident, - # explicitly set the $SUDO variable to an empty string. - SUDO="" -else - echo "::: sudo will be used." - # Check if it is actually installed - # If it isn't, exit because the install cannot complete - if [[ $(dpkg-query -s sudo) ]];then - echo "::: Running sudo -u pihole $0 $@" - sudo -u pihole "$0" "$@" - exit $? - else - echo "::: Please install sudo." - exit 1 - fi -fi +source /usr/local/include/pihole/piholeInclude + +rerun_pihole "$0" "$@" #globals whitelist=/etc/pihole/whitelist.txt