Skip to content

Instantly share code, notes, and snippets.

@not-a-feature
Last active May 25, 2023 18:05
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 not-a-feature/7621a9a4b0c76d8bbd9c41ffa52898a5 to your computer and use it in GitHub Desktop.
Save not-a-feature/7621a9a4b0c76d8bbd9c41ffa52898a5 to your computer and use it in GitHub Desktop.
Download and update the newest (Nextcloud) AppImage.
#!/bin/bash
APPNAME="Nextcloud"
# Define the directory where the AppImage is stored
APP_DIR="/home/user/dir"
# Fetch the latest release data from the Github API
# See: https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#get-the-latest-release
# Structure: https://api.github.com/repos/OWNER/REPO/releases/latest
API_URL="https://api.github.com/repos/nextcloud-releases/desktop/releases/latest"
#----------------------------------------------------------------------------------
RELEASE_DATA=$(curl --silent $API_URL)
# Use jq to parse the JSON
APPIMAGE_URL=$(echo $RELEASE_DATA | jq -r ".assets[] | select(.name | test(\"AppImage\")) | .browser_download_url")
if [[ -z "$APPIMAGE_URL" ]]; then
echo "No release found"
exit
fi
# Extract the filename
FILENAME=$(basename $APPIMAGE_URL)
APPIMAGE="$APP_DIR/$APPNAME.AppImage"
# Check if the Nextcloud client is currently running
if pgrep $APPNAME; then
# If it is, kill it
pkill $APPNAME
# Give it a moment to fully terminate
sleep 2
fi
# If an old AppImage exists, delete it
if [ -f "$APPIMAGE" ]; then
rm $APPIMAGE
fi
echo "Downloading $FILENAME"
# Download the new AppImage
wget -q --show-progress $APPIMAGE_URL -O $APPIMAGE
# Make the new AppImage executable
chmod +x $APPIMAGE
# Run the new AppImage
$APPIMAGE &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment