scripts/github/check.cachet.update

68 lines
2.3 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for Cachet
## project on Github.
## It based on the cachet's root directory to get the current version and
## supposed to be install from source (github) or at least get a VERSION file.
## How-to use {{{
### 1. Needs releasetags script, in the same directory
### cf. https://git.ipr.univ-rennes1.fr/cellinfo/scripts/src/master/github/releasetags
# wget https://git.ipr.univ-rennes1.fr/cellinfo/scripts/raw/master/github/releasetags
### 2. Create a cron job with Cachet directory as first argument, eg.
#00 20 * * * root /opt/repos/ipr.scripts/github/check_cachet_update /var/www/cachet
### 3. Monitor the temp file: /tmp/.github.cachet.upgrade
# Or enable MAILTO in cronjob and edit the script to print a message.
# Or send a mail.
# …
## }}}
# }}}
# Expect 1 argument {{{
if [ $# -ne 1 ]
then
cat << HELP
check.cachet.update --
Compare current version of an installed Cachet and the last available.
EXAMPLE:
- Compare the current version installed in /var/www/cachet.domain.tld
check.cachet.update /var/www/cachet.domain.tld
HELP
exit 1
fi
# }}}
# Vars {{{
DEBUG=1
script_wd=$(dirname "${0}")
cachet_install_dir="${1}"
cachet_current_version=$(cd "${cachet_install_dir}" || exit 1 ; grep . -m1 VERSION | sed 's/\(.*\)-.*/\1/g' ; cd - > /dev/null || exit 1)
cachet_repo_url="https://github.com/CachetHQ/Cachet"
cachet_new_version=$("${script_wd}"/releasetags "${cachet_repo_url}" | head -n1 | sed 's/v//')
cachet_new_version_file="/tmp/.github.cachet.upgrade"
# }}}
# Check if the current version is the last one {{{
if [ "${cachet_current_version}" != "${cachet_new_version}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Current version (${cachet_current_version}) and new one (${cachet_new_version}) seems to be different."
## Create a temp file to monitor
touch -- "${cachet_new_version_file}"
2019-08-22 09:26:59 +02:00
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Cachet (current: ${cachet_current_version}): ${cachet_new_version}." >> "${cachet_new_version_file}"
else
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — The current version is up-to-date."
rm -f -- "${cachet_new_version_file}"
fi
# }}}
exit 0