Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
element-web auto-updater script
# 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