From 5382b4fa3785b1f2f16201436826a3ea1cd8c725 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 5 Oct 2016 09:42:15 -0700 Subject: [PATCH 01/18] Change installScripts to use install Use the install program instead of copying files and directories in installScripts function. --- automated install/basic-install.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 4d8c602a..63ce926f 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -526,11 +526,8 @@ installScripts() { # Install the scripts from /etc/.pihole to their various locations ${SUDO} echo ":::" ${SUDO} echo -n "::: Installing scripts to /opt/pihole..." - if [ ! -d /opt/pihole ]; then - ${SUDO} mkdir /opt/pihole - ${SUDO} chown "$USER":root /opt/pihole - ${SUDO} chmod u+srwx /opt/pihole - fi + ${SUDO} install -o ${USER} -m755 -d /opt/pihole + ${SUDO} cp /etc/.pihole/gravity.sh /opt/pihole/gravity.sh ${SUDO} cp /etc/.pihole/advanced/Scripts/chronometer.sh /opt/pihole/chronometer.sh ${SUDO} cp /etc/.pihole/advanced/Scripts/whitelist.sh /opt/pihole/whitelist.sh From 36987cb1cca0169adc9c655c9c951c04df2c9ded Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 5 Oct 2016 09:57:48 -0700 Subject: [PATCH 02/18] Continue migration to `install` --- automated install/basic-install.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 63ce926f..ed9fa7e7 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -526,13 +526,11 @@ installScripts() { # Install the scripts from /etc/.pihole to their various locations ${SUDO} echo ":::" ${SUDO} echo -n "::: Installing scripts to /opt/pihole..." - ${SUDO} install -o ${USER} -m755 -d /opt/pihole - - ${SUDO} cp /etc/.pihole/gravity.sh /opt/pihole/gravity.sh - ${SUDO} cp /etc/.pihole/advanced/Scripts/chronometer.sh /opt/pihole/chronometer.sh - ${SUDO} cp /etc/.pihole/advanced/Scripts/whitelist.sh /opt/pihole/whitelist.sh - ${SUDO} cp /etc/.pihole/advanced/Scripts/blacklist.sh /opt/pihole/blacklist.sh - ${SUDO} cp /etc/.pihole/advanced/Scripts/piholeDebug.sh /opt/pihole/piholeDebug.sh + ${SUDO} install -o "${USER}" -m755 -d /opt/pihole + + cd /etc/.pihole/ + + ${SUDO} install cp "${USER}" -m755 -d /opt/pihole/ gravity.sh chronometer.sh whitelist.sh blacklist.sh piholeDebug.sh ${SUDO} cp /etc/.pihole/advanced/Scripts/piholeLogFlush.sh /opt/pihole/piholeLogFlush.sh ${SUDO} cp /etc/.pihole/automated\ install/uninstall.sh /opt/pihole/uninstall.sh ${SUDO} cp /etc/.pihole/advanced/Scripts/setupLCD.sh /opt/pihole/setupLCD.sh From e8bb4a7e363c4316e2832af5377bcce3620466ad Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 5 Oct 2016 10:14:36 -0700 Subject: [PATCH 03/18] Continue migration to `install` --- automated install/basic-install.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index ed9fa7e7..12fccfa0 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -530,12 +530,8 @@ installScripts() { cd /etc/.pihole/ - ${SUDO} install cp "${USER}" -m755 -d /opt/pihole/ gravity.sh chronometer.sh whitelist.sh blacklist.sh piholeDebug.sh - ${SUDO} cp /etc/.pihole/advanced/Scripts/piholeLogFlush.sh /opt/pihole/piholeLogFlush.sh - ${SUDO} cp /etc/.pihole/automated\ install/uninstall.sh /opt/pihole/uninstall.sh - ${SUDO} cp /etc/.pihole/advanced/Scripts/setupLCD.sh /opt/pihole/setupLCD.sh - ${SUDO} cp /etc/.pihole/advanced/Scripts/version.sh /opt/pihole/version.sh - ${SUDO} chmod 755 /opt/pihole/gravity.sh /opt/pihole/chronometer.sh /opt/pihole/whitelist.sh /opt/pihole/blacklist.sh /opt/pihole/piholeLogFlush.sh /opt/pihole/uninstall.sh /opt/pihole/setupLCD.sh /opt/pihole/version.sh + ${SUDO} install -o "${USER}" -Dm755 -t /opt/pihole/ gravity.sh + ${SUDO} install -o "${USER}" -Dm755 -t /opt/pihole/ ./advanced/Scripts/*.sh ${SUDO} cp /etc/.pihole/pihole /usr/local/bin/pihole ${SUDO} chmod 755 /usr/local/bin/pihole ${SUDO} cp /etc/.pihole/advanced/bash-completion/pihole /etc/bash_completion.d/pihole From 3600fd277e0385496bd496e350f5ed6d23f84a0a Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 5 Oct 2016 10:16:56 -0700 Subject: [PATCH 04/18] Don't need `sudo` to echo to term. --- automated install/basic-install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 12fccfa0..56b9934e 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -524,8 +524,8 @@ versionCheckDNSmasq(){ installScripts() { # Install the scripts from /etc/.pihole to their various locations - ${SUDO} echo ":::" - ${SUDO} echo -n "::: Installing scripts to /opt/pihole..." + echo ":::" + echo -n "::: Installing scripts to /opt/pihole..." ${SUDO} install -o "${USER}" -m755 -d /opt/pihole cd /etc/.pihole/ @@ -545,7 +545,7 @@ installScripts() { fi done - ${SUDO} echo " done." + echo " done." } installConfigs() { From 3bbac9a5f219cc07831a1e5425d1266a2e650135 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 5 Oct 2016 10:19:47 -0700 Subject: [PATCH 05/18] `install` pihole --- automated install/basic-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 56b9934e..6308a0ed 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -532,8 +532,8 @@ installScripts() { ${SUDO} install -o "${USER}" -Dm755 -t /opt/pihole/ gravity.sh ${SUDO} install -o "${USER}" -Dm755 -t /opt/pihole/ ./advanced/Scripts/*.sh - ${SUDO} cp /etc/.pihole/pihole /usr/local/bin/pihole - ${SUDO} chmod 755 /usr/local/bin/pihole + ${SUDO} install -o "${USER}" -Dm755 -t /usr/local/bin/ pihole + ${SUDO} cp /etc/.pihole/advanced/bash-completion/pihole /etc/bash_completion.d/pihole . /etc/bash_completion.d/pihole From 50d16d8215f2a7016d9cf3650a61e44814c1b8ba Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 5 Oct 2016 10:45:17 -0700 Subject: [PATCH 06/18] Finish `install` conversion for installScripts() --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 6308a0ed..84ef9788 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -534,7 +534,7 @@ installScripts() { ${SUDO} install -o "${USER}" -Dm755 -t /opt/pihole/ ./advanced/Scripts/*.sh ${SUDO} install -o "${USER}" -Dm755 -t /usr/local/bin/ pihole - ${SUDO} cp /etc/.pihole/advanced/bash-completion/pihole /etc/bash_completion.d/pihole + ${SUDO} install -Dm644 ./advanced/bash-completion/pihole /etc/bash_completion.d/pihole . /etc/bash_completion.d/pihole #Tidy up /usr/local/bin directory if installing over previous install. From 8c151c62ce3ab311d561d5048a53685e75d9b037 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 5 Oct 2016 10:46:10 -0700 Subject: [PATCH 07/18] echo's don't need sudo --- automated install/basic-install.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 84ef9788..72b28d22 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -550,8 +550,8 @@ installScripts() { installConfigs() { # Install the configs from /etc/.pihole to their various locations - ${SUDO} echo ":::" - ${SUDO} echo "::: Installing configs..." + echo ":::" + echo "::: Installing configs..." versionCheckDNSmasq if [ ! -d "/etc/lighttpd" ]; then ${SUDO} mkdir /etc/lighttpd @@ -567,15 +567,15 @@ installConfigs() { stopServices() { # Stop dnsmasq and lighttpd - ${SUDO} echo ":::" - ${SUDO} echo -n "::: Stopping services..." + echo ":::" + echo -n "::: Stopping services..." #$SUDO service dnsmasq stop & spinner $! || true if [ -x "$(command -v systemctl)" ]; then ${SUDO} systemctl stop lighttpd & spinner $! || true else ${SUDO} service lighttpd stop & spinner $! || true fi - ${SUDO} echo " done." + echo " done." } installerDependencies() { From c39324d11f17b93d59c2daa4d35e20a96d9b84a5 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 7 Oct 2016 00:24:25 -0700 Subject: [PATCH 08/18] Remove bare php package from dependencies `php5` package can trigger install of Apache2. Without this package in deps, PHP is still installed and operational. --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 4d8c602a..ae27e593 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -74,7 +74,7 @@ if [ -x "$(command -v apt-get)" ];then PKG_INSTALL="$PKG_MANAGER --yes --quiet install" PKG_COUNT="$PKG_MANAGER -s -o Debug::NoLocking=true upgrade | grep -c ^Inst" INSTALLER_DEPS=( apt-utils whiptail dhcpcd5) - PIHOLE_DEPS=( dnsutils bc dnsmasq lighttpd ${phpVer}-common ${phpVer}-cgi ${phpVer} git curl unzip wget sudo netcat cron iproute2 ) + PIHOLE_DEPS=( dnsutils bc dnsmasq lighttpd ${phpVer}-common ${phpVer}-cgi git curl unzip wget sudo netcat cron iproute2 ) LIGHTTPD_USER="www-data" LIGHTTPD_GROUP="www-data" LIGHTTPD_CFG="lighttpd.conf.debian" From d1a7fe2d4409ceff36776c78b50d300678bf76c9 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 7 Oct 2016 03:36:34 -0700 Subject: [PATCH 09/18] fix/bashConditional --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 4d8c602a..e65a0bba 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -926,7 +926,7 @@ fi # Start the installer # Verify there is enough disk space for the install -if [ $1 = "--i_do_not_follow_recommendations" ]; then +if [[ $1 = "--i_do_not_follow_recommendations" ]]; then echo "::: ----i_do_not_follow_recommendations passed to script" echo "::: skipping free disk space verification!" else From 6a28070017c83c273e76d40aeac889647d92ce17 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 7 Oct 2016 13:09:27 +0100 Subject: [PATCH 10/18] Too many `-`s --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index ba098109..72c94da8 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -918,7 +918,7 @@ fi # Start the installer # Verify there is enough disk space for the install if [[ $1 = "--i_do_not_follow_recommendations" ]]; then - echo "::: ----i_do_not_follow_recommendations passed to script" + echo "::: --i_do_not_follow_recommendations passed to script" echo "::: skipping free disk space verification!" else verifyFreeDiskSpace From 44170207ac37896e1990c87649f33b559482ae57 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 8 Oct 2016 12:17:04 -0700 Subject: [PATCH 11/18] Add `main` function and fire script from `main` call. Prevents script from running before it is entirely downloaded. --- automated install/basic-install.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 4dab9355..85e93d00 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -903,7 +903,7 @@ updateDialogs(){ } -######## SCRIPT ############ +main() { if [[ -f ${setupVars} ]];then . ${setupVars} @@ -979,3 +979,6 @@ fi echo ":::" echo "::: The install log is located at: /etc/pihole/install.log" echo "::: View the web interface at http://pi.hole/admin or http://${IPv4addr%/*}/admin" +} + +main "$@" \ No newline at end of file From d20df92e9f855f99900a5dcf2ed13c411828cf3e Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 8 Oct 2016 12:56:26 -0700 Subject: [PATCH 12/18] Script will now run as root, removed `sudo` from function calls. --- automated install/basic-install.sh | 232 +++++++++++++++-------------- 1 file changed, 118 insertions(+), 114 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 85e93d00..c6f409fb 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -45,11 +45,15 @@ echo ":::" if [[ $EUID -eq 0 ]];then echo "::: You are root." else - echo "::: sudo will be used for the install." - # Check if it is actually installed - # If it isn't, exit because the install cannot complete + echo "::: Script called with non-root privileges. The Pi-hole installs server packages and configures" + echo "::: system networking, it requires elevated rights. Please check the contents of the script for" + echo "::: any concerns with this requirement. Please be sure to download this script from a trusted source." + echo ":::" + echo "::: Detecting the presence of the sudo utility for continuation of this install..." if [ -x "$(command -v sudo)" ];then - export SUDO="sudo" + echo "::: Utility sudo located." + exec sudo bash "$0" "$@" + exit $? else echo "::: sudo is needed for the Web interface to run pihole commands. Please run this script as root and it will be automatically installed." exit 1 @@ -62,7 +66,7 @@ if [ -x "$(command -v apt-get)" ];then #Debian Family #Decide if php should be `php5` or just `php` (Fixes issues with Ubuntu 16.04 LTS) phpVer="php" - ${SUDO} apt-get install --dry-run php5 > /dev/null 2>&1 + apt-get install --dry-run php5 > /dev/null 2>&1 if [ $? == 0 ]; then phpVer="php5" fi @@ -317,7 +321,7 @@ setDHCPCD() { echo "## interface $piholeInterface static ip_address=$IPv4addr static routers=$IPv4gw - static domain_name_servers=$IPv4gw" | ${SUDO} tee -a /etc/dhcpcd.conf >/dev/null + static domain_name_servers=$IPv4gw" | tee -a /etc/dhcpcd.conf >/dev/null } setStaticIPv4() { @@ -327,7 +331,7 @@ setStaticIPv4() { echo "::: Static IP already configured" else setDHCPCD - ${SUDO} ip addr replace dev "$piholeInterface" "$IPv4addr" + ip addr replace dev "$piholeInterface" "$IPv4addr" echo ":::" echo "::: Setting IP to $IPv4addr. You may need to restart after the install is complete." echo ":::" @@ -343,20 +347,20 @@ setStaticIPv4() { # Backup existing interface configuration: cp ${IFCFG_FILE} ${IFCFG_FILE}.backup-$(date +%Y-%m-%d-%H%M%S) # Build Interface configuration file: - ${SUDO} echo "# Configured via Pi-Hole installer" > ${IFCFG_FILE} - ${SUDO} echo "DEVICE=$piholeInterface" >> ${IFCFG_FILE} - ${SUDO} echo "BOOTPROTO=none" >> ${IFCFG_FILE} - ${SUDO} echo "ONBOOT=yes" >> ${IFCFG_FILE} - ${SUDO} echo "IPADDR=$IPADDR" >> ${IFCFG_FILE} - ${SUDO} echo "PREFIX=$CIDR" >> ${IFCFG_FILE} - ${SUDO} echo "GATEWAY=$IPv4gw" >> ${IFCFG_FILE} - ${SUDO} echo "DNS1=$piholeDNS1" >> ${IFCFG_FILE} - ${SUDO} echo "DNS2=$piholeDNS2" >> ${IFCFG_FILE} - ${SUDO} echo "USERCTL=no" >> ${IFCFG_FILE} - ${SUDO} ip addr replace dev "$piholeInterface" "$IPv4addr" + echo "# Configured via Pi-Hole installer" > ${IFCFG_FILE} + echo "DEVICE=$piholeInterface" >> ${IFCFG_FILE} + echo "BOOTPROTO=none" >> ${IFCFG_FILE} + echo "ONBOOT=yes" >> ${IFCFG_FILE} + echo "IPADDR=$IPADDR" >> ${IFCFG_FILE} + echo "PREFIX=$CIDR" >> ${IFCFG_FILE} + echo "GATEWAY=$IPv4gw" >> ${IFCFG_FILE} + echo "DNS1=$piholeDNS1" >> ${IFCFG_FILE} + echo "DNS2=$piholeDNS2" >> ${IFCFG_FILE} + echo "USERCTL=no" >> ${IFCFG_FILE} + ip addr replace dev "$piholeInterface" "$IPv4addr" if [ -x "$(command -v nmcli)" ];then # Tell NetworkManager to read our new sysconfig file - ${SUDO} nmcli con load ${IFCFG_FILE} > /dev/null + nmcli con load ${IFCFG_FILE} > /dev/null fi echo ":::" echo "::: Setting IP to $IPv4addr. You may need to restart after the install is complete." @@ -491,57 +495,57 @@ versionCheckDNSmasq(){ if grep -q ${dnsSearch} ${dnsFile1}; then echo " it is from a previous pi-hole install." echo -n "::: Backing up dnsmasq.conf to dnsmasq.conf.orig..." - ${SUDO} mv -f ${dnsFile1} ${dnsFile2} + mv -f ${dnsFile1} ${dnsFile2} echo " done." echo -n "::: Restoring default dnsmasq.conf..." - ${SUDO} cp ${defaultFile} ${dnsFile1} + cp ${defaultFile} ${dnsFile1} echo " done." else echo " it is not a pi-hole file, leaving alone!" fi else echo -n "::: No dnsmasq.conf found.. restoring default dnsmasq.conf..." - ${SUDO} cp ${defaultFile} ${dnsFile1} + cp ${defaultFile} ${dnsFile1} echo " done." fi echo -n "::: Copying 01-pihole.conf to /etc/dnsmasq.d/01-pihole.conf..." - ${SUDO} cp ${newFileToInstall} ${newFileFinalLocation} + cp ${newFileToInstall} ${newFileFinalLocation} echo " done." - ${SUDO} sed -i "s/@INT@/$piholeInterface/" ${newFileFinalLocation} + sed -i "s/@INT@/$piholeInterface/" ${newFileFinalLocation} if [[ "$piholeDNS1" != "" ]]; then - ${SUDO} sed -i "s/@DNS1@/$piholeDNS1/" ${newFileFinalLocation} + sed -i "s/@DNS1@/$piholeDNS1/" ${newFileFinalLocation} else - ${SUDO} sed -i '/^server=@DNS1@/d' ${newFileFinalLocation} + sed -i '/^server=@DNS1@/d' ${newFileFinalLocation} fi if [[ "$piholeDNS2" != "" ]]; then - ${SUDO} sed -i "s/@DNS2@/$piholeDNS2/" ${newFileFinalLocation} + sed -i "s/@DNS2@/$piholeDNS2/" ${newFileFinalLocation} else - ${SUDO} sed -i '/^server=@DNS2@/d' ${newFileFinalLocation} + sed -i '/^server=@DNS2@/d' ${newFileFinalLocation} fi - ${SUDO} sed -i 's/^#conf-dir=\/etc\/dnsmasq.d$/conf-dir=\/etc\/dnsmasq.d/' ${dnsFile1} + sed -i 's/^#conf-dir=\/etc\/dnsmasq.d$/conf-dir=\/etc\/dnsmasq.d/' ${dnsFile1} } installScripts() { # Install the scripts from /etc/.pihole to their various locations echo ":::" echo -n "::: Installing scripts to /opt/pihole..." - ${SUDO} install -o "${USER}" -m755 -d /opt/pihole + install -o "${USER}" -m755 -d /opt/pihole cd /etc/.pihole/ - ${SUDO} install -o "${USER}" -Dm755 -t /opt/pihole/ gravity.sh - ${SUDO} install -o "${USER}" -Dm755 -t /opt/pihole/ ./advanced/Scripts/*.sh - ${SUDO} install -o "${USER}" -Dm755 -t /usr/local/bin/ pihole + install -o "${USER}" -Dm755 -t /opt/pihole/ gravity.sh + install -o "${USER}" -Dm755 -t /opt/pihole/ ./advanced/Scripts/*.sh + install -o "${USER}" -Dm755 -t /usr/local/bin/ pihole - ${SUDO} install -Dm644 ./advanced/bash-completion/pihole /etc/bash_completion.d/pihole + install -Dm644 ./advanced/bash-completion/pihole /etc/bash_completion.d/pihole . /etc/bash_completion.d/pihole #Tidy up /usr/local/bin directory if installing over previous install. oldFiles=( gravity chronometer whitelist blacklist piholeLogFlush updateDashboard uninstall setupLCD piholeDebug) for i in "${oldFiles[@]}"; do if [ -f "/usr/local/bin/$i.sh" ]; then - ${SUDO} rm /usr/local/bin/"$i".sh + rm /usr/local/bin/"$i".sh fi done @@ -554,15 +558,15 @@ installConfigs() { echo "::: Installing configs..." versionCheckDNSmasq if [ ! -d "/etc/lighttpd" ]; then - ${SUDO} mkdir /etc/lighttpd - ${SUDO} chown "$USER":root /etc/lighttpd - ${SUDO} mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig + mkdir /etc/lighttpd + chown "$USER":root /etc/lighttpd + mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig fi - ${SUDO} cp /etc/.pihole/advanced/${LIGHTTPD_CFG} /etc/lighttpd/lighttpd.conf - ${SUDO} mkdir -p /var/run/lighttpd - ${SUDO} chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/run/lighttpd - ${SUDO} mkdir -p /var/cache/lighttpd/compress - ${SUDO} chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/compress + cp /etc/.pihole/advanced/${LIGHTTPD_CFG} /etc/lighttpd/lighttpd.conf + mkdir -p /var/run/lighttpd + chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/run/lighttpd + mkdir -p /var/cache/lighttpd/compress + chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/compress } stopServices() { @@ -571,9 +575,9 @@ stopServices() { echo -n "::: Stopping services..." #$SUDO service dnsmasq stop & spinner $! || true if [ -x "$(command -v systemctl)" ]; then - ${SUDO} systemctl stop lighttpd & spinner $! || true + systemctl stop lighttpd & spinner $! || true else - ${SUDO} service lighttpd stop & spinner $! || true + service lighttpd stop & spinner $! || true fi echo " done." } @@ -593,12 +597,12 @@ installerDependencies() { #update package lists echo ":::" echo -n "::: $PKG_MANAGER update has not been run today. Running now..." - ${SUDO} ${UPDATE_PKG_CACHE} > /dev/null 2>&1 + ${UPDATE_PKG_CACHE} > /dev/null 2>&1 echo " done!" fi echo ":::" echo -n "::: Checking $PKG_MANAGER for upgraded packages...." - updatesToInstall=$(eval "${SUDO} ${PKG_COUNT}") + updatesToInstall=$(eval "${PKG_COUNT}") echo " done!" echo ":::" if [[ ${updatesToInstall} -eq "0" ]]; then @@ -615,7 +619,7 @@ installerDependencies() { package_check ${i} > /dev/null if ! [ $? -eq 0 ]; then echo -n " Not found! Installing...." - ${SUDO} ${PKG_INSTALL} "$i" > /dev/null 2>&1 + ${PKG_INSTALL} "$i" > /dev/null 2>&1 echo " done!" else echo " already installed!" @@ -632,7 +636,7 @@ checkForDependencies() { package_check ${i} > /dev/null if ! [ $? -eq 0 ]; then echo -n " Not found! Installing...." - ${SUDO} ${PKG_INSTALL} "$i" > /dev/null & spinner $! + ${PKG_INSTALL} "$i" > /dev/null & spinner $! echo " done!" else echo " already installed!" @@ -673,8 +677,8 @@ is_repo() { make_repo() { # Remove the non-repod interface and clone the interface echo -n "::: Cloning $2 into $1..." - ${SUDO} rm -rf "$1" - ${SUDO} git clone -q "$2" "$1" > /dev/null & spinner $! + rm -rf "$1" + git clone -q "$2" "$1" > /dev/null & spinner $! echo " done!" } @@ -682,7 +686,7 @@ update_repo() { # Pull the latest commits echo -n "::: Updating repo in $1..." cd "$1" || exit - ${SUDO} git pull -q > /dev/null & spinner $! + git pull -q > /dev/null & spinner $! echo " done!" } @@ -690,59 +694,59 @@ update_repo() { CreateLogFile() { # Create logfiles if necessary echo ":::" - ${SUDO} echo -n "::: Creating log file and changing owner to dnsmasq..." + echo -n "::: Creating log file and changing owner to dnsmasq..." if [ ! -f /var/log/pihole.log ]; then - ${SUDO} touch /var/log/pihole.log - ${SUDO} chmod 644 /var/log/pihole.log - ${SUDO} chown dnsmasq:root /var/log/pihole.log - ${SUDO} echo " done!" + touch /var/log/pihole.log + chmod 644 /var/log/pihole.log + chown dnsmasq:root /var/log/pihole.log + echo " done!" else - ${SUDO} echo " already exists!" + echo " already exists!" fi } installPiholeWeb() { # Install the web interface - ${SUDO} echo ":::" - ${SUDO} echo -n "::: Installing pihole custom index page..." + echo ":::" + echo -n "::: Installing pihole custom index page..." if [ -d "/var/www/html/pihole" ]; then - ${SUDO} echo " Existing page detected, not overwriting" + echo " Existing page detected, not overwriting" else - ${SUDO} mkdir /var/www/html/pihole + mkdir /var/www/html/pihole if [ -f /var/www/html/index.lighttpd.html ]; then - ${SUDO} mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig + mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig else printf "\n:::\tNo default index.lighttpd.html file found... not backing up" fi - ${SUDO} cp /etc/.pihole/advanced/index.* /var/www/html/pihole/. - ${SUDO} echo " done!" + cp /etc/.pihole/advanced/index.* /var/www/html/pihole/. + echo " done!" fi # Install Sudoer file echo -n "::: Installing sudoer file..." - ${SUDO} mkdir -p /etc/sudoers.d/ - ${SUDO} cp /etc/.pihole/advanced/pihole.sudo /etc/sudoers.d/pihole - ${SUDO} chmod 0440 /etc/sudoers.d/pihole + mkdir -p /etc/sudoers.d/ + cp /etc/.pihole/advanced/pihole.sudo /etc/sudoers.d/pihole + chmod 0440 /etc/sudoers.d/pihole echo " done!" } installCron() { # Install the cron job - ${SUDO} echo ":::" - ${SUDO} echo -n "::: Installing latest Cron script..." - ${SUDO} cp /etc/.pihole/advanced/pihole.cron /etc/cron.d/pihole - ${SUDO} echo " done!" + echo ":::" + echo -n "::: Installing latest Cron script..." + cp /etc/.pihole/advanced/pihole.cron /etc/cron.d/pihole + echo " done!" } runGravity() { # Rub gravity.sh to build blacklists - ${SUDO} echo ":::" - ${SUDO} echo "::: Preparing to run gravity.sh to refresh hosts..." + echo ":::" + echo "::: Preparing to run gravity.sh to refresh hosts..." if ls /etc/pihole/list* 1> /dev/null 2>&1; then echo "::: Cleaning up previous install (preserving whitelist/blacklist)" - ${SUDO} rm /etc/pihole/list.* + rm /etc/pihole/list.* fi echo "::: Running gravity.sh" - ${SUDO} /opt/pihole/gravity.sh + /opt/pihole/gravity.sh } setUser(){ @@ -752,41 +756,41 @@ setUser(){ echo "::: User 'pihole' already exists" else echo "::: User 'pihole' doesn't exist. Creating..." - ${SUDO} useradd -r -s /usr/sbin/nologin pihole + useradd -r -s /usr/sbin/nologin pihole fi } configureFirewall() { # Allow HTTP and DNS traffic if [ -x "$(command -v firewall-cmd)" ]; then - ${SUDO} firewall-cmd --state > /dev/null + firewall-cmd --state > /dev/null if [[ $? -eq 0 ]]; then - ${SUDO} echo "::: Configuring firewalld for httpd and dnsmasq.." - ${SUDO} firewall-cmd --permanent --add-port=80/tcp - ${SUDO} firewall-cmd --permanent --add-port=53/tcp - ${SUDO} firewall-cmd --permanent --add-port=53/udp - ${SUDO} firewall-cmd --reload + echo "::: Configuring firewalld for httpd and dnsmasq.." + firewall-cmd --permanent --add-port=80/tcp + firewall-cmd --permanent --add-port=53/tcp + firewall-cmd --permanent --add-port=53/udp + firewall-cmd --reload fi elif [ -x "$(command -v iptables)" ]; then - ${SUDO} echo "::: Configuring iptables for httpd and dnsmasq.." - ${SUDO} iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT - ${SUDO} iptables -A INPUT -p tcp -m tcp --dport 53 -j ACCEPT - ${SUDO} iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT + echo "::: Configuring iptables for httpd and dnsmasq.." + iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT + iptables -A INPUT -p tcp -m tcp --dport 53 -j ACCEPT + iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT else - ${SUDO} echo "::: No firewall detected.. skipping firewall configuration." + echo "::: No firewall detected.. skipping firewall configuration." fi } finalExports() { #If it already exists, lets overwrite it with the new values. if [[ -f ${setupVars} ]];then - ${SUDO} rm ${setupVars} + rm ${setupVars} fi - ${SUDO} echo "piholeInterface=${piholeInterface}" >> ${setupVars} - ${SUDO} echo "IPv4addr=${IPv4addr}" >> ${setupVars} - ${SUDO} echo "piholeIPv6=${piholeIPv6}" >> ${setupVars} - ${SUDO} echo "piholeDNS1=${piholeDNS1}" >> ${setupVars} - ${SUDO} echo "piholeDNS2=${piholeDNS2}" >> ${setupVars} + echo "piholeInterface=${piholeInterface}" >> ${setupVars} + echo "IPv4addr=${IPv4addr}" >> ${setupVars} + echo "piholeIPv6=${piholeIPv6}" >> ${setupVars} + echo "piholeDNS1=${piholeDNS1}" >> ${setupVars} + echo "piholeDNS2=${piholeDNS2}" >> ${setupVars} } @@ -796,13 +800,13 @@ installPihole() { stopServices setUser if [ ! -d "/var/www/html" ]; then - ${SUDO} mkdir -p /var/www/html + mkdir -p /var/www/html fi - ${SUDO} chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/www/html - ${SUDO} chmod 775 /var/www/html - ${SUDO} usermod -a -G ${LIGHTTPD_GROUP} pihole + chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/www/html + chmod 775 /var/www/html + usermod -a -G ${LIGHTTPD_GROUP} pihole if [ -x "$(command -v lighty-enable-mod)" ]; then - ${SUDO} lighty-enable-mod fastcgi fastcgi-php > /dev/null + lighty-enable-mod fastcgi fastcgi-php > /dev/null else printf "\n:::\tWarning: 'lighty-enable-mod' utility not found. Please ensure fastcgi is enabled if you experience issues.\n" fi @@ -841,22 +845,22 @@ configureSelinux() { package_check "selinux-policy-devel" > /dev/null if ! [ $? -eq 0 ]; then echo -n " Not found! Installing...." - ${SUDO} ${PKG_INSTALL} "selinux-policy-devel" > /dev/null & spinner $! + ${PKG_INSTALL} "selinux-policy-devel" > /dev/null & spinner $! echo " done!" else echo " already installed!" fi printf "::: Enabling httpd server side includes (SSI).. " - ${SUDO} setsebool -P httpd_ssi_exec on + setsebool -P httpd_ssi_exec on if [ $? -eq 0 ]; then echo -n "Success" fi printf "\n:::\tCompiling Pi-Hole SELinux policy..\n" - ${SUDO} checkmodule -M -m -o /etc/pihole/pihole.mod /etc/.pihole/advanced/selinux/pihole.te - ${SUDO} semodule_package -o /etc/pihole/pihole.pp -m /etc/pihole/pihole.mod - ${SUDO} semodule -i /etc/pihole/pihole.pp - ${SUDO} rm -f /etc/pihole/pihole.mod - ${SUDO} semodule -l | grep pihole > /dev/null + checkmodule -M -m -o /etc/pihole/pihole.mod /etc/.pihole/advanced/selinux/pihole.te + semodule_package -o /etc/pihole/pihole.pp -m /etc/pihole/pihole.mod + semodule -i /etc/pihole/pihole.pp + rm -f /etc/pihole/pihole.mod + semodule -l | grep pihole > /dev/null if [ $? -eq 0 ]; then printf "::: Successfully installed Pi-Hole SELinux policy\n" else @@ -929,7 +933,7 @@ installerDependencies if [[ ${useUpdateVars} == false ]]; then welcomeDialogs - ${SUDO} mkdir -p /etc/pihole/ + mkdir -p /etc/pihole/ # Find IP used to route to outside world findIPRoute # Find interfaces and let the user choose one @@ -945,7 +949,7 @@ else fi # Move the log file into /etc/pihole for storage -${SUDO} mv ${tmpLog} ${instalLogLoc} +mv ${tmpLog} ${instalLogLoc} if [[ ${useUpdateVars} == false ]]; then displayFinalMessage @@ -954,13 +958,13 @@ fi echo -n "::: Restarting services..." # Start services if [ -x "$(command -v systemctl)" ]; then - ${SUDO} systemctl enable dnsmasq - ${SUDO} systemctl restart dnsmasq - ${SUDO} systemctl enable lighttpd - ${SUDO} systemctl start lighttpd + systemctl enable dnsmasq + systemctl restart dnsmasq + systemctl enable lighttpd + systemctl start lighttpd else - ${SUDO} service dnsmasq restart - ${SUDO} service lighttpd start + service dnsmasq restart + service lighttpd start fi echo " done." From 10e1a03c7667488a658e0b2380a442cf711ccfc5 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 8 Oct 2016 12:58:42 -0700 Subject: [PATCH 13/18] `runGravity` is called after `finalExports` in the Debian install side. --- automated install/basic-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index c6f409fb..15aa3dcb 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -818,9 +818,9 @@ installPihole() { configureSelinux installPiholeWeb installCron - runGravity configureFirewall finalExports + runGravity } updatePihole() { @@ -834,8 +834,8 @@ updatePihole() { configureSelinux installPiholeWeb installCron - runGravity configureFirewall + runGravity } configureSelinux() { From b157bc5cd7b36be5ef77229a75753bca837d7283 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 8 Oct 2016 13:47:35 -0700 Subject: [PATCH 14/18] Fixes #768 Check the staleness of the package index instead of the package cache. --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 4dab9355..01fa3824 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -68,7 +68,7 @@ if [ -x "$(command -v apt-get)" ];then fi ############################################# PKG_MANAGER="apt-get" - PKG_CACHE="/var/cache/apt" + PKG_CACHE="/var/lib/apt/lists/" UPDATE_PKG_CACHE="$PKG_MANAGER -qq update" PKG_UPDATE="$PKG_MANAGER upgrade" PKG_INSTALL="$PKG_MANAGER --yes --quiet install" From 6772603c15a4b6bf46196347e3fc59ff291bcae3 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 9 Oct 2016 12:34:53 -0700 Subject: [PATCH 15/18] Relocate cache check to its own function --- automated install/basic-install.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 964d6b26..a06de223 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -73,9 +73,9 @@ if [ -x "$(command -v apt-get)" ];then ############################################# PKG_MANAGER="apt-get" PKG_CACHE="/var/lib/apt/lists/" - UPDATE_PKG_CACHE="$PKG_MANAGER -qq update" + UPDATE_PKG_CACHE="$PKG_MANAGER update" PKG_UPDATE="$PKG_MANAGER upgrade" - PKG_INSTALL="$PKG_MANAGER --yes --quiet install" + PKG_INSTALL="$PKG_MANAGER --yes install" PKG_COUNT="$PKG_MANAGER -s -o Debug::NoLocking=true upgrade | grep -c ^Inst" INSTALLER_DEPS=( apt-utils whiptail dhcpcd5) PIHOLE_DEPS=( dnsutils bc dnsmasq lighttpd ${phpVer}-common ${phpVer}-cgi git curl unzip wget sudo netcat cron iproute2 ) @@ -83,7 +83,7 @@ if [ -x "$(command -v apt-get)" ];then LIGHTTPD_GROUP="www-data" LIGHTTPD_CFG="lighttpd.conf.debian" package_check() { - dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed" + dpkg-query -W -f='${Status}' "$1" | grep -c "ok installed" } elif [ -x "$(command -v rpm)" ];then # Fedora Family @@ -582,11 +582,12 @@ stopServices() { echo " done." } -installerDependencies() { +check_cache_freshness() { #Running apt-get update/upgrade with minimal output can cause some issues with #requiring user input (e.g password for phpmyadmin see #218) #We'll change the logic up here, to check to see if there are any updates availible and # if so, advise the user to run apt-get update/upgrade at their own discretion + #Check to see if apt-get update has already been run today # it needs to have been run at least once on new installs! timestamp=$(stat -c %Y ${PKG_CACHE}) @@ -612,12 +613,14 @@ installerDependencies() { echo "::: We recommend you run '$PKG_UPDATE' after installing Pi-Hole! " echo ":::" fi +} + +installerDependencies() { echo ":::" echo "::: Checking installer dependencies..." for i in "${INSTALLER_DEPS[@]}"; do echo -n "::: Checking for $i..." - package_check ${i} > /dev/null - if ! [ $? -eq 0 ]; then + if ! package_check ${i} &>/dev/null; then echo -n " Not found! Installing...." ${PKG_INSTALL} "$i" > /dev/null 2>&1 echo " done!" @@ -928,6 +931,9 @@ else verifyFreeDiskSpace fi +# Check the package cache and update if necessary +check_cache_freshness + # Install packages used by this installation script installerDependencies From f5be8b2a5e96f7039d4681655d3f5899d3109ea1 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 9 Oct 2016 13:43:01 -0700 Subject: [PATCH 16/18] Single dependency package check function, will exit if any errors with message to update cache. --- automated install/basic-install.sh | 43 +++++++++++++----------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index a06de223..8da5f8b8 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -615,38 +615,28 @@ check_cache_freshness() { fi } -installerDependencies() { - echo ":::" - echo "::: Checking installer dependencies..." - for i in "${INSTALLER_DEPS[@]}"; do +dependency_package_install() { + # Install and verify package installation, exit out if any errors are detected + # Takes array as argument then iterates over array + declare -a argArray1=("${!1}") + + for i in "${argArray1[@]}"; do echo -n "::: Checking for $i..." if ! package_check ${i} &>/dev/null; then echo -n " Not found! Installing...." ${PKG_INSTALL} "$i" > /dev/null 2>&1 - echo " done!" + if ! package_check ${i} &>/dev/null; then + echo "::: ERROR, package ${i} has not been installed, please run ${UPDATE_PKG_CACHE} and try install again." + exit 1 + else + echo " done!" + fi else echo " already installed!" fi done } -checkForDependencies() { - # Install dependencies for Pi-Hole - echo "::: Checking Pi-Hole dependencies:" - - for i in "${PIHOLE_DEPS[@]}"; do - echo -n "::: Checking for $i..." - package_check ${i} > /dev/null - if ! [ $? -eq 0 ]; then - echo -n " Not found! Installing...." - ${PKG_INSTALL} "$i" > /dev/null & spinner $! - echo " done!" - else - echo " already installed!" - fi - done -} - getGitFiles() { # Setup git repos for base files and web admin echo ":::" @@ -799,7 +789,8 @@ finalExports() { installPihole() { # Install base files and web interface - checkForDependencies # done + echo "Checking for Pi-hole dependencies" + dependency_package_install PIHOLE_DEPS[@] # done stopServices setUser if [ ! -d "/var/www/html" ]; then @@ -828,7 +819,8 @@ installPihole() { updatePihole() { # Install base files and web interface - checkForDependencies # done + echo "Checking for Pi-hole dependencies" + dependency_package_install PIHOLE_DEPS[@] # done stopServices getGitFiles installScripts @@ -935,7 +927,8 @@ fi check_cache_freshness # Install packages used by this installation script -installerDependencies +echo "::: Checking for installer dependencies..." +dependency_package_install INSTALLER_DEPS[@] if [[ ${useUpdateVars} == false ]]; then welcomeDialogs From 293c60fb9cadc8d1479c8dff3a1f7a48d749e772 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 9 Oct 2016 13:52:36 -0700 Subject: [PATCH 17/18] Exit script on failure to install dependent package. --- automated install/basic-install.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 8da5f8b8..65812cc5 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -790,7 +790,9 @@ finalExports() { installPihole() { # Install base files and web interface echo "Checking for Pi-hole dependencies" - dependency_package_install PIHOLE_DEPS[@] # done + if ! dependency_package_install PIHOLE_DEPS[@]; then + exit 1 + fi stopServices setUser if [ ! -d "/var/www/html" ]; then @@ -820,7 +822,9 @@ installPihole() { updatePihole() { # Install base files and web interface echo "Checking for Pi-hole dependencies" - dependency_package_install PIHOLE_DEPS[@] # done + if ! dependency_package_install PIHOLE_DEPS[@]; then + exit 1 + fi stopServices getGitFiles installScripts @@ -928,7 +932,9 @@ check_cache_freshness # Install packages used by this installation script echo "::: Checking for installer dependencies..." -dependency_package_install INSTALLER_DEPS[@] +if ! dependency_package_install INSTALLER_DEPS[@]; then + exit 1 +fi if [[ ${useUpdateVars} == false ]]; then welcomeDialogs From 7e0afffca8f196d21a0333c1a660ed1d6a756c15 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 9 Oct 2016 19:41:32 -0700 Subject: [PATCH 18/18] Revert inadvertent commits --- automated install/basic-install.sh | 67 ++++++++++++++---------------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 65812cc5..cbd1c9b0 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -73,9 +73,9 @@ if [ -x "$(command -v apt-get)" ];then ############################################# PKG_MANAGER="apt-get" PKG_CACHE="/var/lib/apt/lists/" - UPDATE_PKG_CACHE="$PKG_MANAGER update" + UPDATE_PKG_CACHE="$PKG_MANAGER -qq update" PKG_UPDATE="$PKG_MANAGER upgrade" - PKG_INSTALL="$PKG_MANAGER --yes install" + PKG_INSTALL="$PKG_MANAGER --yes --quiet install" PKG_COUNT="$PKG_MANAGER -s -o Debug::NoLocking=true upgrade | grep -c ^Inst" INSTALLER_DEPS=( apt-utils whiptail dhcpcd5) PIHOLE_DEPS=( dnsutils bc dnsmasq lighttpd ${phpVer}-common ${phpVer}-cgi git curl unzip wget sudo netcat cron iproute2 ) @@ -83,7 +83,7 @@ if [ -x "$(command -v apt-get)" ];then LIGHTTPD_GROUP="www-data" LIGHTTPD_CFG="lighttpd.conf.debian" package_check() { - dpkg-query -W -f='${Status}' "$1" | grep -c "ok installed" + dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed" } elif [ -x "$(command -v rpm)" ];then # Fedora Family @@ -582,12 +582,11 @@ stopServices() { echo " done." } -check_cache_freshness() { +installerDependencies() { #Running apt-get update/upgrade with minimal output can cause some issues with #requiring user input (e.g password for phpmyadmin see #218) #We'll change the logic up here, to check to see if there are any updates availible and # if so, advise the user to run apt-get update/upgrade at their own discretion - #Check to see if apt-get update has already been run today # it needs to have been run at least once on new installs! timestamp=$(stat -c %Y ${PKG_CACHE}) @@ -613,30 +612,38 @@ check_cache_freshness() { echo "::: We recommend you run '$PKG_UPDATE' after installing Pi-Hole! " echo ":::" fi -} - -dependency_package_install() { - # Install and verify package installation, exit out if any errors are detected - # Takes array as argument then iterates over array - declare -a argArray1=("${!1}") - - for i in "${argArray1[@]}"; do + echo ":::" + echo "::: Checking installer dependencies..." + for i in "${INSTALLER_DEPS[@]}"; do echo -n "::: Checking for $i..." - if ! package_check ${i} &>/dev/null; then + package_check ${i} > /dev/null + if ! [ $? -eq 0 ]; then echo -n " Not found! Installing...." ${PKG_INSTALL} "$i" > /dev/null 2>&1 - if ! package_check ${i} &>/dev/null; then - echo "::: ERROR, package ${i} has not been installed, please run ${UPDATE_PKG_CACHE} and try install again." - exit 1 - else - echo " done!" - fi + echo " done!" else echo " already installed!" fi done } +checkForDependencies() { + # Install dependencies for Pi-Hole + echo "::: Checking Pi-Hole dependencies:" + + for i in "${PIHOLE_DEPS[@]}"; do + echo -n "::: Checking for $i..." + package_check ${i} > /dev/null + if ! [ $? -eq 0 ]; then + echo -n " Not found! Installing...." + ${PKG_INSTALL} "$i" > /dev/null & spinner $! + echo " done!" + else + echo " already installed!" + fi + done +} + getGitFiles() { # Setup git repos for base files and web admin echo ":::" @@ -789,10 +796,7 @@ finalExports() { installPihole() { # Install base files and web interface - echo "Checking for Pi-hole dependencies" - if ! dependency_package_install PIHOLE_DEPS[@]; then - exit 1 - fi + checkForDependencies # done stopServices setUser if [ ! -d "/var/www/html" ]; then @@ -821,10 +825,7 @@ installPihole() { updatePihole() { # Install base files and web interface - echo "Checking for Pi-hole dependencies" - if ! dependency_package_install PIHOLE_DEPS[@]; then - exit 1 - fi + checkForDependencies # done stopServices getGitFiles installScripts @@ -927,14 +928,8 @@ else verifyFreeDiskSpace fi -# Check the package cache and update if necessary -check_cache_freshness - # Install packages used by this installation script -echo "::: Checking for installer dependencies..." -if ! dependency_package_install INSTALLER_DEPS[@]; then - exit 1 -fi +installerDependencies if [[ ${useUpdateVars} == false ]]; then welcomeDialogs @@ -990,4 +985,4 @@ echo "::: The install log is located at: /etc/pihole/install.log" echo "::: View the web interface at http://pi.hole/admin or http://${IPv4addr%/*}/admin" } -main "$@" \ No newline at end of file +main "$@"