From 0229f7076176e777dbba05681fbcd2200280697c Mon Sep 17 00:00:00 2001 From: Promofaux Date: Mon, 12 Sep 2016 18:29:04 +0100 Subject: [PATCH] Make updatePiholeFunc a bit smarter. Only run update if version is not the latest. --- pihole | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/pihole b/pihole index d6da8366..f23db60e 100755 --- a/pihole +++ b/pihole @@ -53,10 +53,26 @@ function updateDashboardFunc { } function updatePiholeFunc { - echo "::: Fetching latest changes from Github..." - cd /etc/.pihole - ${SUDO} git pull origin master - ${SUDO} /etc/.pihole/automated\ install/basic-install.sh pihole + echo "::: Checking for updates..." + piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) + piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') + + if [[ ${piholeVersion} == ${piholeVersionLatest} ]] ; then + echo "::: Pi-hole is already up to date! Version: ${piholeVersion}" + echo ":::" + echo "::: No need to update!" + else + echo "::: An update is available! Current Version: ${piholeVersion}" + echo "::: Latest Version: ${piholeVersionLatest}" + echo ":::" + echo "::: Fetching latest changes from Github..." + cd /etc/.pihole + ${SUDO} git pull origin master + ${SUDO} /etc/.pihole/automated\ install/basic-install.sh pihole + echo ":::" + echo "::: Pi-hole has been updated, see https://changes.pi-hole.net for details" + fi + exit 1 }