scripts/app/check.pihole.update

59 lines
1.8 KiB
Plaintext
Raw Permalink Normal View History

2021-06-25 15:51:08 +02:00
#!/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 {{{
2021-07-07 12:42:13 +02:00
if printf -- '%s' "${pihole_current_status}" | grep --quiet -- "Everything is up to date"; then
2021-06-25 15:51:08 +02:00
[ "${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