76 lines
2.2 KiB
Bash
76 lines
2.2 KiB
Bash
#! /usr/bin/env bash
|
|
|
|
# all executed commands are printed to stdout
|
|
set -x
|
|
|
|
# redirect stdout (and stderr to stdout) to a file
|
|
exec 1> /var/log/updater/bitwarden/bitwarden-$(date +%F).log 2>&1
|
|
|
|
# abort on nonzero exitstatus
|
|
set -o errexit
|
|
|
|
# abort on unbound variable
|
|
set -o nounset
|
|
|
|
# don't hide errors within pipes
|
|
set -o pipefail
|
|
|
|
# set your API key here
|
|
key=
|
|
|
|
# set your chat id here
|
|
chat_id=
|
|
|
|
# set your username
|
|
username=
|
|
|
|
function send_message() {
|
|
if [ $# -eq 0 ]
|
|
then
|
|
echo "No argument supplied. Please specify the message to send."
|
|
else
|
|
curl --silent --show-error --fail --request POST https://api.telegram.org/${key}/sendMessage --data chat_id=${chat_id} --data text="${1}" --output /dev/null
|
|
fi
|
|
}
|
|
|
|
function update_bitwarden {
|
|
rm --recursive --force /tmp/bitwarden
|
|
|
|
# clone the latest release
|
|
su --login ${username} --command "git clone https://github.com/dani-garcia/bitwarden_rs.git /tmp/bitwarden"
|
|
|
|
# compile the binary
|
|
su --login ${username} --command "/home/${username}/.cargo/bin/cargo build --quiet --features sqlite --release --manifest-path=/tmp/bitwarden/Cargo.toml"
|
|
systemctl stop bitwarden.service
|
|
|
|
# move the binary to the right place
|
|
mv /tmp/bitwarden/target/release/bitwarden_rs /usr/local/bin/bitwarden
|
|
|
|
# set the correct permissions
|
|
chown root:bitwarden /usr/local/bin/bitwarden
|
|
chmod 750 /usr/local/bin/bitwarden
|
|
/usr/sbin/restorecon /usr/local/bin/bitwarden
|
|
|
|
if systemctl start bitwarden.service
|
|
then
|
|
send_message "[Bitwarden] - Bitwarden RS has just been updated."
|
|
else
|
|
send_message "[Bitwarden] - Bitwarden RS service did not start correctly. Please log in as soon as possible and see what went wrong."
|
|
fi
|
|
}
|
|
|
|
# retrieve local release
|
|
local_release=$(/usr/local/bin/bitwarden --version | awk --field-separator '-' '{print $2}')
|
|
|
|
# retrieve the latest release
|
|
latest_release=$(git ls-remote https://github.com/dani-garcia/bitwarden_rs.git HEAD | awk '{print substr($1, 1, length($1) - 32)}')
|
|
|
|
# compare these two versions
|
|
if [ ${latest_release} == ${local_release} ]
|
|
then
|
|
send_message "[Bitwarden] - Bitwarden RS is up to date."
|
|
else
|
|
send_message "[Bitwarden] - Bitwarden RS is not up to date (https://github.com/dani-garcia/bitwarden_rs/commit/${latest_release})."
|
|
update_bitwarden
|
|
fi
|