1
0
mirror of https://github.com/pi-hole/pi-hole synced 2024-11-18 14:18:15 +00:00

Functions for Core/Web version and hash. And only check first argument in each section.

Signed-off-by: Dan Schaper <dan.schaper@pi-hole.net>
This commit is contained in:
Dan Schaper 2017-03-03 22:10:32 -08:00
parent 8831b22fc8
commit ed8088f203
No known key found for this signature in database
GPG Key ID: 572E999E385B7BFC

View File

@ -8,10 +8,6 @@
# This file is copyright under the latest version of the EUPL. # This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license. # Please see LICENSE file for your rights under this license.
# Flags:
latest=false
current=false
# Variables # Variables
DEFAULT="-1" DEFAULT="-1"
PHGITDIR="/etc/.pihole/" PHGITDIR="/etc/.pihole/"
@ -20,27 +16,54 @@ WEBGITDIR="/var/www/html/admin/"
getLocalPHVersion(){ getLocalPHVersion(){
# Get the tagged version of the local Pi-hole repository # Get the tagged version of the local Pi-hole repository
local version local version
local hash
cd "${PHGITDIR}" || { PHVERSION="${DEFAULT}"; return -1; } cd "${PHGITDIR}" || { PHVERSION="${DEFAULT}"; return 1; }
version=$(git describe --tags --always || \ version=$(git describe --tags --always || \
echo "${DEFAULT}") echo "${DEFAULT}")
if [[ "${version}" =~ ^v ]]; then if [[ "${version}" =~ ^v ]]; then
PHVERSION="${version}" PHVERSION="${version}"
elif [[ "${version}" == "-1" ]]; then elif [[ "${version}" == "${DEFAULT}" ]]; then
PHVERSION="ERROR" PHVERSION="ERROR"
else else
PHVERSION="Untagged" PHVERSION="Untagged"
fi fi
hash=$(git rev-parse --short HEAD || \
echo "${DEFAULT}")
if [[ "${hash}" == "${DEFAULT}" ]]; then
PHHASH="ERROR"
else
PHHASH="${hash}"
fi
return 0 return 0
} }
WEBVERSION=$(cd /var/www/html/admin/ \ getLocalWebVersion(){
&& git describe --tags --always) # Get the tagged version of the local Pi-hole repository
local version
local hash
PHHASH=$(cd /etc/.pihole/ \ cd "${WEBGITDIR}" || { WEBVERSION="${DEFAULT}"; return 1; }
&& git rev-parse --short HEAD) version=$(git describe --tags --always || \
WEBHASH=$(cd /var/www/html/admin/ \ echo "${DEFAULT}")
&& git rev-parse --short HEAD) if [[ "${version}" =~ ^v ]]; then
WEBVERSION="${version}"
elif [[ "${version}" == "${DEFAULT}" ]]; then
WEBVERSION="ERROR"
else
WEBVERSION="Untagged"
fi
hash=$(git rev-parse --short HEAD || \
echo "${DEFAULT}")
if [[ "${hash}" == "${DEFAULT}" ]]; then
WEBHASH="ERROR"
else
WEBHASH="${hash}"
fi
return 0
}
PHVERSIONLATEST=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | \ PHVERSIONLATEST=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | \
grep -Po '"tag_name":.*?[^\\]",' | \ grep -Po '"tag_name":.*?[^\\]",' | \
@ -64,14 +87,14 @@ WEBHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/commits/ma
normalOutput() { normalOutput() {
echo "::: Pi-hole version is ${PHVERSION} (Latest version is ${PHVERSIONLATEST:-${DEFAULT}})" echo "::: Pi-hole version is ${PHVERSION} (Latest version is ${PHVERSIONLATEST:-${DEFAULT}})"
echo "::: Web-Admin version is ${WEBVERSION:-Untagged} (Latest version is ${WEBVERSIONLATEST:-${DEFAULT}})" echo "::: Web-Admin version is ${WEBVERSION} (Latest version is ${WEBVERSIONLATEST:-${DEFAULT}})"
} }
webOutput() { webOutput() {
for var in "$@"; do for var in "$1"; do
case "${var}" in case "${var}" in
"-l" | "--latest" ) echo "${WEBVERSIONLATEST:-${DEFAULT}}";; "-l" | "--latest" ) echo "${WEBVERSIONLATEST:-${DEFAULT}}";;
"-c" | "--current" ) echo "${WEBVERSION:-Untagged}";; "-c" | "--current" ) echo "${WEBVERSION}";;
"-h" | "--hash" ) echo "${WEBHASH}";; "-h" | "--hash" ) echo "${WEBHASH}";;
* ) echo "::: Invalid Option!"; exit 1; * ) echo "::: Invalid Option!"; exit 1;
esac esac
@ -79,7 +102,7 @@ webOutput() {
} }
coreOutput() { coreOutput() {
for var in "$@"; do for var in "$1"; do
case "${var}" in case "${var}" in
"-l" | "--latest" ) echo "${PHVERSIONLATEST:-${DEFAULT}}";; "-l" | "--latest" ) echo "${PHVERSIONLATEST:-${DEFAULT}}";;
"-c" | "--current" ) echo "${PHVERSION}";; "-c" | "--current" ) echo "${PHVERSION}";;
@ -108,12 +131,13 @@ EOM
} }
getLocalPHVersion getLocalPHVersion
getLocalWebVersion
if [[ $# = 0 ]]; then if [[ $# = 0 ]]; then
normalOutput normalOutput
fi fi
for var in "$@"; do for var in "$1"; do
case "${var}" in case "${var}" in
"-a" | "--admin" ) shift; webOutput "$@";; "-a" | "--admin" ) shift; webOutput "$@";;
"-p" | "--pihole" ) shift; coreOutput "$@" ;; "-p" | "--pihole" ) shift; coreOutput "$@" ;;