#!/bin/bash # ge-tool # # Copyright 2021 crt0mega # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. # # # Configuration declare CONFIG_DIR="$HOME/.config/ge-tool" declare CONFIG_FILE="$CONFIG_DIR/config" declare LATEST_FILE="$CONFIG_DIR/latest" declare API_CACHE=$(mktemp) if [ ! -d "$CONFIG_DIR" ]; then # Create config dir if it doesn't exist mkdir -p $CONFIG_DIR fi if [ ! -f "$CONFIG_FILE" ]; then # Default values declare COMPAT_DIR="$HOME/.steam/root/compatibilitytools.d" declare REL_URL="https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases" declare GITHUB_TOKEN="" else # Read config instead source $CONFIG_FILE > /dev/null fi if [ ! $GITHUB_TOKEN=="" ]; then # Have token, give token declare CURL_ARGS="-H 'Authorization: token $GITHUB_TOKEN'" else # Have no token, give no token declare CURL_ARGS="" fi # Checking requirements declare JQ=$(which jq) declare CURL=$(which curl) declare ZEN=$(which zenity) declare NTFY=$(which notify-send) declare ERR="0" if [ "$JQ" == "" ]; then echo "Error: jq not installed." ERR="1" fi if [ "$CURL" == "" ]; then echo "Error: curl not installed." ERR="2" fi if [ "$ZEN" == "" ]; then echo "Error: zenity not installed." ERR="3" fi if [ "$NTFY" == "" ]; then echo "Error: libnotify-bin not installed." ERR="4" fi if [ ! "$ERR" == "0" ]; then exit; fi # Caching latest release $CURL $CURL_ARGS -sL $REL_URL/latest > $API_CACHE # Getting tag-name of latest git release declare LATEST_REMOTE_REL=$($JQ -r '.tag_name' < $API_CACHE) # Getting tag-name of latest local copy if [ -f "$LATEST_FILE" ]; then declare LATEST_LOCAL_REL=$(<$LATEST_FILE) else declare LATEST_LOCAL_REL="null" fi # Compare with latest local release if [ "$LATEST_LOCAL_REL" == "$LATEST_REMOTE_REL" ]; then $ZEN --info --no-wrap \ --text="Your local copy of proton-ge-custom is up to date!\nLatest git release: $LATEST_REMOTE_REL" exit else if ! $ZEN --question --no-wrap \ --text="A newer release of proton-ge-custom is available!\nLatest local release: $LATEST_LOCAL_REL\n\ Latest git release: $LATEST_REMOTE_REL\n\ Do you want to download it?"; then exit fi fi # Get download URLs if local release is outdated # Download now, verify later :D # declare DOWNLOAD_SHA512_URL=$($JQ -r '.assets[0].browser_download_url' < $API_CACHE) declare DOWNLOAD_TARBALL_URL=$($JQ -r '.assets[1].browser_download_url' < $API_CACHE) declare DOWNLOAD_TARBALL_FILE=$($JQ -r '.assets[1].name' < $API_CACHE) declare DOWNLOAD_DIR=$(mktemp -d) $NTFY "Downloading $DOWNLOAD_TARBALL_FILE" $CURL $DOWNLOAD_TARBALL_URL -o $DOWNLOAD_DIR/$DOWNLOAD_TARBALL_FILE -sL $NTFY "Download completed, extracting ..." # Extracting downloaded Proton release if [ ! -d $COMPAT_DIR ]; then mkdir -p $COMPAT_DIR; fi tar xf $DOWNLOAD_DIR/$DOWNLOAD_TARBALL_FILE -C $COMPAT_DIR # Setting info for latest release echo "$LATEST_REMOTE_REL" > $LATEST_FILE # Cleaning up rm -r $DOWNLOAD_DIR rm $API_CACHE $NTFY "Installation complete."