2022-10-06 19:50:07 +00:00
|
|
|
#!/usr/bin/env sh
|
2016-08-02 19:07:09 +00:00
|
|
|
# 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.
|
|
|
|
#
|
2017-05-14 01:11:44 +00:00
|
|
|
# Show 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.
|
|
|
|
|
2022-10-06 20:08:57 +00:00
|
|
|
# Source the versions file poupulated by updatechecker.sh
|
2022-10-06 15:58:58 +00:00
|
|
|
cachedVersions="/etc/pihole/versions"
|
2018-07-20 20:27:30 +00:00
|
|
|
|
2022-10-06 15:58:58 +00:00
|
|
|
if [ -f ${cachedVersions} ]; then
|
|
|
|
# shellcheck disable=SC1090
|
|
|
|
. "$cachedVersions"
|
|
|
|
else
|
2022-10-14 11:21:31 +00:00
|
|
|
echo "Could not find /etc/pihole/versions. Running update now."
|
|
|
|
pihole updatechecker
|
|
|
|
# shellcheck disable=SC1090
|
|
|
|
. "$cachedVersions"
|
2022-10-06 15:58:58 +00:00
|
|
|
fi
|
2018-07-20 20:27:30 +00:00
|
|
|
|
2022-10-06 15:58:58 +00:00
|
|
|
getLocalVersion() {
|
|
|
|
case ${1} in
|
2022-10-06 19:55:49 +00:00
|
|
|
"Pi-hole" ) echo "${CORE_VERSION:=N/A}";;
|
2023-02-05 18:39:48 +00:00
|
|
|
"AdminLTE" ) echo "${WEB_VERSION:=N/A}";;
|
2022-10-06 19:55:49 +00:00
|
|
|
"FTL" ) echo "${FTL_VERSION:=N/A}";;
|
2022-10-06 15:58:58 +00:00
|
|
|
esac
|
2017-03-05 15:10:18 +00:00
|
|
|
}
|
2016-10-18 11:05:48 +00:00
|
|
|
|
2017-03-05 15:10:18 +00:00
|
|
|
getLocalHash() {
|
2022-10-06 15:58:58 +00:00
|
|
|
case ${1} in
|
2022-10-06 19:55:49 +00:00
|
|
|
"Pi-hole" ) echo "${CORE_HASH:=N/A}";;
|
2023-02-05 18:39:48 +00:00
|
|
|
"AdminLTE" ) echo "${WEB_HASH:=N/A}";;
|
2022-10-06 19:55:49 +00:00
|
|
|
"FTL" ) echo "${FTL_HASH:=N/A}";;
|
2022-10-06 15:58:58 +00:00
|
|
|
esac
|
2017-03-05 15:10:18 +00:00
|
|
|
}
|
2016-10-18 11:05:48 +00:00
|
|
|
|
2017-05-14 01:11:44 +00:00
|
|
|
getRemoteHash(){
|
2022-10-06 15:58:58 +00:00
|
|
|
case ${1} in
|
2022-10-06 19:55:49 +00:00
|
|
|
"Pi-hole" ) echo "${GITHUB_CORE_HASH:=N/A}";;
|
2023-02-05 18:39:48 +00:00
|
|
|
"AdminLTE" ) echo "${GITHUB_WEB_HASH:=N/A}";;
|
2022-10-06 19:55:49 +00:00
|
|
|
"FTL" ) echo "${GITHUB_FTL_HASH:=N/A}";;
|
2022-10-06 15:58:58 +00:00
|
|
|
esac
|
2017-05-14 01:11:44 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:10:18 +00:00
|
|
|
getRemoteVersion(){
|
2022-10-06 15:58:58 +00:00
|
|
|
case ${1} in
|
2022-10-06 19:55:49 +00:00
|
|
|
"Pi-hole" ) echo "${GITHUB_CORE_VERSION:=N/A}";;
|
2023-02-05 18:39:48 +00:00
|
|
|
"AdminLTE" ) echo "${GITHUB_WEB_VERSION:=N/A}";;
|
2022-10-06 19:55:49 +00:00
|
|
|
"FTL" ) echo "${GITHUB_FTL_VERSION:=N/A}";;
|
2022-10-06 15:58:58 +00:00
|
|
|
esac
|
2017-03-05 15:10:18 +00:00
|
|
|
}
|
|
|
|
|
2020-04-13 19:58:46 +00:00
|
|
|
getLocalBranch(){
|
2022-10-06 15:58:58 +00:00
|
|
|
case ${1} in
|
2022-10-06 19:55:49 +00:00
|
|
|
"Pi-hole" ) echo "${CORE_BRANCH:=N/A}";;
|
2023-02-05 18:39:48 +00:00
|
|
|
"AdminLTE" ) echo "${WEB_BRANCH:=N/A}";;
|
2022-10-06 19:55:49 +00:00
|
|
|
"FTL" ) echo "${FTL_BRANCH:=N/A}";;
|
2022-10-06 15:58:58 +00:00
|
|
|
esac
|
2020-04-13 19:58:46 +00:00
|
|
|
}
|
|
|
|
|
2017-05-14 01:11:44 +00:00
|
|
|
versionOutput() {
|
2021-12-02 20:46:11 +00:00
|
|
|
|
2022-10-06 19:50:07 +00:00
|
|
|
[ "$2" = "-c" ] || [ "$2" = "--current" ] || [ -z "$2" ] && current=$(getLocalVersion "${1}") && branch=$(getLocalBranch "${1}")
|
|
|
|
[ "$2" = "-l" ] || [ "$2" = "--latest" ] || [ -z "$2" ] && latest=$(getRemoteVersion "${1}")
|
|
|
|
if [ "$2" = "--hash" ]; then
|
|
|
|
[ "$3" = "-c" ] || [ "$3" = "--current" ] || [ -z "$3" ] && curHash=$(getLocalHash "${1}") && branch=$(getLocalBranch "${1}")
|
2022-10-06 19:55:49 +00:00
|
|
|
[ "$3" = "-l" ] || [ "$3" = "--latest" ] || [ -z "$3" ] && latHash=$(getRemoteHash "${1}") && branch=$(getLocalBranch "${1}")
|
2018-07-20 20:27:30 +00:00
|
|
|
fi
|
2022-11-14 20:39:34 +00:00
|
|
|
|
|
|
|
# We do not want to show the branch name when we are on master,
|
|
|
|
# blank out the variable in this case
|
|
|
|
if [ "$branch" = "master" ]; then
|
|
|
|
branch=""
|
|
|
|
else
|
|
|
|
branch="$branch "
|
|
|
|
fi
|
|
|
|
|
2022-10-06 19:50:07 +00:00
|
|
|
if [ -n "$current" ] && [ -n "$latest" ]; then
|
2022-11-14 20:39:34 +00:00
|
|
|
output="${1} version is $branch$current (Latest: $latest)"
|
2022-10-06 19:50:07 +00:00
|
|
|
elif [ -n "$current" ] && [ -z "$latest" ]; then
|
2022-11-14 20:39:34 +00:00
|
|
|
output="Current ${1} version is $branch$current"
|
2022-10-06 19:50:07 +00:00
|
|
|
elif [ -z "$current" ] && [ -n "$latest" ]; then
|
|
|
|
output="Latest ${1} version is $latest"
|
|
|
|
elif [ -n "$curHash" ] && [ -n "$latHash" ]; then
|
2022-11-14 20:39:34 +00:00
|
|
|
output="Local ${1} hash is $curHash (Remote: $latHash)"
|
2022-10-06 19:50:07 +00:00
|
|
|
elif [ -n "$curHash" ] && [ -z "$latHash" ]; then
|
2022-11-14 20:39:34 +00:00
|
|
|
output="Current local ${1} hash is $curHash"
|
2022-10-06 19:50:07 +00:00
|
|
|
elif [ -z "$curHash" ] && [ -n "$latHash" ]; then
|
2022-11-14 20:39:34 +00:00
|
|
|
output="Latest remote ${1} hash is $latHash"
|
2022-10-06 19:50:07 +00:00
|
|
|
elif [ -z "$curHash" ] && [ -z "$latHash" ]; then
|
|
|
|
output="Hashes for ${1} not available"
|
2018-07-20 20:27:30 +00:00
|
|
|
else
|
|
|
|
errorOutput
|
2021-12-02 20:46:11 +00:00
|
|
|
return 1
|
2018-07-20 20:27:30 +00:00
|
|
|
fi
|
|
|
|
|
2022-10-06 19:50:07 +00:00
|
|
|
[ -n "$output" ] && echo " $output"
|
2016-10-18 11:07:11 +00:00
|
|
|
}
|
|
|
|
|
2017-05-14 01:11:44 +00:00
|
|
|
errorOutput() {
|
2018-07-20 20:27:30 +00:00
|
|
|
echo " Invalid Option! Try 'pihole -v --help' for more information."
|
|
|
|
exit 1
|
2017-05-14 01:11:44 +00:00
|
|
|
}
|
2018-07-20 20:27:30 +00:00
|
|
|
|
2017-05-14 01:11:44 +00:00
|
|
|
defaultOutput() {
|
2022-10-06 19:50:07 +00:00
|
|
|
versionOutput "Pi-hole" "$@"
|
2023-02-05 18:39:48 +00:00
|
|
|
versionOutput "AdminLTE" "$@"
|
2018-07-20 20:27:30 +00:00
|
|
|
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() {
|
2022-10-06 20:08:57 +00:00
|
|
|
echo "Usage: pihole -v [repo | option] [option]
|
2017-05-14 01:11:44 +00:00
|
|
|
Example: 'pihole -v -p -l'
|
|
|
|
Show Pi-hole, Admin Console & FTL versions
|
|
|
|
|
|
|
|
Repositories:
|
|
|
|
-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
|
2018-07-20 20:27:30 +00:00
|
|
|
|
2017-05-14 01:11:44 +00:00
|
|
|
Options:
|
|
|
|
-c, --current Return the current version
|
|
|
|
-l, --latest Return the latest version
|
2020-05-13 10:49:00 +00:00
|
|
|
--hash Return the GitHub hash from your local repositories
|
2017-05-14 03:03:33 +00:00
|
|
|
-h, --help Show this help dialog"
|
2017-05-14 01:11:44 +00:00
|
|
|
exit 0
|
2016-10-18 11:05:48 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:10:18 +00:00
|
|
|
case "${1}" in
|
2022-10-06 19:50:07 +00:00
|
|
|
"-p" | "--pihole" ) shift; versionOutput "Pi-hole" "$@";;
|
2018-07-20 20:27:30 +00:00
|
|
|
"-a" | "--admin" ) shift; versionOutput "AdminLTE" "$@";;
|
|
|
|
"-f" | "--ftl" ) shift; versionOutput "FTL" "$@";;
|
|
|
|
"-h" | "--help" ) helpFunc;;
|
|
|
|
* ) defaultOutput "$@";;
|
2017-03-05 15:10:18 +00:00
|
|
|
esac
|