mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-07-25 14:44:31 +02:00
Display FTL version & version.sh rewrite
While testing to make sure `pihole -v` would output `pihole-FTL version`, I noticed some options didn't work how I expected them to. For example, if I use `pihole -v -p`, I would expect to see the version output of Pi-hole Core. Instead, I'm informed that it's an invalid option. I've had the following things in mind while rewriting this: * I'm operating under the assumption that FTL is only installed if the Admin Console is (Line 113 exit 0) * I have modified the help text to only output with `pihole -v --help` * I have modified all output to be more similar to the output style of `grep` and `curl` (Ditching ":::") Testing output: ``` w3k@MCT:~$ pihole -v Pi-hole version is v3.0.1-14-ga928cd3 (Latest: v3.0.1) Admin Console version is v3.0-9-g3760482 (Latest: v3.0.1) FTL version is v2.6.2 (Latest: v2.6.2) w3k@MCT:~$ pihole -v -c Current Pi-hole version is v3.0.1-14-ga928cd3 Current Admin Console version is v3.0-9-g3760482 Current FTL version is v2.6.2 w3k@MCT:~$ pihole -v -l Latest Pi-hole version is v3.0.1 Latest Admin Console version is v3.0.1 Latest FTL version is v2.6.2 w3k@MCT:~$ pihole -v -p --hash Current Pi-hole hash is a928cd3 w3k@MCT:~$ pihole -v -a --hash Current Admin Console hash is 3760482 w3k@MCT:~$ pihole -v --help Usage: pihole -v [REPO | OPTION] [OPTION] Show Pi-hole, Web Admin & FTL versions <Shows all Repositories and Options> w3k@MCT:~$ pihole -v -foo Invalid Option! ```
This commit is contained in:
parent
a928cd3fa1
commit
03201e2f20
@ -66,72 +66,93 @@ getRemoteVersion(){
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
#PHHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/commits/master | \
|
coreOutput() {
|
||||||
# grep sha | \
|
[ "$1" = "-c" -o "$1" = "--current" -o -z "$1" ] && current="$(getLocalVersion ${PHGITDIR})"
|
||||||
# head -n1 | \
|
[ "$1" = "-l" -o "$1" = "--latest" -o -z "$1" ] && latest="$(getRemoteVersion pi-hole)"
|
||||||
# awk -F ' ' '{ print $2 }' | \
|
[ "$1" = "--hash" ] && hash="$(getLocalHash ${PHGITDIR})"
|
||||||
# tr -cd '[[:alnum:]]._-')
|
|
||||||
|
|
||||||
#WEBHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/commits/master | \
|
if [ -n "$current" -a -n "$latest" ]; then
|
||||||
# grep sha | \
|
str="Pi-hole version is $current (Latest: $latest)"
|
||||||
# head -n1 | \
|
elif [ -n "$current" -a -z "$latest" ]; then
|
||||||
# awk -F ' ' '{ print $2 }' | \
|
str="Current Pi-hole version is $current"
|
||||||
# tr -cd '[[:alnum:]]._-')
|
elif [ -z "$current" -a -n "$latest" ]; then
|
||||||
|
str="Latest Pi-hole version is $latest"
|
||||||
|
elif [ -n "$hash" ]; then
|
||||||
normalOutput() {
|
str="Current Pi-hole hash is $hash"
|
||||||
echo "::: Pi-hole version is $(getLocalVersion "${PHGITDIR}") (Latest version is $(getRemoteVersion pi-hole))"
|
else
|
||||||
if [ -d "${WEBGITDIR}" ]; then
|
echo " Invalid Option! Try 'pihole -v --help' for more information."
|
||||||
echo "::: Web-Admin version is $(getLocalVersion "${WEBGITDIR}") (Latest version is $(getRemoteVersion AdminLTE))"
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
echo " $str"
|
||||||
}
|
}
|
||||||
|
|
||||||
webOutput() {
|
webOutput() {
|
||||||
if [ -d "${WEBGITDIR}" ]; then
|
[ "$1" = "-c" -o "$1" = "--current" -o -z "$1" ] && current="$(getLocalVersion ${WEBGITDIR})"
|
||||||
case "${1}" in
|
[ "$1" = "-l" -o "$1" = "--latest" -o -z "$1" ] && latest="$(getRemoteVersion AdminLTE)"
|
||||||
"-l" | "--latest" ) echo $(getRemoteVersion AdminLTE);;
|
[ "$1" = "--hash" ] && hash="$(getLocalHash ${WEBGITDIR})"
|
||||||
"-c" | "--current" ) echo $(getLocalVersion "${WEBGITDIR}");;
|
[ ! -d "${WEBGITDIR}" ] && str="Web interface not installed!"
|
||||||
"-h" | "--hash" ) echo $(getLocalHash "${WEBGITDIR}");;
|
|
||||||
* ) echo "::: Invalid Option!"; exit 1;
|
if [ -n "$current" -a -n "$latest" ]; then
|
||||||
esac
|
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"
|
||||||
else
|
else
|
||||||
echo "::: Web interface not installed!"; exit 1;
|
echo " Invalid Option! Try 'pihole -v --help' for more information."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
echo " $str"
|
||||||
}
|
}
|
||||||
|
|
||||||
coreOutput() {
|
ftlOutput() {
|
||||||
case "${1}" in
|
[ "$1" = "-c" -o "$1" = "--current" -o -z "$1" ] && current="$(pihole-FTL version)"
|
||||||
"-l" | "--latest" ) echo $(getRemoteVersion pi-hole);;
|
[ "$1" = "-l" -o "$1" = "--latest" -o -z "$1" ] && latest="$(getRemoteVersion FTL)"
|
||||||
"-c" | "--current" ) echo $(getLocalVersion "${PHGITDIR}");;
|
[ ! -d "${WEBGITDIR}" ] && exit 0
|
||||||
"-h" | "--hash" ) echo $(getLocalHash "${PHGITDIR}");;
|
|
||||||
* ) echo "::: Invalid Option!"; exit 1;
|
if [ -n "$current" -a -n "$latest" ]; then
|
||||||
esac
|
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
|
||||||
|
echo " Invalid Option! Try 'pihole -v --help' for more information."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo " $str"
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultOutput() {
|
||||||
|
coreOutput "$1"
|
||||||
|
webOutput "$1"
|
||||||
|
ftlOutput "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
helpFunc() {
|
helpFunc() {
|
||||||
cat << EOM
|
echo "Usage: pihole -v [REPO | OPTION] [OPTION]
|
||||||
:::
|
Show Pi-hole, Web Admin & FTL versions
|
||||||
::: Show Pi-hole/Web Admin versions
|
|
||||||
:::
|
Repositories:
|
||||||
::: Usage: pihole -v [ -a | -p ] [ -l | -c ]
|
-a, --admin Show both current and latest versions of Web Admin
|
||||||
:::
|
-f, --ftl Show both current and latest versions of FTL
|
||||||
::: Options:
|
-p, --pihole Show both current and latest versions of Pi-hole Core
|
||||||
::: -a, --admin Show both current and latest versions of web admin
|
|
||||||
::: -p, --pihole Show both current and latest versions of Pi-hole core files
|
Options:
|
||||||
::: -l, --latest (Only after -a | -p) Return only latest version
|
-c, --current (Only after -a | -p | -f) Return the current version
|
||||||
::: -c, --current (Only after -a | -p) Return only current version
|
-l, --latest (Only after -a | -p | -f) Return the latest version
|
||||||
::: -h, --help Show this help dialog
|
-h, --hash (Only after -a | -p) Return the current Github hash
|
||||||
:::
|
--help Show this help dialog
|
||||||
EOM
|
"
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ $# = 0 ]]; then
|
|
||||||
normalOutput
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
"-a" | "--admin" ) shift; webOutput "$@";;
|
"-a" | "--admin" ) shift; webOutput "$@";;
|
||||||
"-p" | "--pihole" ) shift; coreOutput "$@" ;;
|
"-p" | "--pihole" ) shift; coreOutput "$@";;
|
||||||
"-h" | "--help" ) helpFunc;;
|
"-f" | "--ftl" ) shift; ftlOutput "$@";;
|
||||||
|
"--help" ) helpFunc;;
|
||||||
|
* ) defaultOutput "$@";;
|
||||||
esac
|
esac
|
||||||
|
Loading…
x
Reference in New Issue
Block a user