Fix `pihole -v` output if WebAdmin not installed (#4370)

* Fix https://github.com/pi-hole/pi-hole/issues/4279

Signed-off-by: Subhaditya Nath <sn03.general@gmail.com>

* Don't ignore exit code of version.sh

If it exits with a non-zero return code, that means some error occurred,
and so it shouldn't be ignored.

Signed-off-by: Subhaditya Nath <sn03.general@gmail.com>

* Implement changes suggested by @Michalng

Signed-off-by: Subhaditya Nath <sn03.general@gmail.com>

* Implement changes suggested by @PromoFaux

Signed-off-by: Subhaditya Nath <sn03.general@gmail.com>

* Always source /etc/pihole/setupVars.conf

https://github.com/pi-hole/pi-hole/pull/4370#issuecomment-978149567

Co-authored-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
Subhaditya Nath 2021-12-03 02:16:11 +05:30 committed by GitHub
parent e485a7b9bb
commit ba6d700e7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View File

@ -13,6 +13,10 @@ DEFAULT="-1"
COREGITDIR="/etc/.pihole/"
WEBGITDIR="/var/www/html/admin/"
# Source the setupvars config file
# shellcheck disable=SC1091
source /etc/pihole/setupVars.conf
getLocalVersion() {
# FTL requires a different method
if [[ "$1" == "FTL" ]]; then
@ -91,10 +95,11 @@ getRemoteVersion(){
#If the above file exists, then we can read from that. Prevents overuse of GitHub API
if [[ -f "$cachedVersions" ]]; then
IFS=' ' read -r -a arrCache < "$cachedVersions"
case $daemon in
"pi-hole" ) echo "${arrCache[0]}";;
"AdminLTE" ) echo "${arrCache[1]}";;
"FTL" ) echo "${arrCache[2]}";;
"AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${arrCache[1]}";;
"FTL" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${arrCache[2]}" || echo "${arrCache[1]}";;
esac
return 0
@ -140,6 +145,11 @@ getLocalBranch(){
}
versionOutput() {
if [[ "$1" == "AdminLTE" && "${INSTALL_WEB_INTERFACE}" != true ]]; then
echo " WebAdmin not installed"
return 1
fi
[[ "$1" == "pi-hole" ]] && GITDIR=$COREGITDIR
[[ "$1" == "AdminLTE" ]] && GITDIR=$WEBGITDIR
[[ "$1" == "FTL" ]] && GITDIR="FTL"
@ -166,6 +176,7 @@ versionOutput() {
output="Latest ${1^} hash is $latHash"
else
errorOutput
return 1
fi
[[ -n "$output" ]] && echo " $output"
@ -177,10 +188,6 @@ errorOutput() {
}
defaultOutput() {
# Source the setupvars config file
# shellcheck disable=SC1091
source /etc/pihole/setupVars.conf
versionOutput "pi-hole" "$@"
if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then

3
pihole
View File

@ -95,8 +95,7 @@ uninstallFunc() {
versionFunc() {
shift
"${PI_HOLE_SCRIPT_DIR}"/version.sh "$@"
exit 0
exec "${PI_HOLE_SCRIPT_DIR}"/version.sh "$@"
}
# Get PID of main pihole-FTL process