Script to verify Bitwarden version
This commit is contained in:
parent
a3c56bcaf7
commit
5d3d047223
|
@ -0,0 +1,79 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Purpose {{{
|
||||||
|
## Create a temp file (to monitor) if an upgrade is available for Bitwarden_rs
|
||||||
|
## project on Github.
|
||||||
|
## It based on /opt/bitwarden_rs/bitwarden_rs 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_bitwarden_rs_update
|
||||||
|
### 2-1 Create a cron job with a specific path for bitwarden_rs bin, eg.
|
||||||
|
#00 20 * * * root /opt/repos/ipr.scripts/github/check_bitwarden_rs_update /srv/bin/bitwarden_rs
|
||||||
|
### 3. Monitor the temp file : /tmp/.github.bitwarden_rs.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.bitwarden_rs.update --
|
||||||
|
Compare current version of an installed Bitwarden_rs and the last available.
|
||||||
|
|
||||||
|
EXAMPLE :
|
||||||
|
- Compare the current version of Bitwarden_rs with bin available in
|
||||||
|
/opt/bitwarden_rs/bitwarden_rs
|
||||||
|
check.bitwarden_rs.update
|
||||||
|
|
||||||
|
- Compare the current version of Bitwarden_rs at a specific place
|
||||||
|
check.bitwarden_rs.update /srv/bin/bitwarden_rs
|
||||||
|
|
||||||
|
HELP
|
||||||
|
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
fi
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
# Vars {{{
|
||||||
|
DEBUG=1
|
||||||
|
|
||||||
|
script_wd=$(dirname "${0}")
|
||||||
|
|
||||||
|
if [ $# -eq 1 ] ## If an argument was gave
|
||||||
|
then
|
||||||
|
bitwarden_rs_bin_path="${1}"
|
||||||
|
else
|
||||||
|
bitwarden_rs_bin_path="/opt/bitwarden_rs/bitwarden_rs"
|
||||||
|
fi
|
||||||
|
|
||||||
|
bitwarden_rs_current_version=$("${bitwarden_rs_bin_path}" --version | sed 's/bitwarden_rs \(\([0-9]\{1,3\}\.\)\{2\}\([0-9]\{1,3\}\)\).*/\1/')
|
||||||
|
|
||||||
|
bitwarden_rs_repo_url="https://github.com/dani-garcia/bitwarden_rs"
|
||||||
|
bitwarden_rs_new_version=$("${script_wd}"/releasetags "${bitwarden_rs_repo_url}" | grep -vE -- '(dev|rc)' | head -n1)
|
||||||
|
|
||||||
|
bitwarden_rs_new_version_file="/tmp/.github.bitwarden_rs.upgrade"
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
# Check if the current version is the last one {{{
|
||||||
|
if [ "${bitwarden_rs_current_version}" != "${bitwarden_rs_new_version}" ]; then
|
||||||
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test version — Current version (${bitwarden_rs_current_version}) and new one (${bitwarden_rs_new_version}) seems to be different."
|
||||||
|
|
||||||
|
## Create a temp file to monitor
|
||||||
|
touch -- "${bitwarden_rs_new_version_file}"
|
||||||
|
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Bitwarden_rs (current : ${bitwarden_rs_current_version}) : ${bitwarden_rs_new_version}." >> "${bitwarden_rs_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 -- "${bitwarden_rs_new_version_file}"
|
||||||
|
fi
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
exit 0
|
Loading…
Reference in New Issue