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.
|
|
|
|
|
|
|
|
|
2016-08-02 19:07:09 +00:00
|
|
|
|
2016-10-18 11:07:11 +00:00
|
|
|
# Flags:
|
|
|
|
latest=false
|
|
|
|
current=false
|
2016-10-18 11:05:48 +00:00
|
|
|
|
2016-11-02 19:29:55 +00:00
|
|
|
DEFAULT="-1"
|
|
|
|
|
2016-10-20 02:47:45 +00:00
|
|
|
normalOutput() {
|
2016-10-22 17:01:15 +00:00
|
|
|
piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0)
|
|
|
|
webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0)
|
2016-10-18 11:05:48 +00:00
|
|
|
|
2016-10-22 17:01:15 +00:00
|
|
|
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/",$//')
|
2016-10-18 11:05:48 +00:00
|
|
|
|
2016-11-02 19:29:55 +00:00
|
|
|
echo "::: Pi-hole version is ${piholeVersion} (Latest version is ${piholeVersionLatest:-${DEFAULT}})"
|
|
|
|
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() {
|
2016-10-22 17:01:15 +00:00
|
|
|
for var in "$@"; do
|
|
|
|
case "${var}" in
|
|
|
|
"-l" | "--latest" ) latest=true;;
|
|
|
|
"-c" | "--current" ) current=true;;
|
|
|
|
* ) echo "::: Invalid Option!"; exit 1;
|
|
|
|
esac
|
|
|
|
done
|
2016-08-02 19:07:09 +00:00
|
|
|
|
2016-10-22 17:01:15 +00:00
|
|
|
if [[ "${latest}" == true && "${current}" == false ]]; then
|
|
|
|
webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
|
2016-11-02 19:29:55 +00:00
|
|
|
echo "${webVersionLatest:--1}"
|
2016-10-22 17:01:15 +00:00
|
|
|
elif [[ "${latest}" == false && "${current}" == true ]]; then
|
|
|
|
webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0)
|
2016-11-02 19:29:55 +00:00
|
|
|
echo "${webVersion}"
|
2016-10-22 17:01:15 +00:00
|
|
|
else
|
|
|
|
webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0)
|
|
|
|
webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
|
2016-11-02 19:29:55 +00:00
|
|
|
echo "::: Web-Admin version is ${webVersion} (Latest version is ${webVersionLatest:-${DEFAULT}})"
|
2016-10-22 17:01:15 +00:00
|
|
|
fi
|
2016-10-18 11:07:11 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 02:47:45 +00:00
|
|
|
coreOutput() {
|
2016-10-22 17:01:15 +00:00
|
|
|
for var in "$@"; do
|
|
|
|
case "${var}" in
|
|
|
|
"-l" | "--latest" ) latest=true;;
|
|
|
|
"-c" | "--current" ) current=true;;
|
|
|
|
* ) echo "::: Invalid Option!"; exit 1;
|
|
|
|
esac
|
|
|
|
done
|
2016-08-02 19:07:09 +00:00
|
|
|
|
2016-10-22 17:01:15 +00:00
|
|
|
if [[ "${latest}" == true && "${current}" == false ]]; then
|
|
|
|
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/",$//')
|
2016-11-02 19:29:55 +00:00
|
|
|
echo "${piholeVersionLatest:--1}"
|
2016-10-22 17:01:15 +00:00
|
|
|
elif [[ "${latest}" == false && "${current}" == true ]]; then
|
|
|
|
piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0)
|
2016-11-02 19:29:55 +00:00
|
|
|
echo "${piholeVersion}"
|
2016-10-22 17:01:15 +00:00
|
|
|
else
|
|
|
|
piholeVersion=$(cd /etc/.pihole/ && 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/",$//')
|
2016-11-02 19:29:55 +00:00
|
|
|
echo "::: Pi-hole version is ${piholeVersion} (Latest version is ${piholeVersionLatest:-${DEFAULT}})"
|
2016-10-22 17:01:15 +00:00
|
|
|
fi
|
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
|
|
|
}
|
|
|
|
|
2016-10-18 11:07:11 +00:00
|
|
|
if [[ $# = 0 ]]; then
|
|
|
|
normalOutput
|
|
|
|
fi
|
|
|
|
|
2016-10-22 17:01:15 +00:00
|
|
|
for var in "$@"; do
|
|
|
|
case "${var}" in
|
|
|
|
"-a" | "--admin" ) shift; webOutput "$@";;
|
|
|
|
"-p" | "--pihole" ) shift; coreOutput "$@" ;;
|
|
|
|
"-h" | "--help" ) helpFunc;;
|
|
|
|
esac
|
2016-10-20 02:47:45 +00:00
|
|
|
done
|