mirror of
https://github.com/pi-hole/pi-hole
synced 2025-01-03 12:40:56 +00:00
Collapse duplicate functions, and take out argument loops.
Signed-off-by: Dan Schaper <dan.schaper@pi-hole.net>
This commit is contained in:
parent
77ab47a984
commit
945e22874e
@ -13,54 +13,38 @@ DEFAULT="-1"
|
|||||||
PHGITDIR="/etc/.pihole/"
|
PHGITDIR="/etc/.pihole/"
|
||||||
WEBGITDIR="/var/www/html/admin/"
|
WEBGITDIR="/var/www/html/admin/"
|
||||||
|
|
||||||
getLocalPHVersion(){
|
getLocalVersion() {
|
||||||
# Get the tagged version of the local Pi-hole repository
|
# Get the tagged version of the local repository
|
||||||
|
local directory="${1}"
|
||||||
local version
|
local version
|
||||||
local hash
|
|
||||||
|
|
||||||
cd "${PHGITDIR}" || { PHVERSION="${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
|
||||||
PHVERSION="${version}"
|
echo "${version}"
|
||||||
elif [[ "${version}" == "${DEFAULT}" ]]; then
|
elif [[ "${version}" == "${DEFAULT}" ]]; then
|
||||||
PHVERSION="ERROR"
|
echo "ERROR"
|
||||||
|
return 1
|
||||||
else
|
else
|
||||||
PHVERSION="Untagged"
|
echo "Untagged"
|
||||||
fi
|
|
||||||
|
|
||||||
hash=$(git rev-parse --short HEAD || \
|
|
||||||
echo "${DEFAULT}")
|
|
||||||
if [[ "${hash}" == "${DEFAULT}" ]]; then
|
|
||||||
PHHASH="ERROR"
|
|
||||||
else
|
|
||||||
PHHASH="${hash}"
|
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
getLocalWebVersion(){
|
getLocalHash() {
|
||||||
# Get the tagged version of the local Pi-hole repository
|
# Get the short hash of the local repository
|
||||||
local version
|
local directory="${1}"
|
||||||
local hash
|
local hash
|
||||||
|
|
||||||
cd "${WEBGITDIR}" || { WEBVERSION="${DEFAULT}"; return 1; }
|
cd "${directory}" || { echo "${DEFAULT}"; return 1; }
|
||||||
version=$(git describe --tags --always || \
|
|
||||||
echo "${DEFAULT}")
|
|
||||||
if [[ "${version}" =~ ^v ]]; then
|
|
||||||
WEBVERSION="${version}"
|
|
||||||
elif [[ "${version}" == "${DEFAULT}" ]]; then
|
|
||||||
WEBVERSION="ERROR"
|
|
||||||
else
|
|
||||||
WEBVERSION="Untagged"
|
|
||||||
fi
|
|
||||||
|
|
||||||
hash=$(git rev-parse --short HEAD || \
|
hash=$(git rev-parse --short HEAD || \
|
||||||
echo "${DEFAULT}")
|
echo "${DEFAULT}")
|
||||||
if [[ "${hash}" == "${DEFAULT}" ]]; then
|
if [[ "${hash}" == "${DEFAULT}" ]]; then
|
||||||
WEBHASH="ERROR"
|
echo "ERROR"
|
||||||
|
return 1
|
||||||
else
|
else
|
||||||
WEBHASH="${hash}"
|
echo "${hash}"
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -91,25 +75,21 @@ normalOutput() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
webOutput() {
|
webOutput() {
|
||||||
for var in "$1"; do
|
case "${1}" in
|
||||||
case "${var}" in
|
"-l" | "--latest" ) echo "${WEBVERSIONLATEST:-${DEFAULT}}";;
|
||||||
"-l" | "--latest" ) echo "${WEBVERSIONLATEST:-${DEFAULT}}";;
|
"-c" | "--current" ) echo "${WEBVERSION}";;
|
||||||
"-c" | "--current" ) echo "${WEBVERSION}";;
|
"-h" | "--hash" ) echo "${WEBHASH}";;
|
||||||
"-h" | "--hash" ) echo "${WEBHASH}";;
|
* ) echo "::: Invalid Option!"; exit 1;
|
||||||
* ) echo "::: Invalid Option!"; exit 1;
|
esac
|
||||||
esac
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
coreOutput() {
|
coreOutput() {
|
||||||
for var in "$1"; do
|
case "${1}" in
|
||||||
case "${var}" in
|
"-l" | "--latest" ) echo "${PHVERSIONLATEST:-${DEFAULT}}";;
|
||||||
"-l" | "--latest" ) echo "${PHVERSIONLATEST:-${DEFAULT}}";;
|
"-c" | "--current" ) echo "${PHVERSION}";;
|
||||||
"-c" | "--current" ) echo "${PHVERSION}";;
|
"-h" | "--hash" ) echo "${PHHASH}";;
|
||||||
"-h" | "--hash" ) echo "${PHHASH}";;
|
* ) echo "::: Invalid Option!"; exit 1;
|
||||||
* ) echo "::: Invalid Option!"; exit 1;
|
esac
|
||||||
esac
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
helpFunc() {
|
helpFunc() {
|
||||||
@ -130,17 +110,18 @@ EOM
|
|||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
getLocalPHVersion
|
PHVERSION=$(getLocalVersion "${PHGITDIR}")
|
||||||
getLocalWebVersion
|
PHHASH=$(getLocalHash "${PHGITDIR}")
|
||||||
|
WEBVERSION=$(getLocalVersion "${WEBGITDIR}")
|
||||||
|
WEBHASH=$(getLocalHash "${WEBGITDIR}")
|
||||||
|
|
||||||
|
|
||||||
if [[ $# = 0 ]]; then
|
if [[ $# = 0 ]]; then
|
||||||
normalOutput
|
normalOutput
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for var in "$1"; do
|
case "${1}" in
|
||||||
case "${var}" in
|
"-a" | "--admin" ) shift; webOutput "$@";;
|
||||||
"-a" | "--admin" ) shift; webOutput "$@";;
|
"-p" | "--pihole" ) shift; coreOutput "$@" ;;
|
||||||
"-p" | "--pihole" ) shift; coreOutput "$@" ;;
|
"-h" | "--help" ) helpFunc;;
|
||||||
"-h" | "--help" ) helpFunc;;
|
esac
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
Loading…
Reference in New Issue
Block a user