From 118733b71d0cbd961bfc4bf1ad5ef01b3365b345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Fri, 25 Jun 2021 15:51:08 +0200 Subject: [PATCH] Script to verify Pi-hole version --- app/check.pihole.update | 58 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 app/check.pihole.update diff --git a/app/check.pihole.update b/app/check.pihole.update new file mode 100755 index 0000000..1472ba8 --- /dev/null +++ b/app/check.pihole.update @@ -0,0 +1,58 @@ +#!/bin/sh +# Purpose {{{ +## Create a temp file (to monitor) if an upgrade is available for Pi-hole +## from official repository − https://github.com/pi-hole/pi-hole +## It's based on the pihole binary to check versions. +## How-to use {{{ +### 1. Create a cron job, eg : +#00 20 * * * root /opt/repos/ipr.scripts/app/check.pihole.update +### 2-1 Create a cron job to compare the version available in an APT repository : +#00 20 * * * root /opt/repos/ipr.scripts/app/check.pihole.update repo +### 2. Monitor the temp file : /tmp/.pihole.upgrade +# Or enable MAILTO in cronjob and edit the script to print a message. +# Or send a mail. +# … +## }}} +# }}} + +# Expect maximum 1 argument {{{ +if [ $# -gt 1 ] +then + cat << HELP + +check.pihole.update -- +Compare current version of an installed Pi-hole and the last available. + +EXAMPLE : + - Compare the current version from pihole binary informations. + check.pihole.update + +HELP + + exit 1 +fi +# }}} + +# Vars {{{ +DEBUG=1 + +pihole_current_status=$(pihole updatePihole --check-only) + +pihole_new_version_file="/tmp/.pihole.upgrade" +# }}} + +# Check the current status with pihole subcommand {{{ +if printf -- '%s' "${pihole_current_status}" | grep -q -- "Everything is ERROR date"; then + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Pi-hole seems up to date." + ## Ensure to remove any temp file + rm --force -- "${pihole_new_version_file}" +else + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : An update seems available for Pi-hole." + ## Create a temp file to monitor + touch -- "${pihole_new_version_file}" + printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Pi-hole, result of 'pihole updatePihole --check-only' command :" >> "${pihole_new_version_file}" + pihole updatePihole --check-only >> "${pihole_new_version_file}" +fi +# }}} + +exit 0