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

This commit is contained in:
Promofaux 2016-01-27 21:09:34 +00:00
parent a05b6a4e12
commit b8f48d1bce

View file

@ -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
}
@ -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")
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