2016-08-02 19:07:09 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Pi-hole: A black hole for Internet advertisements
|
2017-02-22 17:55:20 +00:00
|
|
|
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
|
|
|
# Network-wide ad blocking via your own hardware.
|
|
|
|
#
|
2016-10-18 13:19:44 +00:00
|
|
|
# shows version numbers
|
2016-08-02 19:07:09 +00:00
|
|
|
#
|
2017-02-22 17:55:20 +00:00
|
|
|
# This file is copyright under the latest version of the EUPL.
|
|
|
|
# Please see LICENSE file for your rights under this license.
|
|
|
|
|
2017-03-04 04:16:53 +00:00
|
|
|
# Variables
|
2016-11-02 19:29:55 +00:00
|
|
|
DEFAULT="-1"
|
2017-05-11 03:34:58 +00:00
|
|
|
COREGITDIR="/etc/.pihole/"
|
2017-03-04 05:36:38 +00:00
|
|
|
WEBGITDIR="/var/www/html/admin/"
|
|
|
|
|
2017-03-04 07:12:28 +00:00
|
|
|
getLocalVersion() {
|
2017-05-11 03:34:58 +00:00
|
|
|
# FTL requires a different method
|
|
|
|
if [ "$1" == "FTL" ]; then
|
|
|
|
echo $(pihole-FTL version)
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2017-03-04 07:12:28 +00:00
|
|
|
# Get the tagged version of the local repository
|
|
|
|
local directory="${1}"
|
2017-03-04 05:36:38 +00:00
|
|
|
local version
|
|
|
|
|
2017-03-04 07:12:28 +00:00
|
|
|
cd "${directory}" || { echo "${DEFAULT}"; return 1; }
|
2017-03-04 05:36:38 +00:00
|
|
|
version=$(git describe --tags --always || \
|
|
|
|
echo "${DEFAULT}")
|
|
|
|
if [[ "${version}" =~ ^v ]]; then
|
2017-03-04 07:12:28 +00:00
|
|
|
echo "${version}"
|
2017-03-04 06:10:32 +00:00
|
|
|
elif [[ "${version}" == "${DEFAULT}" ]]; then
|
2017-03-04 07:12:28 +00:00
|
|
|
echo "ERROR"
|
|
|
|
return 1
|
2017-03-04 06:10:32 +00:00
|
|
|
else
|
2017-03-04 07:12:28 +00:00
|
|
|
echo "Untagged"
|
2017-03-04 06:10:32 +00:00
|
|
|
fi
|
2017-03-04 05:36:38 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2017-03-04 07:12:28 +00:00
|
|
|
getLocalHash() {
|
2017-05-11 03:34:58 +00:00
|
|
|
# FTL hash is not applicable
|
|
|
|
if [ "$1" == "FTL" ]; then
|
|
|
|
echo "N/A"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2017-03-04 07:12:28 +00:00
|
|
|
# Get the short hash of the local repository
|
|
|
|
local directory="${1}"
|
2017-03-04 06:10:32 +00:00
|
|
|
local hash
|
|
|
|
|
2017-03-04 07:12:28 +00:00
|
|
|
cd "${directory}" || { echo "${DEFAULT}"; return 1; }
|
2017-03-04 06:10:32 +00:00
|
|
|
hash=$(git rev-parse --short HEAD || \
|
|
|
|
echo "${DEFAULT}")
|
|
|
|
if [[ "${hash}" == "${DEFAULT}" ]]; then
|
2017-03-04 07:12:28 +00:00
|
|
|
echo "ERROR"
|
|
|
|
return 1
|
2017-03-04 06:10:32 +00:00
|
|
|
else
|
2017-03-04 07:12:28 +00:00
|
|
|
echo "${hash}"
|
2017-03-04 06:10:32 +00:00
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
2017-03-04 03:14:30 +00:00
|
|
|
|
2017-03-04 07:30:57 +00:00
|
|
|
getRemoteVersion(){
|
|
|
|
# Get the version from the remote origin
|
|
|
|
local daemon="${1}"
|
|
|
|
local version
|
|
|
|
|
|
|
|
version=$(curl --silent --fail https://api.github.com/repos/pi-hole/${daemon}/releases/latest | \
|
|
|
|
awk -F: '$1 ~/tag_name/ { print $2 }' | \
|
|
|
|
tr -cd '[[:alnum:]]._-')
|
|
|
|
if [[ "${version}" =~ ^v ]]; then
|
|
|
|
echo "${version}"
|
|
|
|
else
|
|
|
|
echo "ERROR"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
2017-03-04 03:14:30 +00:00
|
|
|
|
2017-05-11 03:34:58 +00:00
|
|
|
versionOutput() {
|
|
|
|
[ "$1" == "pi-hole" ] && GITDIR=${COREGITDIR}
|
|
|
|
[ "$1" == "AdminLTE" ] && GITDIR=${WEBGITDIR}
|
|
|
|
[ "$1" == "FTL" ] && GITDIR="FTL"
|
2017-05-10 03:07:56 +00:00
|
|
|
|
2017-05-11 03:34:58 +00:00
|
|
|
[ "$2" == "-c" -o "$2" == "--current" -o -z "$2" ] && current=$(getLocalVersion $GITDIR)
|
|
|
|
[ "$2" == "-l" -o "$2" == "--latest" -o -z "$2" ] && latest=$(getRemoteVersion $1)
|
|
|
|
[ "$2" == "-h" -o "$2" == "--hash" ] && hash=$(getLocalHash $GITDIR)
|
|
|
|
|
2017-05-10 03:07:56 +00:00
|
|
|
if [ -n "$current" -a -n "$latest" ]; then
|
2017-05-11 03:34:58 +00:00
|
|
|
output="${1^} version is $current (Latest: $latest)"
|
2017-05-10 03:07:56 +00:00
|
|
|
elif [ -n "$current" -a -z "$latest" ]; then
|
2017-05-11 03:34:58 +00:00
|
|
|
output="Current ${1^} version is $current"
|
2017-05-10 03:07:56 +00:00
|
|
|
elif [ -z "$current" -a -n "$latest" ]; then
|
2017-05-11 03:34:58 +00:00
|
|
|
output="Latest ${1^} version is $latest"
|
|
|
|
elif [ "$hash" == "N/A" ]; then
|
|
|
|
output=""
|
2017-05-10 03:07:56 +00:00
|
|
|
elif [ -n "$hash" ]; then
|
2017-05-11 03:34:58 +00:00
|
|
|
output="Current ${1^} hash is $hash"
|
2017-03-07 12:07:34 +00:00
|
|
|
else
|
2017-05-11 03:34:58 +00:00
|
|
|
errorOutput
|
2017-03-07 12:07:34 +00:00
|
|
|
fi
|
2017-05-10 22:30:49 +00:00
|
|
|
|
2017-05-11 03:34:58 +00:00
|
|
|
[ -n "$output" ] && echo " $output"
|
2016-10-18 11:07:11 +00:00
|
|
|
}
|
|
|
|
|
2017-05-11 03:34:58 +00:00
|
|
|
errorOutput() {
|
|
|
|
echo " Invalid Option! Try 'pihole -v --help' for more information."
|
|
|
|
exit 1
|
2017-05-10 03:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
defaultOutput() {
|
2017-05-11 03:34:58 +00:00
|
|
|
versionOutput "pi-hole" "$@"
|
|
|
|
versionOutput "AdminLTE" "$@"
|
|
|
|
versionOutput "FTL" "$@"
|
2016-10-18 11:07:11 +00:00
|
|
|
}
|
2016-10-18 11:05:48 +00:00
|
|
|
|
2016-10-20 02:47:45 +00:00
|
|
|
helpFunc() {
|
2017-05-10 03:07:56 +00:00
|
|
|
echo "Usage: pihole -v [REPO | OPTION] [OPTION]
|
|
|
|
Show Pi-hole, Web Admin & FTL versions
|
|
|
|
|
|
|
|
Repositories:
|
2017-05-11 03:34:58 +00:00
|
|
|
-p, --pihole Only retrieve info regarding Pi-hole repository
|
|
|
|
-a, --admin Only retrieve info regarding AdminLTE repository
|
|
|
|
-f, --ftl Only retrieve info regarding FTL repository
|
2017-05-10 03:07:56 +00:00
|
|
|
|
|
|
|
Options:
|
2017-05-11 03:34:58 +00:00
|
|
|
-c, --current Return the current version
|
|
|
|
-l, --latest Return the latest version
|
|
|
|
-h, --hash Return the Github hash from your local repositories
|
2017-05-10 03:07:56 +00:00
|
|
|
--help Show this help dialog
|
|
|
|
"
|
2016-12-01 23:10:06 +00:00
|
|
|
exit 0
|
2016-10-18 11:05:48 +00:00
|
|
|
}
|
|
|
|
|
2017-03-04 07:12:28 +00:00
|
|
|
case "${1}" in
|
2017-05-11 03:34:58 +00:00
|
|
|
"-p" | "--pihole" ) shift; versionOutput "pi-hole" "$@";;
|
|
|
|
"-a" | "--admin" ) shift; versionOutput "AdminLTE" "$@";;
|
|
|
|
"-f" | "--ftl" ) shift; versionOutput "FTL" "$@";;
|
2017-05-10 03:07:56 +00:00
|
|
|
"--help" ) helpFunc;;
|
|
|
|
* ) defaultOutput "$@";;
|
2017-03-04 07:12:28 +00:00
|
|
|
esac
|