scripts/github/check.shaarli.update

69 lines
2.4 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for Shaarli
## project on Github.
## It based on shaarli's binary available in $PATH or give as first argument.
## How-to use {{{
### 1. Needs releasetags script, in the same directory
### cf. https://git.ipr.univ-rennes.fr/cellinfo/scripts/src/master/github/releasetags
# wget https://git.ipr.univ-rennes.fr/cellinfo/scripts/raw/master/github/releasetags
### 2. Create a cron job, eg.
#00 20 * * * root /opt/repos/ipr.scripts/github/check_shaarli_update
### 2-1 Create a cron job with a specific path for Shaarli bin, eg.
#00 20 * * * root /opt/repos/ipr.scripts/github/check_shaarli_update /var/www/shaarli.domain.tld
### 3. Monitor the temp file: /tmp/.github.shaarli.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.shaarli.update --
Compare current version of an installed Shaarli and the last available.
EXAMPLE:
- Compare the current version installed in /var/www/shaarli.domain.tld
check.shaarli.update /var/www/shaarli.domain.tld
HELP
exit 1
fi
# }}}
# Vars {{{
DEBUG=1
script_wd=$(dirname "${0}")
shaarli_install_dir="${1}"
shaarli_current_version=$(cd "${shaarli_install_dir}" || exit 1 ; grep . -m1 shaarli_version.php | cut -d" " -f3 ; cd - > /dev/null || exit 1)
shaarli_repo_url="https://github.com/shaarli/Shaarli"
shaarli_new_version=$("${script_wd}"/releasetags "${shaarli_repo_url}" | grep -vE -- '(beta)' | head -n1 | sed 's/v//')
shaarli_new_version_file="/tmp/.github.shaarli.upgrade"
# }}}
# Check if the current version is the last one {{{
if [ "${shaarli_current_version}" != "${shaarli_new_version}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Current version (${shaarli_current_version}) and new one (${shaarli_new_version}) seems to be different."
## Create a temp file to monitor
touch -- "${shaarli_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Shaarli (current: ${shaarli_current_version}): ${shaarli_new_version}." >> "${shaarli_new_version_file}"
else
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — The current (${shaarli_current_version}) version is up-to-date."
rm -f -- "${shaarli_new_version_file}"
fi
# }}}
exit 0