2020-12-07 23:48:40 +01:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
|
|
|
|
# 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=
|
|
|
|
|
2020-12-10 11:58:22 +01:00
|
|
|
function send_message {
|
|
|
|
if [ $# -eq 0 ]
|
|
|
|
then
|
|
|
|
echo "No argument supplied. Please specify the message to send."
|
|
|
|
else
|
|
|
|
curl -sSf -X POST https://api.telegram.org/${key}/sendMessage --data chat_id=${chat_id} --data text="${1}" --output /dev/null
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function download_and_compile_bitwarden {
|
2020-12-07 23:48:40 +01:00
|
|
|
rm --recursive --force /tmp/bitwarden
|
2020-12-10 11:58:22 +01:00
|
|
|
su --login ${username} --command "git clone https://github.com/dani-garcia/bitwarden_rs.git /tmp/bitwarden"
|
|
|
|
su --login ${username} --command "/home/${username}/.cargo/bin/cargo build --quiet --features sqlite --release --manifest-path=/tmp/bitwarden/Cargo.toml"
|
2020-12-07 23:48:40 +01:00
|
|
|
systemctl stop bitwarden.service
|
|
|
|
mv /tmp/bitwarden/target/release/bitwarden_rs /usr/local/bin/bitwarden
|
|
|
|
chown root:bitwarden /usr/local/bin/bitwarden
|
|
|
|
chmod 750 /usr/local/bin/bitwarden
|
|
|
|
restorecon /usr/local/bin/bitwarden
|
|
|
|
systemctl start bitwarden.service
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_if_bitwarden_is_up_to_date {
|
|
|
|
local_release=$(/usr/local/bin/bitwarden --version | awk --field-separator '-' '{print $2}')
|
|
|
|
latest_release=$(git ls-remote https://github.com/dani-garcia/bitwarden_rs.git HEAD | awk '{print substr($1, 1, length($1) - 32)}')
|
2020-12-10 11:58:22 +01:00
|
|
|
if [ ${latest_release} == ${local_release} ]
|
|
|
|
then
|
|
|
|
send_message "[Bitwarden] - Bitwarden RS is up to date (${local_release})"
|
2020-12-07 23:48:40 +01:00
|
|
|
else
|
2020-12-10 11:58:22 +01:00
|
|
|
send_message "[Bitwarden] - Bitwarden RS is not up to date (https://github.com/dani-garcia/bitwarden_rs/commit/${latest_release})"
|
|
|
|
download_and_compile_bitwarden
|
|
|
|
send_message "[Bitwarden] - Bitwarden RS has just been updated."
|
2020-12-07 23:48:40 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
check_if_bitwarden_is_up_to_date
|