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-03-04 05:36:38 +00:00
|
|
|
PHGITDIR="/etc/.pihole/"
|
|
|
|
WEBGITDIR="/var/www/html/admin/"
|
|
|
|
|
2017-03-04 07:12:28 +00:00
|
|
|
getLocalVersion() {
|
|
|
|
# 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() {
|
|
|
|
# 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-10 03:07:56 +00:00
|
|
|
coreOutput() {
|
|
|
|
[ "$1" = "-c" -o "$1" = "--current" -o -z "$1" ] && current="$(getLocalVersion ${PHGITDIR})"
|
|
|
|
[ "$1" = "-l" -o "$1" = "--latest" -o -z "$1" ] && latest="$(getRemoteVersion pi-hole)"
|
2017-05-10 22:30:49 +00:00
|
|
|
[ "$1" = "-h" -o "$1" = "--hash" ] && hash="$(getLocalHash ${PHGITDIR})"
|
|
|
|
[ -n "$2" ] && error="true"
|
|
|
|
|
2017-05-10 03:07:56 +00:00
|
|
|
if [ -n "$current" -a -n "$latest" ]; then
|
|
|
|
str="Pi-hole version is $current (Latest: $latest)"
|
|
|
|
elif [ -n "$current" -a -z "$latest" ]; then
|
|
|
|
str="Current Pi-hole version is $current"
|
|
|
|
elif [ -z "$current" -a -n "$latest" ]; then
|
|
|
|
str="Latest Pi-hole version is $latest"
|
|
|
|
elif [ -n "$hash" ]; then
|
|
|
|
str="Current Pi-hole hash is $hash"
|
|
|
|
else
|
2017-05-11 00:11:04 +00:00
|
|
|
error="true"
|
2017-05-10 22:30:49 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$error" = "true" ]; then
|
2017-05-11 00:11:04 +00:00
|
|
|
echo " Invalid Option! Try 'pihole -v --help' for more information."
|
|
|
|
exit 1
|
2017-05-10 03:07:56 +00:00
|
|
|
fi
|
2017-05-10 22:30:49 +00:00
|
|
|
|
2017-05-10 03:07:56 +00:00
|
|
|
echo " $str"
|
2016-10-18 11:07:11 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 02:47:45 +00:00
|
|
|
webOutput() {
|
2017-05-10 03:07:56 +00:00
|
|
|
[ "$1" = "-c" -o "$1" = "--current" -o -z "$1" ] && current="$(getLocalVersion ${WEBGITDIR})"
|
|
|
|
[ "$1" = "-l" -o "$1" = "--latest" -o -z "$1" ] && latest="$(getRemoteVersion AdminLTE)"
|
2017-05-10 22:30:49 +00:00
|
|
|
[ "$1" = "-h" -o "$1" = "--hash" ] && hash="$(getLocalHash ${WEBGITDIR})"
|
2017-05-10 03:07:56 +00:00
|
|
|
[ ! -d "${WEBGITDIR}" ] && str="Web interface not installed!"
|
2017-05-10 22:30:49 +00:00
|
|
|
[ -n "$2" ] && error="true"
|
|
|
|
|
2017-05-10 03:07:56 +00:00
|
|
|
|
|
|
|
if [ -n "$current" -a -n "$latest" ]; then
|
|
|
|
str="Admin Console version is $current (Latest: $latest)"
|
|
|
|
elif [ -n "$current" -a -z "$latest" ]; then
|
|
|
|
str="Current Admin Console version is $current"
|
|
|
|
elif [ -z "$current" -a -n "$latest" ]; then
|
|
|
|
str="Latest Admin Console version is $latest"
|
|
|
|
elif [ -n "$hash" ]; then
|
|
|
|
str="Current Admin Console hash is $hash"
|
2017-03-07 12:07:34 +00:00
|
|
|
else
|
2017-05-11 00:11:04 +00:00
|
|
|
error="true"
|
2017-03-07 12:07:34 +00:00
|
|
|
fi
|
2017-05-10 22:30:49 +00:00
|
|
|
|
|
|
|
if [ "$error" = "true" ]; then
|
2017-05-11 00:11:04 +00:00
|
|
|
echo " Invalid Option! Try 'pihole -v --help' for more information."
|
|
|
|
exit 1
|
2017-05-10 22:30:49 +00:00
|
|
|
fi
|
|
|
|
|
2017-05-10 03:07:56 +00:00
|
|
|
echo " $str"
|
2016-10-18 11:07:11 +00:00
|
|
|
}
|
|
|
|
|
2017-05-10 03:07:56 +00:00
|
|
|
ftlOutput() {
|
|
|
|
[ "$1" = "-c" -o "$1" = "--current" -o -z "$1" ] && current="$(pihole-FTL version)"
|
|
|
|
[ "$1" = "-l" -o "$1" = "--latest" -o -z "$1" ] && latest="$(getRemoteVersion FTL)"
|
|
|
|
[ ! -d "${WEBGITDIR}" ] && exit 0
|
2017-05-10 22:30:49 +00:00
|
|
|
[ -n "$2" ] && error="true"
|
2017-05-10 03:07:56 +00:00
|
|
|
|
|
|
|
if [ -n "$current" -a -n "$latest" ]; then
|
|
|
|
str="FTL version is $current (Latest: $latest)"
|
|
|
|
elif [ -n "$current" -a -z "$latest" ]; then
|
|
|
|
str="Current FTL version is $current"
|
|
|
|
elif [ -z "$current" -a -n "$latest" ]; then
|
|
|
|
str="Latest FTL version is $latest"
|
|
|
|
else
|
2017-05-11 00:11:04 +00:00
|
|
|
error="true"
|
2017-05-10 03:07:56 +00:00
|
|
|
fi
|
2017-05-10 22:30:49 +00:00
|
|
|
|
|
|
|
if [ "$error" = "true" ]; then
|
2017-05-11 00:11:04 +00:00
|
|
|
echo " Invalid Option! Try 'pihole -v --help' for more information."
|
|
|
|
exit 1
|
2017-05-10 22:30:49 +00:00
|
|
|
fi
|
|
|
|
|
2017-05-10 03:07:56 +00:00
|
|
|
echo " $str"
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultOutput() {
|
2017-05-10 22:30:49 +00:00
|
|
|
coreOutput "$1" "$2"
|
|
|
|
webOutput "$1" "$2"
|
|
|
|
ftlOutput "$1" "$2"
|
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:
|
|
|
|
-a, --admin Show both current and latest versions of Web Admin
|
|
|
|
-f, --ftl Show both current and latest versions of FTL
|
|
|
|
-p, --pihole Show both current and latest versions of Pi-hole Core
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-c, --current (Only after -a | -p | -f) Return the current version
|
|
|
|
-l, --latest (Only after -a | -p | -f) Return the latest version
|
|
|
|
-h, --hash (Only after -a | -p) Return the current Github hash
|
|
|
|
--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
|
|
|
|
"-a" | "--admin" ) shift; webOutput "$@";;
|
2017-05-10 03:07:56 +00:00
|
|
|
"-p" | "--pihole" ) shift; coreOutput "$@";;
|
|
|
|
"-f" | "--ftl" ) shift; ftlOutput "$@";;
|
|
|
|
"--help" ) helpFunc;;
|
|
|
|
* ) defaultOutput "$@";;
|
2017-03-04 07:12:28 +00:00
|
|
|
esac
|