mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 18:53:56 +00:00
Merge pull request #1447 from WaLLy3K/patch-1
Display FTL version & version.sh rewrite
This commit is contained in:
commit
68dd2a6b91
1 changed files with 65 additions and 62 deletions
|
@ -10,17 +10,22 @@
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
DEFAULT="-1"
|
DEFAULT="-1"
|
||||||
PHGITDIR="/etc/.pihole/"
|
COREGITDIR="/etc/.pihole/"
|
||||||
WEBGITDIR="/var/www/html/admin/"
|
WEBGITDIR="/var/www/html/admin/"
|
||||||
|
|
||||||
getLocalVersion() {
|
getLocalVersion() {
|
||||||
|
# FTL requires a different method
|
||||||
|
if [ "$1" == "FTL" ]; then
|
||||||
|
pihole-FTL version
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Get the tagged version of the local repository
|
# Get the tagged version of the local repository
|
||||||
local directory="${1}"
|
local directory="${1}"
|
||||||
local version
|
local version
|
||||||
|
|
||||||
cd "${directory}" || { echo "${DEFAULT}"; return 1; }
|
cd "${directory}" || { echo "${DEFAULT}"; return 1; }
|
||||||
version=$(git describe --tags --always || \
|
version=$(git describe --tags --always || echo "$DEFAULT")
|
||||||
echo "${DEFAULT}")
|
|
||||||
if [[ "${version}" =~ ^v ]]; then
|
if [[ "${version}" =~ ^v ]]; then
|
||||||
echo "${version}"
|
echo "${version}"
|
||||||
elif [[ "${version}" == "${DEFAULT}" ]]; then
|
elif [[ "${version}" == "${DEFAULT}" ]]; then
|
||||||
|
@ -33,13 +38,18 @@ getLocalVersion() {
|
||||||
}
|
}
|
||||||
|
|
||||||
getLocalHash() {
|
getLocalHash() {
|
||||||
|
# FTL hash is not applicable
|
||||||
|
if [ "$1" == "FTL" ]; then
|
||||||
|
echo "N/A"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Get the short hash of the local repository
|
# Get the short hash of the local repository
|
||||||
local directory="${1}"
|
local directory="${1}"
|
||||||
local hash
|
local hash
|
||||||
|
|
||||||
cd "${directory}" || { echo "${DEFAULT}"; return 1; }
|
cd "${directory}" || { echo "${DEFAULT}"; return 1; }
|
||||||
hash=$(git rev-parse --short HEAD || \
|
hash=$(git rev-parse --short HEAD || echo "$DEFAULT")
|
||||||
echo "${DEFAULT}")
|
|
||||||
if [[ "${hash}" == "${DEFAULT}" ]]; then
|
if [[ "${hash}" == "${DEFAULT}" ]]; then
|
||||||
echo "ERROR"
|
echo "ERROR"
|
||||||
return 1
|
return 1
|
||||||
|
@ -54,7 +64,7 @@ getRemoteVersion(){
|
||||||
local daemon="${1}"
|
local daemon="${1}"
|
||||||
local version
|
local version
|
||||||
|
|
||||||
version=$(curl --silent --fail https://api.github.com/repos/pi-hole/${daemon}/releases/latest | \
|
version=$(curl --silent --fail "https://api.github.com/repos/pi-hole/${daemon}/releases/latest" | \
|
||||||
awk -F: '$1 ~/tag_name/ { print $2 }' | \
|
awk -F: '$1 ~/tag_name/ { print $2 }' | \
|
||||||
tr -cd '[[:alnum:]]._-')
|
tr -cd '[[:alnum:]]._-')
|
||||||
if [[ "${version}" =~ ^v ]]; then
|
if [[ "${version}" =~ ^v ]]; then
|
||||||
|
@ -66,72 +76,65 @@ getRemoteVersion(){
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
#PHHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/commits/master | \
|
versionOutput() {
|
||||||
# grep sha | \
|
[ "$1" == "pi-hole" ] && GITDIR=$COREGITDIR
|
||||||
# head -n1 | \
|
[ "$1" == "AdminLTE" ] && GITDIR=$WEBGITDIR
|
||||||
# awk -F ' ' '{ print $2 }' | \
|
[ "$1" == "FTL" ] && GITDIR="FTL"
|
||||||
# tr -cd '[[:alnum:]]._-')
|
|
||||||
|
|
||||||
#WEBHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/commits/master | \
|
[ "$2" == "-c" ] || [ "$2" == "--current" ] || [ -z "$2" ] && current=$(getLocalVersion $GITDIR)
|
||||||
# grep sha | \
|
[ "$2" == "-l" ] || [ "$2" == "--latest" ] || [ -z "$2" ] && latest=$(getRemoteVersion "$1")
|
||||||
# head -n1 | \
|
[ "$2" == "-h" ] || [ "$2" == "--hash" ] && hash=$(getLocalHash "$GITDIR")
|
||||||
# awk -F ' ' '{ print $2 }' | \
|
|
||||||
# tr -cd '[[:alnum:]]._-')
|
|
||||||
|
|
||||||
|
if [ -n "$current" ] && [ -n "$latest" ]; then
|
||||||
normalOutput() {
|
output="${1^} version is $current (Latest: $latest)"
|
||||||
echo "::: Pi-hole version is $(getLocalVersion "${PHGITDIR}") (Latest version is $(getRemoteVersion pi-hole))"
|
elif [ -n "$current" ] && [ -z "$latest" ]; then
|
||||||
if [ -d "${WEBGITDIR}" ]; then
|
output="Current ${1^} version is $current"
|
||||||
echo "::: Web-Admin version is $(getLocalVersion "${WEBGITDIR}") (Latest version is $(getRemoteVersion AdminLTE))"
|
elif [ -z "$current" ] && [ -n "$latest" ]; then
|
||||||
fi
|
output="Latest ${1^} version is $latest"
|
||||||
}
|
elif [ "$hash" == "N/A" ]; then
|
||||||
|
output=""
|
||||||
webOutput() {
|
elif [ -n "$hash" ]; then
|
||||||
if [ -d "${WEBGITDIR}" ]; then
|
output="Current ${1^} hash is $hash"
|
||||||
case "${1}" in
|
|
||||||
"-l" | "--latest" ) echo $(getRemoteVersion AdminLTE);;
|
|
||||||
"-c" | "--current" ) echo $(getLocalVersion "${WEBGITDIR}");;
|
|
||||||
"-h" | "--hash" ) echo $(getLocalHash "${WEBGITDIR}");;
|
|
||||||
* ) echo "::: Invalid Option!"; exit 1;
|
|
||||||
esac
|
|
||||||
else
|
else
|
||||||
echo "::: Web interface not installed!"; exit 1;
|
errorOutput
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
[ -n "$output" ] && echo " $output"
|
||||||
}
|
}
|
||||||
|
|
||||||
coreOutput() {
|
errorOutput() {
|
||||||
case "${1}" in
|
echo " Invalid Option! Try 'pihole -v --help' for more information."
|
||||||
"-l" | "--latest" ) echo $(getRemoteVersion pi-hole);;
|
exit 1
|
||||||
"-c" | "--current" ) echo $(getLocalVersion "${PHGITDIR}");;
|
}
|
||||||
"-h" | "--hash" ) echo $(getLocalHash "${PHGITDIR}");;
|
|
||||||
* ) echo "::: Invalid Option!"; exit 1;
|
defaultOutput() {
|
||||||
esac
|
versionOutput "pi-hole" "$@"
|
||||||
|
versionOutput "AdminLTE" "$@"
|
||||||
|
versionOutput "FTL" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
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 ]
|
-p, --pihole Only retrieve info regarding Pi-hole repository
|
||||||
:::
|
-a, --admin Only retrieve info regarding AdminLTE repository
|
||||||
::: Options:
|
-f, --ftl Only retrieve info regarding FTL repository
|
||||||
::: -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 Return the current version
|
||||||
::: -c, --current (Only after -a | -p) Return only current version
|
-l, --latest Return the latest version
|
||||||
::: -h, --help Show this help dialog
|
-h, --hash Return the Github hash from your local repositories
|
||||||
:::
|
--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 "$@";;
|
"-p" | "--pihole" ) shift; versionOutput "pi-hole" "$@";;
|
||||||
"-p" | "--pihole" ) shift; coreOutput "$@" ;;
|
"-a" | "--admin" ) shift; versionOutput "AdminLTE" "$@";;
|
||||||
"-h" | "--help" ) helpFunc;;
|
"-f" | "--ftl" ) shift; versionOutput "FTL" "$@";;
|
||||||
|
"--help" ) helpFunc;;
|
||||||
|
* ) defaultOutput "$@";;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in a new issue