75 lines
2.3 KiB
Bash
75 lines
2.3 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/vaultwarden-updater/vaultwarden-updater-"$(date +%F)".log 2>&1
|
|
|
|
# Abort on nonzero exit status
|
|
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
|
|
curl --silent --show-error --fail --request POST "https://api.telegram.org/$key/sendMessage" --data chat_id="$chat_id" --data text="$1" --output /dev/null
|
|
else
|
|
echo "No argument supplied, please specify the message to send"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
function update_vaultwarden {
|
|
rm --recursive --force /tmp/vaultwarden
|
|
|
|
# Clone the latest release
|
|
su --login "$username" --command "git clone https://github.com/dani-garcia/vaultwarden.git /tmp/vaultwarden"
|
|
|
|
# Compile the binary
|
|
su --login "$username" --command "/home/$username/.cargo/bin/cargo build --quiet --features sqlite --release --manifest-path=/tmp/vaultwarden/Cargo.toml"
|
|
systemctl stop vaultwarden.service
|
|
|
|
# Move the binary to the right place
|
|
mv /tmp/vaultwarden/target/release/vaultwarden /usr/local/bin/vaultwarden
|
|
|
|
# Set the correct permissions
|
|
chown root:vaultwarden /usr/local/bin/vaultwarden
|
|
chmod 750 /usr/local/bin/vaultwarden
|
|
/sbin/restorecon -v /usr/local/bin/vaultwarden
|
|
|
|
if ! systemctl start vaultwarden.service; then
|
|
send_message "[Vaultwarden] - Vaultwarden service did not start correctly. Please log in as soon as possible and see what went wrong"
|
|
exit 1
|
|
fi
|
|
|
|
send_message "[Vaultwarden] - Vaultwarden has just been updated"
|
|
}
|
|
|
|
# Retrieve local release
|
|
local_release=$(/usr/local/bin/vaultwarden --version | awk --field-separator '-' '{print $2}')
|
|
|
|
# Retrieve the latest release
|
|
latest_release=$(git ls-remote https://github.com/dani-garcia/vaultwarden.git HEAD | awk '{print substr($1, 1, length($1) - 32)}')
|
|
|
|
# Compare these two versions
|
|
if ! [ "$latest_release" == "$local_release" ]; then
|
|
send_message "[Vaultwarden] - Vaultwarden is not up to date (https://github.com/dani-garcia/vaultwarden/commit/$latest_release)"
|
|
update_vaultwarden
|
|
fi
|
|
|
|
send_message "[Vaultwarden] - Vaultwarden is up to date"
|