2021-02-24 13:49:37 +01:00
#!/bin/sh
# Purpose {{{
2021-03-24 10:07:55 +01:00
## Create a file (to monitor) if an upgrade is available for Ceph
2021-02-24 13:49:37 +01:00
## project on Github.
## It's based on .deb package (or repository) installation to check 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, eg :
2021-02-24 13:57:11 +01:00
#00 20 * * * root /opt/repos/ipr.scripts/github/check_ceph_update
2021-03-24 10:07:55 +01:00
### 3. Monitor the file : /srv/.github.ceph.upgrade
2021-02-24 13:49:37 +01:00
# Or enable MAILTO in cronjob and edit the script to print a message.
# Or send a mail.
# …
## }}}
# }}}
# Don't expect any argument {{{
if [ $# -gt 0 ]
then
cat << HELP
check.ceph.update --
Compare current version of an installed Ceph and the last available (filtered according to current major version).
EXAMPLE :
- Compare the current version installed from .deb file or repository
check.ceph.update
HELP
exit 1
fi
# }}}
# Vars {{{
DEBUG=1
script_wd=$(dirname "${0}")
ceph_repo_url="https://github.com/ceph/ceph"
ceph_current_version=$(dpkg -l ceph | awk '/^ii.*ceph/ { print $3}' | sed 's/\(.*\)-.*/\1/')
ceph_current_major_version=$(printf -- '%s' "${ceph_current_version}" | cut -d"." -f1)
## Filter new versions to get only same major releases
ceph_new_version=$("${script_wd}"/releasetags "${ceph_repo_url}" | \
grep "v${ceph_current_major_version}" | \
head -n1 | \
sed 's/v//g')
2021-03-24 10:07:55 +01:00
ceph_new_version_file="/srv/.github.ceph.upgrade"
2021-02-24 13:49:37 +01:00
# }}}
# Check if the current version is the last one {{{
if [ "${ceph_current_version}" != "${ceph_new_version}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test version — Current version (${ceph_current_version}) and new one (${ceph_new_version}) seems to be different."
2021-03-24 10:07:55 +01:00
## Create a file to monitor
2021-02-24 13:49:37 +01:00
touch -- "${ceph_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Ceph (current : ${ceph_current_version}) : ${ceph_new_version}." >> "${ceph_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 -- "${ceph_new_version_file}"
fi
# }}}
exit 0