From b8f48d1bce621fa136af96f2ea765b85780b924e Mon Sep 17 00:00:00 2001 From: Promofaux Date: Wed, 27 Jan 2016 21:09:34 +0000 Subject: [PATCH] Add in apt-get update if it has not been run today. Otherwise, check number of upgrades availible, advise user there are updates, and at their choice, either continue or cancel the installation --- automated install/basic-install.sh | 41 ++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 6b0e304f..d9046089 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -16,7 +16,7 @@ # # curl -L install.pi-hole.net | bash -$SUDO mkdir -p /etc/pihole/ + ######## VARIABLES ######### tmpLog=/tmp/pihole-install.log @@ -63,7 +63,7 @@ else fi fi -if [ -f "/etc/dnsmasq.d/01-pihole.conf" ]; then +if [ -d "/etc/pihole" ]; then #Likely an existing install upgrade=true else @@ -260,7 +260,9 @@ setStaticIPv4(){ else setDHCPCD $SUDO ip addr replace dev $piholeInterface $IPv4addr - echo "Setting IP to $IPv4addr. You may need to restart after the install is complete." + echo ":::" + echo "::: Setting IP to $IPv4addr. You may need to restart after the install is complete." + echo ":::" fi } @@ -273,7 +275,7 @@ installScripts(){ $SUDO cp /etc/.pihole/advanced/Scripts/blacklist.sh /usr/local/bin/blacklist.sh $SUDO cp /etc/.pihole/advanced/Scripts/piholeLogFlush.sh /usr/local/bin/piholeLogFlush.sh $SUDO cp /etc/.pihole/advanced/Scripts/updateDashboard.sh /usr/local/bin/updateDashboard.sh - $SUDO chmod 755 /usr/local/bin/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard}.sh + $SUDO chmod 755 /usr/local/bin/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard}.sh $SUDO echo " done." } @@ -303,19 +305,33 @@ checkForDependencies(){ #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 /var/cache/apt/) + timestampAsDate=$(date -d @$timestamp "+%b %e") today=$(date "+%b %e") - echo ":::" + + if [ ! "$today" == "$timestampAsDate" ]; then + #update package lists + echo ":::" + echo -n "::: apt-get update has not been run today. Running now..." + $SUDO apt-get -qq update & spinner $! + echo " done!" + fi + + echo ":::" echo -n "::: Checking apt-get for upgraded packages...." - updatesToInstall=$(sudo apt-get -s -o Debug::NoLocking=true upgrade | grep -c ^Inst) & spinner $! + updatesToInstall=$(sudo apt-get -s -o Debug::NoLocking=true upgrade | grep -c ^Inst) echo " done!" - + echo ":::" - if [[ $updatesToInstall -eq 0 ]]; then + if [[ $updatesToInstall -eq "0" ]]; then echo "::: Your pi is up to date! Continuing with pi-hole installation..." else echo "::: There are $updatesToInstall updates availible for your pi!" - echo "::: Please consider running 'sudo apt-get update', followed by 'sudo apt-get upgrade'" - echo "::: after pi-hole has finished installing." + echo "::: Please consider running 'sudo apt-get upgrade' before continuing with installation" echo ":::" #add in a prompt to give users the option to quit installation or continue echo -n "::: Would you like to continue with the pi-hole installation? (Y/n):" @@ -324,7 +340,7 @@ checkForDependencies(){ case "$answer" in [yY][eE][sS]|[yY] ) echo "::: Continuing!";; * ) echo "::: Quitting install, please run 'curl -L install.pi-hole.net | bash' after updating packages!" - exit 0;; + exit 1;; esac fi @@ -480,6 +496,7 @@ The install log is in /etc/pihole." $r $c ######## SCRIPT ############ # Start the installer +$SUDO mkdir -p /etc/pihole/ welcomeDialogs # Just back up the original Pi-hole right away since it won't take long and it gets it out of the way @@ -489,8 +506,6 @@ chooseInterface # Let the user decide if they want to block ads over IPv4 and/or IPv6 use4andor6 - - # Install and log everything to a file installPihole | tee $tmpLog