scripts/github/check.vaultwarden.update

80 lines
2.7 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for Vaultwarden
## (previously Bitwarden_rs) project on Github.
## It based on /opt/vaultwarden/vaultwarden binary available or the one give
## as first argument.
## 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, eg.
#00 20 * * * root /opt/repos/ipr.scripts/github/check_vaultwarden_update
### 2-1 Create a cron job with a specific path for vaultwarden bin, eg.
#00 20 * * * root /opt/repos/ipr.scripts/github/check_vaultwarden_update /srv/bin/vaultwarden
### 3. Monitor the temp file: /tmp/.github.vaultwarden.upgrade
# Or enable MAILTO in cronjob and edit the script to print a message.
# Or send a mail.
# …
## }}}
# }}}
# Expect max 1 argument {{{
if [ $# -gt 1 ]
then
cat << HELP
check.vaultwarden.update --
Compare current version of an installed Vaultwarden and the last available.
EXAMPLE:
- Compare the current version of Vaultwarden with bin available in
/opt/vaultwarden/vaultwarden
check.vaultwarden.update
- Compare the current version of Vaultwarden at a specific place
check.vaultwarden.update /srv/bin/vaultwarden
HELP
exit 1
fi
# }}}
# Vars {{{
DEBUG=1
script_wd=$(dirname "${0}")
if [ $# -eq 1 ] ## If an argument was gave
then
vaultwarden_bin_path="${1}"
else
vaultwarden_bin_path="/opt/vaultwarden/vaultwarden"
fi
vaultwarden_current_version=$("${vaultwarden_bin_path}" --version | sed 's/vaultwarden \(\([0-9]\{1,3\}\.\)\{2\}\([0-9]\{1,3\}\)\).*/\1/')
vaultwarden_repo_url="https://github.com/dani-garcia/vaultwarden"
vaultwarden_new_version=$("${script_wd}"/releasetags "${vaultwarden_repo_url}" | grep -vE -- '(dev|rc)' | head -n1)
vaultwarden_new_version_file="/tmp/.github.vaultwarden.upgrade"
# }}}
# Check if the current version is the last one {{{
if [ "${vaultwarden_current_version}" != "${vaultwarden_new_version}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Current version (${vaultwarden_current_version}) and new one (${vaultwarden_new_version}) seems to be different."
## Create a temp file to monitor
touch -- "${vaultwarden_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Vaultwarden (current: ${vaultwarden_current_version}): ${vaultwarden_new_version}." >> "${vaultwarden_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 -- "${vaultwarden_new_version_file}"
fi
# }}}
exit 0