Skip to content

Instantly share code, notes, and snippets.

@tulir
Last active May 12, 2020 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tulir/a09df0367e6efe08cacc0e2a5463b920 to your computer and use it in GitHub Desktop.
Save tulir/a09df0367e6efe08cacc0e2a5463b920 to your computer and use it in GitHub Desktop.
Riot updater
#!/bin/bash
cd /var/www
old_version="v$(cat riot/version)"
version="latest"
if [[ ! -z "$1" ]]; then
version="tags/$1"
fi
echo "Fetching latest release info from GitHub"
version_info=$(curl -s "https://api.github.com/repos/vector-im/riot-web/releases/$version")
new_version=$(echo "$version_info" | jq -r '.name')
URL=$(echo "$version_info" | jq -r '.assets[0].browser_download_url')
if [[ "$new_version" == "$old_version" ]]; then
echo "No updates found"
exit
fi
# Remove previous backup riot
rm -rf riot.bak
# Create temp directory for new riot
mkdir riot.new
cd riot.new
echo "Downloading Riot $new_version"
curl -L "$URL" -o riot-tmp.tar.gz
echo "Unpacking archive"
tar -xzf riot-tmp.tar.gz --strip-components=1
rm -f riot-tmp.tar.gz
echo "Replacing files"
cd ..
cp -f riot/config.json riot.new/config.json
# Back up old version and activate new version
mv riot riot.bak
mv riot.new riot
echo "Updated to Riot from $old_version to $new_version"

Dependencies: bash, rm, mv, cp, cat, tar, curl, jq

To update riot to the latest version, simply run the script. Optionally pass a riot-web tag to download a specific release (useful for release candidates)

The first cd in the script is where it runs. Riot is installed to path/riot (so /var/www/riot by default). The script also uses riot.bak and riot.new directories and downloads the archive to riot-tmp.tar.gz.

Support/bug reports/feature requests/etc: #maunium:maunium.net

Copyright (c) 2019-2020 Tulir Asokan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment