Last active
April 15, 2021 11:35
-
-
Save DisasteR/5877aca7b26f3ef2739f86f9b207aa81 to your computer and use it in GitHub Desktop.
Atom Debian amd64 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 atom-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 atom-update.XXXXXXXXXX 2>/dev/null) || { write_log "Failed to create temp directory"; exit 1; } | |
TMP_LATEST="${TMP_DIR}/latest" | |
TMP_FILE="${TMP_DIR}/atom-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 Atom release" | |
LATEST=$(curl -s -I https://github.com/atom/atom/releases/latest -w "%{redirect_url}" -o /dev/null | awk -F'/' '{ print $NF }') | |
VER_LATEST=$(echo "${LATEST}" | sed 's/v//g') | |
VER_INST=$(dpkg -l atom 2> /dev/null | tail -n1 | tr -s ' ' | cut -d" " -f 3) | |
VER_INST=${VER_INST:-0} | |
write_log "Atom currently installed version is ${VER_INST}" | |
write_log "Atom last downloadable version is ${VER_LATEST}" | |
if dpkg --compare-versions "${VER_INST}" lt "${VER_LATEST}" | |
then | |
write_log "Get: https://github.com/atom/atom/releases/latest atom amd64 ${VER_LATEST}" | |
wget --show-progress --progress=bar:force -q \ | |
"https://github.com/atom/atom/releases/download/${LATEST}/atom-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 "Atom version seen in downloaded package is ${VER_DOWN}" | |
if [ "${VER_DOWN}" == "${VER_LATEST}" ]; then | |
sudo dpkg -i "${TMP_FILE}" | |
write_log "Atom has been updated from ${VER_INST} to ${VER_LATEST}" | |
else | |
write_log "Atom version seen in downloaded package differ from fetched one" | |
clean_up 1 | |
fi | |
else | |
write_log "Atom 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