From 6daf80ef56698e917b188967e075a4873eca4bb0 Mon Sep 17 00:00:00 2001 From: jacobsalmela Date: Fri, 18 Mar 2016 18:01:51 -0500 Subject: [PATCH] add update mechanism This is some nice code found on stack overflow that I have been using for a while that seems very reliable. I just commented out a few things since we really only want to check if it needs an update or if it is already up to date. --- advanced/Scripts/updatePihole | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 advanced/Scripts/updatePihole diff --git a/advanced/Scripts/updatePihole b/advanced/Scripts/updatePihole new file mode 100644 index 00000000..5a4f31f8 --- /dev/null +++ b/advanced/Scripts/updatePihole @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# Pi-hole: A black hole for Internet advertisements +# (c) 2015, 2016 by Jacob Salmela +# Network-wide ad blocking via your Raspberry Pi +# http://pi-hole.net +# Checks if Pi-hole needs updating and then +# +# Pi-hole is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. + +# Taken from http://stackoverflow.com/questions/3258243/check-if-pull-needed-in-git + +# Move into the git directory +cd /etc/.pihole/ + +LOCAL=$(git rev-parse @) +REMOTE=$(git rev-parse @{u}) +BASE=$(git merge-base @ @{u}) + +if [[ $LOCAL = $REMOTE ]]; then + echo "Up-to-date" +elif [[ $LOCAL = $BASE ]]; then + echo "Updating Pi-hole..." + git pull +elif [[ $REMOTE = $BASE ]]; then + : # Need to push, so do nothing +else + : # Diverged, so do nothing +fi