scripts/app/check.pihole.update

59 lines
1.8 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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 --quiet -- "Everything is up to 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