From c47793c6c552aba16c541feb6b40e549dd287815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Mon, 12 Aug 2019 15:24:36 +0200 Subject: [PATCH] Script to check if installed Wallabag is uptodate --- github/check.wallabag.update | 67 ++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 github/check.wallabag.update diff --git a/github/check.wallabag.update b/github/check.wallabag.update new file mode 100755 index 0000000..7857b09 --- /dev/null +++ b/github/check.wallabag.update @@ -0,0 +1,67 @@ +#!/bin/sh +# Purpose {{{ +## Create a temp file (to monitor) if an upgrade is available for Wallabag +## project on Github. +## It based on the wallabag's root directory to get the current version and +## supposed to be install from source (github). +## 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 Wallabag directory as first argument, eg. +#00 20 * * * root /opt/repos/ipr.scripts/github/check.wallabag.update /var/www/wallabag +### 3. Monitor the temp file : /tmp/.github.wallabag.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.wallabag.update -- +Compare current version of an installed Wallabag and the last available. + +EXAMPLE : + - Compare the current version installed in /var/www/bag.domain.tld + check.wallabag.update /var/www/bag.domain.tld + +HELP + + exit 1 +# }}} + +fi + +# Vars {{{ +DEBUG=1 + +script_wd=$(dirname "${0}") + +wb_install_dir="${1}" +wb_current_version=$(cd "${wb_install_dir}" || exit 1 ; git status | head -n1 | cut -d" " -f4 ; cd - > /dev/null || exit 1) + +wb_repo_url="https://github.com/wallabag/wallabag" +wb_new_version=$("${script_wd}"/releasetags "${wb_repo_url}" | head -n1) + +wb_new_version_file="/tmp/.github.wallabag.upgrade" +# }}} + +# Check if the current version is the last one {{{ +if [ "${wb_current_version}" != "${wb_new_version}" ]; then + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test version — Current version (${wb_current_version}) and new one (${wb_new_version}) seems to be different." + + ## Create a temp file to monitor + touch -- "${wb_new_version_file}" + printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Wallabag : ${wb_new_version}." >> "${wb_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 -- "${wb_new_version_file}" +fi +# }}} + +exit 0