Skip to content

Instantly share code, notes, and snippets.

@MurzNN MurzNN/riot-web-update.sh
Last active Mar 31, 2020

Embed
What would you like to do?
riot-web-update.sh - bash script for auto-update Riot.im to latest version from GitHub vector-im/riot-web project releases
#!/bin/bash
###################################################################
# Script for check new version of Riot from.
# https://api.github.com/repos/vector-im/riot-web/releases/latest
# and download new version, if update is avaiable
#
# https://gist.github.com/MurzNN/ee64f98ab2e71b886c41d55594e5dd9e
#
###################################################################
# Directory where Riot files must be placed
DIRECTORY_INSTALL=~/public_html
# Directory for temp files - must be different that install directory!
DIRECTORY_TMP=/tmp
command -v curl >/dev/null 2>&1 || { echo "You need to install "curl" package for this script: sudo apt install curl"; exit 1; }
command -v tar >/dev/null 2>&1 || { echo "You need to install "tar" package for this script: sudo apt install tar"; exit 1; }
command -v jq >/dev/null 2>&1 || { echo "You need to install "jq" package for this script: sudo apt install jq"; exit 1; }
VERSION_INSTALLED=`cat $DIRECTORY_INSTALL/version`
VERSION_LATEST=`curl -s https://api.github.com/repos/vector-im/riot-web/releases/latest | jq -r '.name' | sed s/v//` || { echo "Error checking last Riot version!"; exit 1; }
if ( [[ -z "$VERSION_LATEST" ]] || [ "$VERSION_LATEST" == "null" ] ); then
echo "Error! Received bad version number from https://api.github.com/repos/vector-im/riot-web/releases/latest: $VERSION_LATEST"
exit
fi
if ( [ "$VERSION_INSTALLED" != "$VERSION_LATEST" ] ); then
echo "Riot installed version is $VERSION_INSTALLED, in GitHub releases found fresher version: $VERSION_LATEST - updating..."
DL_URL=`curl -s https://api.github.com/repos/vector-im/riot-web/releases/latest | jq -r '.assets[0].browser_download_url'`
curl -L -o $DIRECTORY_TMP/riot-latest.tar.gz $DL_URL || { echo "Error downloading riot-latest.tar.gz"; exit 1; }
tar -xf $DIRECTORY_TMP/riot-latest.tar.gz -C $DIRECTORY_TMP/
find $DIRECTORY_INSTALL/* -not -name 'config*.json' -delete
rm -f $DIRECTORY_INSTALL/config.sample.json
mv $DIRECTORY_TMP/riot-v$VERSION_LATEST/* $DIRECTORY_INSTALL/
rm -rf $DIRECTORY_TMP/riot-v$VERSION_LATEST
rm $DIRECTORY_TMP/riot-latest.tar.gz
echo "Riot succesfully updated from $VERSION_INSTALLED to $VERSION_LATEST";
else
echo "Installed Riot version $VERSION_INSTALLED, last is $VERSION_LATEST - no update found, exiting.";
fi
@MurzNN

This comment has been minimized.

Copy link
Owner Author

MurzNN commented Mar 27, 2020

Fixed problem when github return null instead of actual version number (happens today)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.