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/"
|
|
|
|
|
|
|
|
getLocalPHVersion(){
|
|
|
|
# Get the tagged version of the local Pi-hole repository
|
|
|
|
local version
|
2017-03-04 06:10:32 +00:00
|
|
|
local hash
|
2017-03-04 05:36:38 +00:00
|
|
|
|
2017-03-04 06:10:32 +00:00
|
|
|
cd "${PHGITDIR}" || { PHVERSION="${DEFAULT}"; return 1; }
|
2017-03-04 05:36:38 +00:00
|
|
|
version=$(git describe --tags --always || \
|
|
|
|
echo "${DEFAULT}")
|
|
|
|
if [[ "${version}" =~ ^v ]]; then
|
|
|
|
PHVERSION="${version}"
|
2017-03-04 06:10:32 +00:00
|
|
|
elif [[ "${version}" == "${DEFAULT}" ]]; then
|
2017-03-04 05:36:38 +00:00
|
|
|
PHVERSION="ERROR"
|
|
|
|
else
|
|
|
|
PHVERSION="Untagged"
|
|
|
|
fi
|
2017-03-04 06:10:32 +00:00
|
|
|
|
|
|
|
hash=$(git rev-parse --short HEAD || \
|
|
|
|
echo "${DEFAULT}")
|
|
|
|
if [[ "${hash}" == "${DEFAULT}" ]]; then
|
|
|
|
PHHASH="ERROR"
|
|
|
|
else
|
|
|
|
PHHASH="${hash}"
|
|
|
|
fi
|
2017-03-04 05:36:38 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2017-03-04 06:10:32 +00:00
|
|
|
getLocalWebVersion(){
|
|
|
|
# Get the tagged version of the local Pi-hole repository
|
|
|
|
local version
|
|
|
|
local hash
|
|
|
|
|
|
|
|
cd "${WEBGITDIR}" || { WEBVERSION="${DEFAULT}"; return 1; }
|
|
|
|
version=$(git describe --tags --always || \
|
|
|
|
echo "${DEFAULT}")
|
|
|
|
if [[ "${version}" =~ ^v ]]; then
|
|
|
|
WEBVERSION="${version}"
|
|
|
|
elif [[ "${version}" == "${DEFAULT}" ]]; then
|
|
|
|
WEBVERSION="ERROR"
|
|
|
|
else
|
|
|
|
WEBVERSION="Untagged"
|
|
|
|
fi
|
2016-11-02 19:29:55 +00:00
|
|
|
|
2017-03-04 06:10:32 +00:00
|
|
|
hash=$(git rev-parse --short HEAD || \
|
|
|
|
echo "${DEFAULT}")
|
|
|
|
if [[ "${hash}" == "${DEFAULT}" ]]; then
|
|
|
|
WEBHASH="ERROR"
|
|
|
|
else
|
|
|
|
WEBHASH="${hash}"
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
2017-03-04 03:14:30 +00:00
|
|
|
|
2017-03-04 04:16:53 +00:00
|
|
|
PHVERSIONLATEST=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | \
|
2017-03-04 06:34:55 +00:00
|
|
|
awk -F: '$1 ~/tag_name/ { print $2 }' | \
|
|
|
|
tr -cd '[[:alnum:]]._-')
|
2017-03-04 04:16:53 +00:00
|
|
|
WEBVERSIONLATEST=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | \
|
2017-03-04 06:34:55 +00:00
|
|
|
awk -F: '$1 ~/tag_name/ { print $2 }' | \
|
|
|
|
tr -cd '[[:alnum:]]._-')
|
2017-03-04 03:14:30 +00:00
|
|
|
|
2017-03-04 06:34:55 +00:00
|
|
|
#PHHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/commits/master | \
|
|
|
|
# grep sha | \
|
|
|
|
# head -n1 | \
|
|
|
|
# awk -F ' ' '{ print $2 }' | \
|
|
|
|
# tr -cd '[[:alnum:]]._-')
|
2017-03-04 03:14:30 +00:00
|
|
|
|
2017-03-04 06:34:55 +00:00
|
|
|
#WEBHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/commits/master | \
|
|
|
|
# grep sha | \
|
|
|
|
# head -n1 | \
|
|
|
|
# awk -F ' ' '{ print $2 }' | \
|
|
|
|
# tr -cd '[[:alnum:]]._-')
|
2017-03-04 05:36:38 +00:00
|
|
|
|
|
|
|
|
2017-03-04 04:16:53 +00:00
|
|
|
normalOutput() {
|
|
|
|
echo "::: Pi-hole version is ${PHVERSION} (Latest version is ${PHVERSIONLATEST:-${DEFAULT}})"
|
2017-03-04 06:10:32 +00:00
|
|
|
echo "::: Web-Admin version is ${WEBVERSION} (Latest version is ${WEBVERSIONLATEST:-${DEFAULT}})"
|
2016-10-18 11:07:11 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 02:47:45 +00:00
|
|
|
webOutput() {
|
2017-03-04 06:10:32 +00:00
|
|
|
for var in "$1"; do
|
2016-10-22 17:01:15 +00:00
|
|
|
case "${var}" in
|
2017-03-04 05:36:38 +00:00
|
|
|
"-l" | "--latest" ) echo "${WEBVERSIONLATEST:-${DEFAULT}}";;
|
2017-03-04 06:10:32 +00:00
|
|
|
"-c" | "--current" ) echo "${WEBVERSION}";;
|
2017-03-04 04:32:26 +00:00
|
|
|
"-h" | "--hash" ) echo "${WEBHASH}";;
|
2016-10-22 17:01:15 +00:00
|
|
|
* ) echo "::: Invalid Option!"; exit 1;
|
|
|
|
esac
|
|
|
|
done
|
2016-10-18 11:07:11 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 02:47:45 +00:00
|
|
|
coreOutput() {
|
2017-03-04 06:10:32 +00:00
|
|
|
for var in "$1"; do
|
2016-10-22 17:01:15 +00:00
|
|
|
case "${var}" in
|
2017-03-04 05:36:38 +00:00
|
|
|
"-l" | "--latest" ) echo "${PHVERSIONLATEST:-${DEFAULT}}";;
|
2017-03-04 04:32:26 +00:00
|
|
|
"-c" | "--current" ) echo "${PHVERSION}";;
|
|
|
|
"-h" | "--hash" ) echo "${PHHASH}";;
|
2016-10-22 17:01:15 +00:00
|
|
|
* ) echo "::: Invalid Option!"; exit 1;
|
|
|
|
esac
|
|
|
|
done
|
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() {
|
2016-10-20 03:46:37 +00:00
|
|
|
cat << EOM
|
|
|
|
:::
|
|
|
|
::: Show Pi-hole/Web Admin versions
|
|
|
|
:::
|
|
|
|
::: Usage: pihole -v [ -a | -p ] [ -l | -c ]
|
|
|
|
:::
|
|
|
|
::: Options:
|
|
|
|
::: -a, --admin Show both current and latest versions of web admin
|
|
|
|
::: -p, --pihole Show both current and latest versions of Pi-hole core files
|
|
|
|
::: -l, --latest (Only after -a | -p) Return only latest version
|
|
|
|
::: -c, --current (Only after -a | -p) Return only current version
|
|
|
|
::: -h, --help Show this help dialog
|
|
|
|
:::
|
|
|
|
EOM
|
2016-12-01 23:10:06 +00:00
|
|
|
exit 0
|
2016-10-18 11:05:48 +00:00
|
|
|
}
|
|
|
|
|
2017-03-04 05:36:38 +00:00
|
|
|
getLocalPHVersion
|
2017-03-04 06:10:32 +00:00
|
|
|
getLocalWebVersion
|
2017-03-04 05:36:38 +00:00
|
|
|
|
2016-10-18 11:07:11 +00:00
|
|
|
if [[ $# = 0 ]]; then
|
|
|
|
normalOutput
|
|
|
|
fi
|
|
|
|
|
2017-03-04 06:10:32 +00:00
|
|
|
for var in "$1"; do
|
2016-10-22 17:01:15 +00:00
|
|
|
case "${var}" in
|
|
|
|
"-a" | "--admin" ) shift; webOutput "$@";;
|
|
|
|
"-p" | "--pihole" ) shift; coreOutput "$@" ;;
|
|
|
|
"-h" | "--help" ) helpFunc;;
|
|
|
|
esac
|
2016-10-20 02:47:45 +00:00
|
|
|
done
|