2019-08-13 13:56:26 +02:00
#!/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 {{{
2019-08-13 14:10:10 +02:00
DEBUG=1
2019-08-13 13:56:26 +02:00
script_wd=$(dirname "${0}")
ssp_repo_url="https://github.com/ltb-project/self-service-password"
2019-08-13 14:10:10 +02:00
if [ $# -eq 1 ] ## If source directory should be used
then
ssp_install_dir="${1}"
ssp_current_version=$(cd "${ssp_install_dir}" || exit 1 ; git status | head -n1 | cut -d" " -f4 ; cd - > /dev/null || exit 1)
ssp_new_version=$("${script_wd}"/releasetags "${ssp_repo_url}" | head -n1)
else ## If .deb file should be used
ssp_current_version=$(dpkg -l self-service-password | awk '/^ii.*self-service-password/ { print $3}' | sed 's/\(.*\)-.*/\1/')
ssp_new_version=$("${script_wd}"/releasetags "${ssp_repo_url}" | head -n1 | sed 's/v//g')
fi
2019-08-13 13:56:26 +02:00
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}"
2019-08-22 09:26:59 +02:00
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Self Service Password/SSP (current : ${ssp_current_version}) : ${ssp_new_version}." >> "${ssp_new_version_file}"
2019-08-13 13:56:26 +02:00
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