From 500a5af1db1fd8081d6b9356e3c3f2449d6b31ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Tue, 13 Aug 2019 17:40:37 +0200 Subject: [PATCH] Script to check if Cachet installation is uptodate --- github/check.cachet.update | 67 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 github/check.cachet.update diff --git a/github/check.cachet.update b/github/check.cachet.update new file mode 100755 index 0000000..72ad5a4 --- /dev/null +++ b/github/check.cachet.update @@ -0,0 +1,67 @@ +#!/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}" + printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Cachet : ${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