Script to monitor new version of PrivateBin project

This commit is contained in:
Jeremy Gardais 2019-08-26 14:59:05 +02:00
parent e37544c96f
commit 088523f955
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 67 additions and 0 deletions

67
github/check.privatebin.update Executable file
View File

@ -0,0 +1,67 @@
#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for PrivateBin
## project on Github.
## It based on the privatebin's root directory to get the current version and
## supposed to be install from source (github) or archives.
## 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 PrivateBin directory as first argument, eg.
#00 20 * * * root /opt/repos/ipr.scripts/github/check.privatebin.update /var/www/privatebin
### 3. Monitor the temp file: /tmp/.github.privatebin.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.privatebin.update --
Compare current version of an installed PrivateBin and the last available.
EXAMPLE:
- Compare the current version installed in /var/www/privatebin.domain.tld
check.privatebin.update /var/www/privatebin.domain.tld
HELP
exit 1
fi
# }}}
# Vars {{{
DEBUG=0
script_wd=$(dirname "${0}")
pb_install_dir="${1}"
pb_current_version=$(cd "${pb_install_dir}" || exit 1 ; awk '/@version/ { print $3 }' index.php || exit 1 ; cd - > /dev/null || exit 1)
pb_repo_url="https://github.com/PrivateBin/PrivateBin"
pb_new_version=$("${script_wd}"/releasetags "${pb_repo_url}" | head -n1 | sed 's/v//')
pb_new_version_file="/tmp/.github.privatebin.upgrade"
# }}}
# Check if the current version is the last one {{{
if [ "${pb_current_version}" != "${pb_new_version}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Current version (${pb_current_version}) and new one (${pb_new_version}) seems to be different."
## Create a temp file to monitor
touch -- "${pb_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for PrivateBin (current: ${pb_current_version}): ${pb_new_version}." >> "${pb_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 -- "${pb_new_version_file}"
fi
# }}}
exit 0