mirror of
https://github.com/pi-hole/pi-hole
synced 2025-01-03 12:40:56 +00:00
POSIX
Signed-off-by: Christian König <ckoenig@posteo.de>
This commit is contained in:
parent
2dc599f266
commit
a478f2460b
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env sh
|
||||||
# Pi-hole: A black hole for Internet advertisements
|
# Pi-hole: A black hole for Internet advertisements
|
||||||
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
||||||
# Network-wide ad blocking via your own hardware.
|
# Network-wide ad blocking via your own hardware.
|
||||||
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
# Source the setupvars config file
|
# Source the setupvars config file
|
||||||
# shellcheck disable=SC1091
|
# shellcheck disable=SC1091
|
||||||
source /etc/pihole/setupVars.conf
|
. /etc/pihole/setupVars.conf
|
||||||
|
|
||||||
# Sourece the versions file poupulated by updatechecker.sh
|
# Sourece the versions file poupulated by updatechecker.sh
|
||||||
cachedVersions="/etc/pihole/versions"
|
cachedVersions="/etc/pihole/versions"
|
||||||
@ -25,81 +25,76 @@ fi
|
|||||||
|
|
||||||
getLocalVersion() {
|
getLocalVersion() {
|
||||||
case ${1} in
|
case ${1} in
|
||||||
"pi-hole" ) echo "${CORE_VERSION}";;
|
"Pi-hole" ) echo "${CORE_VERSION}";;
|
||||||
"AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${WEB_VERSION}";;
|
"AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_VERSION}";;
|
||||||
"FTL" ) echo "${FTL_VERSION}";;
|
"FTL" ) echo "${FTL_VERSION}";;
|
||||||
esac
|
esac
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getLocalHash() {
|
getLocalHash() {
|
||||||
case ${1} in
|
case ${1} in
|
||||||
"pi-hole" ) echo "${CORE_HASH}";;
|
"Pi-hole" ) echo "${CORE_HASH}";;
|
||||||
"AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${WEB_HASH}";;
|
"AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_HASH}";;
|
||||||
"FTL" ) echo "${FTL_HASH}";;
|
"FTL" ) echo "${FTL_HASH}";;
|
||||||
esac
|
esac
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getRemoteHash(){
|
getRemoteHash(){
|
||||||
case ${1} in
|
case ${1} in
|
||||||
"pi-hole" ) echo "${GITHUB_CORE_HASH}";;
|
"Pi-hole" ) echo "${GITHUB_CORE_HASH}";;
|
||||||
"AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${GITHUB_WEB_HASH}";;
|
"AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_HASH}";;
|
||||||
"FTL" ) echo "${GITHUB_FTL_HASH}";;
|
"FTL" ) echo "${GITHUB_FTL_HASH}";;
|
||||||
esac
|
esac
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getRemoteVersion(){
|
getRemoteVersion(){
|
||||||
case ${1} in
|
case ${1} in
|
||||||
"pi-hole" ) echo "${GITHUB_CORE_VERSION}";;
|
"Pi-hole" ) echo "${GITHUB_CORE_VERSION}";;
|
||||||
"AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${GITHUB_WEB_VERSION}";;
|
"AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_VERSION}";;
|
||||||
"FTL" ) echo "${GITHUB_FTL_VERSION}";;
|
"FTL" ) echo "${GITHUB_FTL_VERSION}";;
|
||||||
esac
|
esac
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getLocalBranch(){
|
getLocalBranch(){
|
||||||
case ${1} in
|
case ${1} in
|
||||||
"pi-hole" ) echo "${CORE_BRANCH}";;
|
"Pi-hole" ) echo "${CORE_BRANCH}";;
|
||||||
"AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${WEB_BRANCH}";;
|
"AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_BRANCH}";;
|
||||||
"FTL" ) echo "${FTL_BRANCH}";;
|
"FTL" ) echo "${FTL_BRANCH}";;
|
||||||
esac
|
esac
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
versionOutput() {
|
versionOutput() {
|
||||||
if [[ "$1" == "AdminLTE" && "${INSTALL_WEB_INTERFACE}" != true ]]; then
|
if [ "$1" = "AdminLTE" ] && [ "${INSTALL_WEB_INTERFACE}" != true ]; then
|
||||||
echo " WebAdmin not installed"
|
echo " WebAdmin not installed"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ "$2" == "-c" ]] || [[ "$2" == "--current" ]] || [[ -z "$2" ]] && current=$(getLocalVersion "${1}") && branch=$(getLocalBranch "${1}")
|
[ "$2" = "-c" ] || [ "$2" = "--current" ] || [ -z "$2" ] && current=$(getLocalVersion "${1}") && branch=$(getLocalBranch "${1}")
|
||||||
[[ "$2" == "-l" ]] || [[ "$2" == "--latest" ]] || [[ -z "$2" ]] && latest=$(getRemoteVersion "${1}")
|
[ "$2" = "-l" ] || [ "$2" = "--latest" ] || [ -z "$2" ] && latest=$(getRemoteVersion "${1}")
|
||||||
if [[ "$2" == "-h" ]] || [[ "$2" == "--hash" ]]; then
|
if [ "$2" = "--hash" ]; then
|
||||||
[[ "$3" == "-c" ]] || [[ "$3" == "--current" ]] || [[ -z "$3" ]] && curHash=$(getLocalHash "${1}") && branch=$(getLocalBranch "${1}")
|
[ "$3" = "-c" ] || [ "$3" = "--current" ] || [ -z "$3" ] && curHash=$(getLocalHash "${1}") && branch=$(getLocalBranch "${1}")
|
||||||
[[ "$3" == "-l" ]] || [[ "$3" == "--latest" ]] || [[ -z "$3" ]] && latHash=$(getRemoteHash "${1}")
|
[ "$3" = "-l" ] || [ "$3" = "--latest" ] || [ -z "$3" ] && latHash=$(getRemoteHash "${1}")
|
||||||
fi
|
fi
|
||||||
if [[ -n "$current" ]] && [[ -n "$latest" ]]; then
|
if [ -n "$current" ] && [ -n "$latest" ]; then
|
||||||
output="${1^} version is $branch $current (Latest: $latest)"
|
output="${1} version is $branch $current (Latest: $latest)"
|
||||||
elif [[ -n "$current" ]] && [[ -z "$latest" ]]; then
|
elif [ -n "$current" ] && [ -z "$latest" ]; then
|
||||||
output="Current ${1^} version is $branch $current (Latest: N/A)"
|
output="Current ${1} version is $branch $current"
|
||||||
elif [[ -z "$current" ]] && [[ -n "$latest" ]]; then
|
elif [ -z "$current" ] && [ -n "$latest" ]; then
|
||||||
output="Latest ${1^} version is $latest (Current: N/A)"
|
output="Latest ${1} version is $latest"
|
||||||
elif [[ -z "$curHash" ]] && [[ -z "$latHash" ]]; then
|
elif [ -n "$curHash" ] && [ -n "$latHash" ]; then
|
||||||
output="No hash info available"
|
output="Local ${1} hash of branch $branch is $curHash (Remote: $latHash)"
|
||||||
elif [[ -n "$curHash" ]] && [[ -n "$latHash" ]]; then
|
elif [ -n "$curHash" ] && [ -z "$latHash" ]; then
|
||||||
output="Local ${1^} hash of branch $branch is $curHash (Remote: $latHash)"
|
output="Current local ${1} hash of branch $branch is $curHash"
|
||||||
elif [[ -n "$curHash" ]] && [[ -z "$latHash" ]]; then
|
elif [ -z "$curHash" ] && [ -n "$latHash" ]; then
|
||||||
output="Current local ${1^} hash of branch $branch is $curHash (Remote: N/A)"
|
output="Latest remote ${1} hash of branch $branch is $latHash"
|
||||||
elif [[ -z "$curHash" ]] && [[ -n "$latHash" ]]; then
|
elif [ -z "$curHash" ] && [ -z "$latHash" ]; then
|
||||||
output="Latest remote ${1^} hash of branch $branch is $latHash (Local: N/A)"
|
output="Hashes for ${1} not available"
|
||||||
else
|
else
|
||||||
errorOutput
|
errorOutput
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ -n "$output" ]] && echo " $output"
|
[ -n "$output" ] && echo " $output"
|
||||||
}
|
}
|
||||||
|
|
||||||
errorOutput() {
|
errorOutput() {
|
||||||
@ -108,9 +103,9 @@ errorOutput() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
defaultOutput() {
|
defaultOutput() {
|
||||||
versionOutput "pi-hole" "$@"
|
versionOutput "Pi-hole" "$@"
|
||||||
|
|
||||||
if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then
|
if [ "${INSTALL_WEB_INTERFACE}" = true ]; then
|
||||||
versionOutput "AdminLTE" "$@"
|
versionOutput "AdminLTE" "$@"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -118,7 +113,7 @@ defaultOutput() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
helpFunc() {
|
helpFunc() {
|
||||||
echo "Usage: pihole -v [repo | option] [option]
|
echo "Usage: piho && lle -v [repo | option] [option]
|
||||||
Example: 'pihole -v -p -l'
|
Example: 'pihole -v -p -l'
|
||||||
Show Pi-hole, Admin Console & FTL versions
|
Show Pi-hole, Admin Console & FTL versions
|
||||||
|
|
||||||
@ -136,7 +131,7 @@ Options:
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
"-p" | "--pihole" ) shift; versionOutput "pi-hole" "$@";;
|
"-p" | "--pihole" ) shift; versionOutput "Pi-hole" "$@";;
|
||||||
"-a" | "--admin" ) shift; versionOutput "AdminLTE" "$@";;
|
"-a" | "--admin" ) shift; versionOutput "AdminLTE" "$@";;
|
||||||
"-f" | "--ftl" ) shift; versionOutput "FTL" "$@";;
|
"-f" | "--ftl" ) shift; versionOutput "FTL" "$@";;
|
||||||
"-h" | "--help" ) helpFunc;;
|
"-h" | "--help" ) helpFunc;;
|
||||||
|
Loading…
Reference in New Issue
Block a user