From 99062b251c66ec0289d4009373812a6556d4d0b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Tue, 13 Aug 2019 14:42:26 +0200 Subject: [PATCH] Script to check if installed Searx is uptodate --- github/check.searx.update | 67 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 github/check.searx.update diff --git a/github/check.searx.update b/github/check.searx.update new file mode 100755 index 0000000..00f943b --- /dev/null +++ b/github/check.searx.update @@ -0,0 +1,67 @@ +#!/bin/sh +# Purpose {{{ +## Create a temp file (to monitor) if an upgrade is available for Searx +## project on Github. +## It based on the searx'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 Searx directory as first argument, eg. +#00 20 * * * root /opt/repos/ipr.scripts/github/check.searx.update /var/www/searx +### 3. Monitor the temp file : /tmp/.github.searx.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.searx.update -- +Compare current version of an installed Searx and the last available. + +EXAMPLE : + - Compare the current version installed in /var/www/searx.domain.tld + check.searx.update /var/www/searx.domain.tld + +HELP + + exit 1 +fi + +# }}} + +# Vars {{{ +DEBUG=1 + +script_wd=$(dirname "${0}") + +searx_install_dir="${1}" +searx_current_version=$(cd "${searx_install_dir}" || exit 1 ; git describe --match "v[0-9]*\.[0-9]*\.[0-9]*" HEAD 2>/dev/null | awk -F'-' '{ print $1 }' ; cd - > /dev/null || exit 1) + +searx_repo_url="https://github.com/asciimoo/searx" +searx_new_version=$("${script_wd}"/releasetags "${searx_repo_url}" | head -n1) + +searx_new_version_file="/tmp/.github.searx.upgrade" +# }}} + +# Check if the current version is the last one {{{ +if [ "${searx_current_version}" != "${searx_new_version}" ]; then + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test version — Current version (${searx_current_version}) and new one (${searx_new_version}) seems to be different." + + ## Create a temp file to monitor + touch -- "${searx_new_version_file}" + printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Searx : ${searx_new_version}." >> "${searx_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 -- "${searx_new_version_file}" +fi +# }}} + +exit 0