forked from huygn/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom-update
executable file
·27 lines (20 loc) · 965 Bytes
/
atom-update
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash
# wget -q https://github.com/atom/atom/releases/latest -O /tmp/latest
# wget -q $(awk -F '[<>]' '/href=".*atom-amd64.deb/ {match($0,"href=\"(.*.deb)\"",a); print "https://github.com/" a[1]} ' /tmp/latest) -O /tmp/atom-amd64.deb
# dpkg -i /tmp/atom-amd64.deb
# Use this with cron:
# 0 9 * * * atom-update > /tmp/atom-update-cron.log 2>&1
TMP_DIR=$(mktemp -d)
TMP_FILE="${TMP_DIR}/atom-amd64.deb"
VER_LATEST=$(curl -sL https://api.github.com/repos/atom/atom/releases/latest | grep tag_name | cut -d '"' -f 4)
LATEST_URL="https://github.com/atom/atom/releases/download/${VER_LATEST}/atom-amd64.deb"
VER_INST=$(dpkg -l atom | tail -n1 | tr -s ' ' | cut -d" " -f 3)
echo "$(date)> [atom] - current: $VER_INST | lastest: $VER_LATEST"
if [ "$VER_LATEST" != "$VER_INST" ]; then
wget -q $LATEST_URL -O $TMP_FILE
VER_DOWN=$(dpkg-deb -f $TMP_FILE Version)
if [ "$VER_DOWN" != "$VER_INST" ]; then
sudo dpkg -i $TMP_FILE
fi
fi
rm -rf "${TMP_DIR}"