Last active
April 15, 2021 11:34
-
-
Save DisasteR/339350abb9c1ca85e840605b5ea5db3e to your computer and use it in GitHub Desktop.
Rambox Debian x64 auto upgrade script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
write_log() { | |
echo "${1}" | |
logger -t rambox-update "${1}" | |
} | |
progressfilt () | |
{ | |
local flag=false c count cr=$'\r' nl=$'\n' | |
while IFS='' read -d '' -rn 1 c | |
do | |
if $flag | |
then | |
printf '%c' "$c" | |
else | |
if [[ $c != $cr && $c != $nl ]] | |
then | |
count=0 | |
else | |
((count++)) | |
if ((count > 1)) | |
then | |
flag=true | |
fi | |
fi | |
fi | |
done | |
} | |
TMP_DIR=$(mktemp -t -d rambox-update.XXXXXXXXXX 2>/dev/null) || { write_log "Failed to create temp directory"; exit 1; } | |
TMP_LATEST="${TMP_DIR}/latest" | |
TMP_FILE="${TMP_DIR}/rambox-amd64.deb" | |
clean_up() { | |
[ -d "${TMP_DIR}" ] && { write_log "Cleaning up temporary files"; rm -rf "${TMP_DIR}"; } | |
exit ${1:-0} | |
} | |
trap 'clean_up 1' SIGHUP SIGINT SIGTERM | |
write_log "Fetching latest Rambox release" | |
LATEST=$(curl -s -I https://github.com/ramboxapp/community-edition/releases/latest -w "%{redirect_url}" -o /dev/null | awk -F'/' '{ print $NF }') | |
VER_LATEST=$(echo "${LATEST}" | sed 's/v//g') | |
VER_INST=$(dpkg -l rambox 2> /dev/null | tail -n1 | tr -s ' ' | cut -d" " -f 3) | |
VER_INST=${VER_INST:-0} | |
write_log "Rambox currently installed version is ${VER_INST}" | |
write_log "Rambox last downloadable version is ${VER_LATEST}" | |
if dpkg --compare-versions "${VER_INST}" lt "${VER_LATEST}" | |
then | |
write_log "Get: https://github.com/ramboxapp/community-edition/releases/latest rambox amd64 ${VER_LATEST}" | |
wget --show-progress --progress=bar:force -q \ | |
https://github.com/ramboxapp/community-edition/releases/download/${LATEST}/Rambox-${LATEST}-linux-amd64.deb \ | |
-O "${TMP_FILE}" || \ | |
{ write_log "Can't fetch atom package"; clean_up 1; } | |
VER_DOWN=$(dpkg-deb -f "${TMP_FILE}" Version) | |
write_log "Rambox version seen in downloaded package is ${VER_DOWN}" | |
if [ "${VER_DOWN%%-*}" == "${VER_LATEST}" ]; then | |
sudo dpkg -i "${TMP_FILE}" | |
write_log "Rambox has been updated from ${VER_INST} to ${VER_DOWN}" | |
else | |
write_log "Rambox version seen in downloaded package differ from fetched one" | |
clean_up 1 | |
fi | |
else | |
write_log "Rambox version ${VER_INST} is the latest version, no update required" | |
fi | |
clean_up |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment