From d4fed686d0d9e4ac0f9daf67d89473d9fbdbd04f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Tue, 13 Aug 2019 13:56:26 +0200 Subject: [PATCH] Script to check if installed SSP is uptodate --- github/check.self-service-password.update | 72 +++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 github/check.self-service-password.update diff --git a/github/check.self-service-password.update b/github/check.self-service-password.update new file mode 100755 index 0000000..4ee31b3 --- /dev/null +++ b/github/check.self-service-password.update @@ -0,0 +1,72 @@ +#!/bin/sh +# Purpose {{{ +## Create a temp file (to monitor) if an upgrade is available for Self Service Password (SSP) +## project on Github. +## It's based on .deb package installation to check the current version. +## It can also be based on installation from source if the self-service-password's +## root is given as first argument. +## 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, eg : +#00 20 * * * root /opt/repos/ipr.scripts/github/check.self-service-password.update +### 2-1. Create a cron job with Self Service Password (SSP) directory as first argument, eg : +#00 20 * * * root /opt/repos/ipr.scripts/github/check.self-service-password.update /var/www/self-service-password +### 3. Monitor the temp file : /tmp/.github.self-service-password.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.self-service-password.update -- +Compare current version of an installed Self Service Password (SSP) and the last available. + +EXAMPLE : + - Compare the current version installed from .deb file + check.self-service-password.update + + - Compare the current version installed from sources in /var/www/self-service-password + check.self-service-password.update /var/www/self-service-password + +HELP + + exit 1 +fi +# }}} + +# Vars {{{ +DEBUG=0 + +script_wd=$(dirname "${0}") + +ssp_install_dir="${1}" +ssp_current_version=$(cd "${ssp_install_dir}" || exit 1 ; git status | head -n1 | cut -d" " -f4 | sed 's/v//g' ; cd - > /dev/null || exit 1) + +ssp_repo_url="https://github.com/ltb-project/self-service-password" +ssp_new_version=$("${script_wd}"/releasetags "${ssp_repo_url}" | head -n1 | sed 's/v//g') + +ssp_new_version_file="/tmp/.github.self-service-password.upgrade" +# }}} + +# Check if the current version is the last one {{{ +if [ "${ssp_current_version}" != "${ssp_new_version}" ]; then + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test version — Current version (${ssp_current_version}) and new one (${ssp_new_version}) seems to be different." + + ## Create a temp file to monitor + touch -- "${ssp_new_version_file}" + printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Self Service Password (SSP) : ${ssp_new_version}." >> "${ssp_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 -- "${ssp_new_version_file}" +fi +# }}} + +exit 0