Move version messages to main function, check for repos.

This commit is contained in:
Dan Schaper 2016-11-02 01:12:02 -07:00
parent d9528dfd09
commit 7d414b5628

View file

@ -63,6 +63,7 @@ getGitFiles() {
fi fi
} }
main() {
is_repo "${PI_HOLE_FILES_DIR}" &> /dev/null is_repo "${PI_HOLE_FILES_DIR}" &> /dev/null
if [[ $? -eq 1 ]]; then #This is unlikely if [[ $? -eq 1 ]]; then #This is unlikely
@ -80,19 +81,14 @@ fi
echo "::: Checking for updates..." echo "::: Checking for updates..."
# Checks Pi-hole version > pihole only > current local git repo version : returns string in format vX.X.X # Checks Pi-hole version > pihole only > current local git repo version : returns string in format vX.X.X
piholeVersion="$(/usr/local/bin/pihole -v -p -c)" local -r pihole_version_current="$(/usr/local/bin/pihole -v -p -c)"
# Checks Pi-hole version > pihole only > remote upstream repo version : returns string in format vX.X.X # Checks Pi-hole version > pihole only > remote upstream repo version : returns string in format vX.X.X
piholeVersionLatest="$(/usr/local/bin/pihole -v -p -l)" local -r pihole_version_latest="$(/usr/local/bin/pihole -v -p -l)"
# Checks Pi-hole version > admin only > current local git repo version : returns string in format vX.X.X # Checks Pi-hole version > admin only > current local git repo version : returns string in format vX.X.X
webVersion="$(/usr/local/bin/pihole -v -a -c)" local -r web_version_current="$(/usr/local/bin/pihole -v -a -c)"
# Checks Pi-hole version > admin only > remote upstream repo version : returns string in format vX.X.X # Checks Pi-hole version > admin only > remote upstream repo version : returns string in format vX.X.X
webVersionLatest="$(/usr/local/bin/pihole -v -a -l)" local -r web_version_latest="$(/usr/local/bin/pihole -v -a -l)"
echo ":::"
echo "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)"
echo "::: Web Admin version is $webVersion (Latest version is $webVersionLatest)"
echo ":::"
# Logic # Logic
# If latest versions are blank - we've probably hit Github rate limit (stop running `pihole -up so often!): # If latest versions are blank - we've probably hit Github rate limit (stop running `pihole -up so often!):
@ -106,47 +102,50 @@ echo ":::"
# if Core NOT up to date AND web NOT up to date: # if Core NOT up to date AND web NOT up to date:
# pull pihole repo run install --unattended # pull pihole repo run install --unattended
if [[ "${pihole_version_current}" == "${pihole_version_latest}" ]] && [[ "${web_version_current}" == "${web_version_latest}" ]]; then
echo "::: Pi-hole version is $pihole_version_current"
if [[ "${piholeVersion}" == "${piholeVersionLatest}" ]] && [[ "${webVersion}" == "${webVersionLatest}" ]]; then echo "::: Web Admin version is $web_version_current"
echo "::: Everything is up to date!" echo "::: Everything is up to date!"
echo "" echo ""
exit 0 exit 0
elif [[ "${piholeVersion}" == "${piholeVersionLatest}" ]] && [[ "${webVersion}" != "${webVersionLatest}" ]]; then elif [[ "${pihole_version_current}" == "${pihole_version_latest}" ]] && [[ "${web_version_current}" != "${web_version_latest}" ]]; then
echo "::: Pi-hole Web Admin files out of date" echo "::: Pi-hole Web Admin files out of date"
getGitFiles "${ADMIN_INTERFACE_DIR}" "${ADMIN_INTERFACE_GIT_URL}" getGitFiles "${ADMIN_INTERFACE_DIR}" "${ADMIN_INTERFACE_GIT_URL}"
echo ":::" echo ":::"
webVersion="$(/usr/local/bin/pihole -v -a -c)" web_version_current="$(/usr/local/bin/pihole -v -a -c)"
echo "::: Web Admin version is now at ${webVersion}" echo "::: Web Admin version is now at ${web_version_current}"
echo "::: If you had made any changes in '/var/www/html/admin', they have been stashed using 'git stash'" echo "::: If you had made any changes in '/var/www/html/admin', they have been stashed using 'git stash'"
echo "" echo ""
elif [[ "${piholeVersion}" != "${piholeVersionLatest}" ]] && [[ "${webVersion}" == "${webVersionLatest}" ]]; then elif [[ "${pihole_version_current}" != "${pihole_version_latest}" ]] && [[ "${web_version_current}" == "${web_version_latest}" ]]; then
echo "::: Pi-hole core files out of date" echo "::: Pi-hole core files out of date"
getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}" getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}"
/etc/.pihole/automated\ install/basic-install.sh --reconfigure --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1 /etc/.pihole/automated\ install/basic-install.sh --reconfigure --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1
echo ":::" echo ":::"
piholeVersion="$(/usr/local/bin/pihole -v -p -c)" pihole_version_current="$(/usr/local/bin/pihole -v -p -c)"
echo "::: Pi-hole version is now at ${piholeVersion}" echo "::: Pi-hole version is now at ${pihole_version_current}"
echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'" echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'"
echo "" echo ""
elif [[ "${piholeVersion}" != "${piholeVersionLatest}" ]] && [[ "${webVersion}" != "${webVersionLatest}" ]]; then elif [[ "${pihole_version_current}" != "${pihole_version_latest}" ]] && [[ "${web_version_current}" != "${web_version_latest}" ]]; then
echo "::: Updating Everything" echo "::: Updating Everything"
getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}" getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}"
/etc/.pihole/automated\ install/basic-install.sh --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1 /etc/.pihole/automated\ install/basic-install.sh --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1
# Checks Pi-hole version > admin only > current local git repo version : returns string in format vX.X.X # Checks Pi-hole version > admin only > current local git repo version : returns string in format vX.X.X
webVersion="$(/usr/local/bin/pihole -v -a -c)" web_version_current="$(/usr/local/bin/pihole -v -a -c)"
# Checks Pi-hole version > admin only > current local git repo version : returns string in format vX.X.X # Checks Pi-hole version > admin only > current local git repo version : returns string in format vX.X.X
piholeVersion="$(/usr/local/bin/pihole -v -p -c)" pihole_version_current="$(/usr/local/bin/pihole -v -p -c)"
echo ":::" echo ":::"
echo "::: Pi-hole version is now at ${piholeVersion}" echo "::: Pi-hole version is now at ${pihole_version_current}"
echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'" echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'"
echo ":::" echo ":::"
echo "::: Pi-hole version is now at ${piholeVersion}" echo "::: Pi-hole version is now at ${pihole_version_current}"
echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'" echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'"
echo "" echo ""
fi fi
}
main