46 lines
2.0 KiB
Bash
46 lines
2.0 KiB
Bash
#! /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=
|
|
|
|
download_and_compile_bitwarden () {
|
|
rm --recursive --force /tmp/bitwarden
|
|
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"
|
|
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)}')
|
|
if [ "${latest_release}" == "${local_release}" ]; then
|
|
curl -sSf -X POST https://api.telegram.org/"${key}"/sendMessage --data chat_id="${chat_id}" --data text="[Bitwarden] - Bitwarden RS is up to date (${local_release})" --output /dev/null
|
|
else
|
|
curl -sSf -X POST https://api.telegram.org/"${key}"/sendMessage --data chat_id="${chat_id}" --data text="[Bitwarden] - Bitwarden RS is not up to date (https://github.com/dani-garcia/bitwarden_rs/commit/${latest_release})" --output /dev/null
|
|
download_and_compile_bitwarden "${latest_release}"
|
|
curl -sSf -X POST https://api.telegram.org/"${key}"/sendMessage --data chat_id="${chat_id}" --data text="[Bitwarden] - Bitwarden RS has just been updated." --output /dev/null
|
|
fi
|
|
}
|
|
|
|
check_if_bitwarden_is_up_to_date
|