diff --git a/bw-updater b/bw-updater index b162ffa..f05888f 100644 --- a/bw-updater +++ b/bw-updater @@ -18,10 +18,19 @@ chat_id= # set your username username= -download_and_compile_bitwarden () { +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 { 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" + 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 @@ -33,12 +42,13 @@ download_and_compile_bitwarden () { 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 + if [ ${latest_release} == ${local_release} ] + then + send_message "[Bitwarden] - Bitwarden RS is up to date (${local_release})" 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 + 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 }