From 088523f955e70c0e4d3b23adf7381ea8fba15ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Mon, 26 Aug 2019 14:59:05 +0200 Subject: [PATCH] Script to monitor new version of PrivateBin project --- github/check.privatebin.update | 67 ++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 github/check.privatebin.update diff --git a/github/check.privatebin.update b/github/check.privatebin.update new file mode 100755 index 0000000..b50dd08 --- /dev/null +++ b/github/check.privatebin.update @@ -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