scripts/github/check.searx.update

69 lines
2.3 KiB
Plaintext
Raw Normal View History

#!/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}"
2020-07-01 13:20:47 +02:00
temp_searx_current_version=$(cd "${searx_install_dir}" || exit 1 ; grep "\(VERSION_MAJOR\|VERSION_MINOR\|VERSION_BUILD\) =" searx/version.py | cut -d\= -f2 | sed -e 's/^[[:space:]]*//' | paste -sd "." - ; cd - > /dev/null || exit 1)
searx_current_version="v${temp_searx_current_version}"
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}"
2019-08-22 09:26:59 +02:00
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Searx (current: ${searx_current_version}): ${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