From 81939ab265f9b85516f673df3b3b13467371ded7 Mon Sep 17 00:00:00 2001
From: Dan Schaper <dan.schaper@pi-hole.net>
Date: Fri, 3 Mar 2017 19:14:30 -0800
Subject: [PATCH] Get short hash of local and remote

Signed-off-by: Dan Schaper <dan.schaper@pi-hole.net>
---
 advanced/Scripts/version.sh | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh
index 11a7af00..27166507 100755
--- a/advanced/Scripts/version.sh
+++ b/advanced/Scripts/version.sh
@@ -17,11 +17,34 @@ current=false
 DEFAULT="-1"
 
 normalOutput() {
-	piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0)
-	webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0)
+	piholeVersion=$(cd /etc/.pihole/ \
+	                && git describe --tags --abbrev=0)
+	webVersion=$(cd /var/www/html/admin/ \
+	             && 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/",$//')
-	webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' |  perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
+	piholeHash=$(cd /etc/.pihole/ \
+	             && git rev-parse --short HEAD)
+	webHash=$(cd /var/www/html/admin/ \
+	          && git rev-parse --short HEAD)
+
+	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/",$//')
+	webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | \
+	                   grep -Po '"tag_name":.*?[^\\]",' | \
+	                   perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
+
+  piholeHashLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/commits/master | \
+                     grep sha | \
+                     head -n1 | \
+                     awk -F ' ' '{ print $2}' | \
+                     tr -cd '[[:alnum:]]._-')
+
+  piholeHashLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/commits/master | \
+                     grep sha | \
+                     head -n1 | \
+                     awk -F ' ' '{ print $2}' | \
+                     tr -cd '[[:alnum:]]._-')
 
 	echo "::: Pi-hole version is ${piholeVersion} (Latest version is ${piholeVersionLatest:-${DEFAULT}})"
 	echo "::: Web-Admin version is ${webVersion} (Latest version is ${webVersionLatest:-${DEFAULT}})"