Last active
September 29, 2020 20:38
-
-
Save researcx/f6f78409bb87630dc7dfb253d9642dd6 to your computer and use it in GitHub Desktop.
element-web auto-updater script
This file contains 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
# element-web auto-updater script by unendingPattern ( unendingpattern.github.io ) | |
# fetches the latest element (matrix client) release for self-hosting | |
# requirements: curl, jq, tar | |
# cron: | |
# @hourly /bin/sh /path/to/get-latest-element.sh | |
# OR | |
# 0 * * * * /bin/sh /path/to/get-latest-element.sh | |
# functions | |
# credit: maboloshi ( https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c#gistcomment-2839301 ) | |
get_latest_release() { | |
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api | |
grep '"tag_name":' | # Get tag line | |
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value | |
} | |
# credit: yairchu ( https://stackoverflow.com/a/37939589 ) | |
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; } | |
# code | |
USR="nginx" | |
GRP="nginx" | |
DIR="/var/www/element-web" | |
NEW=$(get_latest_release vector-im/element-web) | |
DNL=$(curl -s https://api.github.com/repos/vector-im/element-web/releases/latest | jq --raw-output '.assets[0] | .browser_download_url') | |
FIL="$(basename -- $DNL)" | |
if [ -d "$DIR" ]; then | |
OLD=$(cat $DIR/version) | |
else | |
OLD="N/A" | |
mkdir $DIR | |
fi | |
echo "Latest: $NEW | Installed: $OLD" | |
echo "Install path: $DIR" | |
echo "Download link: $DNL" | |
echo "Filename: $FIL" | |
if [ $(version $NEW) -ge $(version $OLD) ]; then | |
curl -LJO $DNL | |
tar -C $DIR -xvf $FIL --strip 1 | |
chown -R $USR:$GRP $DIR | |
rm $FIL | |
echo "Finished!" | |
else | |
echo "Already up to date." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment