scripts/github/check.self-service-password...

80 lines
3.0 KiB
Bash
Executable File
Raw 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.

#!/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-rennes.fr/cellinfo/scripts/src/master/github/releasetags
# wget https://git.ipr.univ-rennes.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=1
script_wd=$(dirname "${0}")
ssp_repo_url="https://github.com/ltb-project/self-service-password"
if [ $# -eq 1 ] ## If source directory should be used
then
ssp_install_dir="${1}"
ssp_current_version=$(find "${ssp_install_dir}" -iname index.php -exec grep -- "^\$version" {} \; | cut -d'"' -f2)
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
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 (current: ${ssp_current_version}): ${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