Use long parameter notation for curl and remove useless function
This commit is contained in:
parent
1ca817968b
commit
b31551267f
54
bw-updater
54
bw-updater
@ -23,33 +23,47 @@ function send_message {
|
||||
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
|
||||
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 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
|
||||
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
|
||||
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} ]
|
||||
if systemctl start bitwarden.service
|
||||
then
|
||||
send_message "[Bitwarden] - Bitwarden RS is up to date (${local_release})"
|
||||
else
|
||||
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."
|
||||
fi
|
||||
else
|
||||
send_message "[Bitwarden] - Bitwarden RS service did not start correctly. Please log in as soon as possible and see what went wrong."
|
||||
fi
|
||||
}
|
||||
|
||||
check_if_bitwarden_is_up_to_date
|
||||
# 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})."
|
||||
download_and_compile_bitwarden
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user