Skip to content

Instantly share code, notes, and snippets.

@hutattedonmyarm
Last active December 6, 2021 07:06
Show Gist options
  • Save hutattedonmyarm/ff73c12cb5ae5b546d4856b06b6ae484 to your computer and use it in GitHub Desktop.
Save hutattedonmyarm/ff73c12cb5ae5b546d4856b06b6ae484 to your computer and use it in GitHub Desktop.
Updating RSS-Bridge
#!/bin/bash
# Updates rss-bridge to the latest Github release
# Prerequsitions: The dependencies for rss-bridge need to be installed
# This script uses jq, but falls bacl to using grep if jq cannot be found
RSS_BRIDGE_FOLDER="/var/www/html/rss-bridge/" # Edit this to point to the folder you want rss-bridge installed to
REPO="RSS-Bridge/rss-bridge"
GH_API_URL="https://api.github.com/repos/${REPO}/releases/latest"
VERSION_FILE="${RSS_BRIDGE_FOLDER}version.txt"
CACHE_FOLDER="${RSS_BRIDGE_FOLDER}cache"
DOWNLOAD_TO=$(mktemp /tmp/rssbridge.XXXXXXXXX)
# Check if jq exists
jq --version &> /dev/null
JQ_STATUS=$?
if [ $JQ_STATUS -ne 0 ] ; then
echo 'jq is not installed. Using alternative commands'
fi
# Fetch latest version name
if [ $JQ_STATUS -ne 0 ] ; then
CURRENT=$(curl --silent $GH_API_URL | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
else
CURRENT=$(curl --silent $GH_API_URL | jq -r ".tag_name")
fi
# Check which version is currently installed
INSTALLED="0"
if test -f "$VERSION_FILE"; then
INSTALLED=$(cat $VERSION_FILE)
else
echo "Version file ${VERSION_FILE} does not exist, forcing update"
fi
if [ ! -d "$RSS_BRIDGE_FOLDER" ]; then
echo "RSS bridge folder ${RSS_BRIDGE_FOLDER} does not exist, creating"
sudo mkdir $RSS_BRIDGE_FOLDER;
fi
if [[ "$CURRENT" > "$INSTALLED" ]]; then
echo "Updating installed version ${INSTALLED} to ${CURRENT}."
# Get tarball URL for latest release & download release
if [ $JQ_STATUS -ne 0 ] ; then
wget -O $DOWNLOAD_TO --no-verbose --show-progress $(curl --silent $GH_API_URL | grep '"tarball_url":' | sed -E 's/.*"([^"]+)".*/\1/')
else
wget -O $DOWNLOAD_TO --no-verbose --show-progress $(curl --silent $GH_API_URL | jq -r ".tarball_url")
fi
# Extract to target folder, overwrite existing files
# Also strips the first level, because rss-bridge releases come in a subfolder within the tarball
sudo tar -xzf $DOWNLOAD_TO -C $RSS_BRIDGE_FOLDER --strip 1 --overwrite
# Write permission on cache folder
sudo chown -R www-data $CACHE_FOLDER
# Save updated version
echo "${CURRENT}" | sudo tee $VERSION_FILE > /dev/null
# Clean up
rm $DOWNLOAD_TO
else
echo "Installed version ${INSTALLED} is up to date."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment