67 lines
2.2 KiB
Bash
Executable File
67 lines
2.2 KiB
Bash
Executable File
#!/bin/sh
|
||
# Purpose {{{
|
||
## Create a temp file (to monitor) if an upgrade is available for cState
|
||
## project on Github.
|
||
## It's based on the cState URL site to get the current version.
|
||
## 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 cState URL as first argument, eg.
|
||
#00 20 * * * root /opt/repos/ipr.scripts/github/check.cstate.update https://vmstatus.domain.tld
|
||
### 3. Monitor the temp file : /tmp/.github.cstate.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.cstate.update --
|
||
Compare current version of an installed cState site and the last available.
|
||
|
||
EXAMPLE :
|
||
- Compare the current version installed on https://vmstatus.domain.tld
|
||
check.cstate.update https://vmstatus.domain.tld
|
||
|
||
HELP
|
||
|
||
exit 1
|
||
fi
|
||
|
||
# }}}
|
||
|
||
# Vars {{{
|
||
DEBUG=1
|
||
|
||
script_wd=$(dirname "${0}")
|
||
|
||
cstate_url="${1}"
|
||
cstate_current_version=$(curl --insecure --silent "${cstate_url}" | grep -E 'meta.*generator.*cState.*github.com' | sed 's;.*generator.*content.*cState \(v.*\) - https.*github.com.*;\1;')
|
||
|
||
cstate_repo_url="https://github.com/cstate/cstate"
|
||
cstate_new_version=$("${script_wd}"/releasetags "${cstate_repo_url}" | grep -vE -- '(dev|rc)' | head -n1)
|
||
|
||
cstate_new_version_file="/tmp/.github.cstate.upgrade"
|
||
# }}}
|
||
|
||
# Check if the current version is the last one {{{
|
||
if [ "${cstate_current_version}" != "${cstate_new_version}" ]; then
|
||
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test version — Current version (${cstate_current_version}) and new one (${cstate_new_version}) seems to be different."
|
||
|
||
## Create a temp file to monitor
|
||
touch -- "${cstate_new_version_file}"
|
||
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for cState (current : ${cstate_current_version}) : ${cstate_new_version}." >> "${cstate_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 -- "${cstate_new_version_file}"
|
||
fi
|
||
# }}}
|
||
|
||
exit 0
|