Update NonSteamLaunchers.sh

This commit is contained in:
Roy 2025-01-05 11:04:31 -08:00 committed by GitHub
parent 53a803b447
commit 31ec5936a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2456,8 +2456,6 @@ show_message "Waiting to detect plugin..."
sleep 20 sleep 20
# Function to switch to Game Mode # Function to switch to Game Mode
switch_to_game_mode() { switch_to_game_mode() {
echo "Switching to Game Mode..." echo "Switching to Game Mode..."
@ -2479,148 +2477,113 @@ REPO_URL="https://github.com/moraroy/NonSteamLaunchersDecky/archive/refs/heads/m
# Set the local directory path # Set the local directory path
LOCAL_DIR="${logged_in_home}/homebrew/plugins/NonSteamLaunchers" LOCAL_DIR="${logged_in_home}/homebrew/plugins/NonSteamLaunchers"
# Check if the Decky Loader and NSL Plugin exist # Function to check if a directory exists and contains files
DECKY_LOADER_EXISTS=false directory_exists_and_not_empty() {
NSL_PLUGIN_EXISTS=false [ -d "$1" ] && [ -n "$(ls -A "$1")" ]
if [ -d "${logged_in_home}/homebrew/plugins" ]; then
DECKY_LOADER_EXISTS=true
fi
if [ -d "$LOCAL_DIR" ]; then
if [ -z "$(ls -A $LOCAL_DIR)" ]; then
NSL_PLUGIN_EXISTS=false
else
NSL_PLUGIN_EXISTS=true
fi
fi
# Set version check variables
GITHUB_URL="https://raw.githubusercontent.com/moraroy/NonSteamLaunchersDecky/refs/heads/main/package.json"
# Function to fetch GitHub package.json version
fetch_github_version() {
response=$(curl -s "$GITHUB_URL")
github_version=$(echo "$response" | jq -r '.version')
if [ "$github_version" != "null" ]; then
echo "$github_version"
else
echo "Error: Could not fetch or parse GitHub version"
return 1
fi
} }
# Function to fetch the local package.json version # Function to fetch version from GitHub
fetch_github_version() {
response=$(curl -s "https://raw.githubusercontent.com/moraroy/NonSteamLaunchersDecky/refs/heads/main/package.json")
echo "$response" | jq -r '.version'
}
# Function to fetch local version from package.json
fetch_local_version() { fetch_local_version() {
if [ -f "$LOCAL_DIR/package.json" ]; then if [ -f "$LOCAL_DIR/package.json" ]; then
local_version=$(jq -r '.version' "$LOCAL_DIR/package.json") jq -r '.version' "$LOCAL_DIR/package.json"
if [ "$local_version" != "null" ]; then
echo "$local_version"
else
echo "Error: Failed to parse local version"
return 1
fi
else else
echo "Error: Local package.json not found!" echo "null"
return 1
fi fi
} }
# Function to compare versions # Function to compare versions
compare_versions() { compare_versions() {
# Fetch local and GitHub versions local local_version=$(fetch_local_version)
local_version=$(fetch_local_version) local github_version=$(fetch_github_version)
github_version=$(fetch_github_version)
if [ "$local_version" == "Error:" ] || [ "$github_version" == "Error:" ]; then if [ "$local_version" == "null" ]; then
echo "Error: Could not fetch version information" echo "Local version not found, need installation."
return 1 return 1 # Local version is missing, so installation is needed
fi fi
echo "Local Version: $local_version, GitHub Version: $github_version" echo "Local Version: $local_version, GitHub Version: $github_version"
if [ "$local_version" == "$github_version" ]; then if [ "$local_version" == "$github_version" ]; then
echo "Status: Up-to-date" echo "Plugin is up-to-date."
return 0 return 0 # No update needed
else else
echo "Status: Update available" echo "Update needed."
return 1 return 1 # Versions don't match, so update is needed
fi fi
} }
set +x # Main logic
# Show initial message show_message "Detecting environment..."
show_message "Detected environment..."
if $DECKY_LOADER_EXISTS; then # Check if Decky Loader exists
# Compare versions before prompting for password if ! directory_exists_and_not_empty "${logged_in_home}/homebrew/plugins"; then
compare_versions zenity --error --text=" This is not an error. Decky Loader was not detected. Please install it from their website and re-run this script to access the plugin version of NSL."
if [ $? -eq 0 ]; then
echo "No update needed. The plugin is already up-to-date."
show_message "No update needed. The plugin is already up-to-date."
else
# If version update is required, ask for the password
while true; do
USER_INPUT=$(zenity --forms --title="Authentication Required" --text="Decky Loader detected! $(if $NSL_PLUGIN_EXISTS; then echo 'NSL Plugin also detected and will be updated to the latest version 🚀.'; else echo 'But no NSL plugin :(. Would you like to inject it and go to Game Mode?'; fi) Please enter your sudo password to proceed:" --separator="|" --add-password="Password")
USER_PASSWORD=$(echo $USER_INPUT | cut -d'|' -f1)
if [ -z "$USER_PASSWORD" ]; then
zenity --error --text="No password entered. Exiting." --timeout 5
exit 1
fi
echo "$USER_PASSWORD" | sudo -S echo "Password accepted" 2>/dev/null
if [ $? -eq 0 ]; then
break
else
zenity --error --text="Incorrect password. Please try again."
fi
done
fi
else
zenity --error --text="Decky Loader not detected. Please download and install it from their website first and re-run this script to get the NSL Plugin."
rm -rf "$download_dir"
exit 1 exit 1
fi fi
# If update is needed, continue with the update process # Check if the NSL Plugin exists
if [ $? -eq 1 ]; then if directory_exists_and_not_empty "$LOCAL_DIR"; then
# If NSL Plugin exists, delete and update NSL_PLUGIN_EXISTS=true
else
NSL_PLUGIN_EXISTS=false
fi
set +x
# Compare versions and update if necessary
if compare_versions; then
echo "No update needed. Plugin is already up-to-date."
show_message "Plugin is up-to-date."
else
echo "Updating plugin..."
while true; do
USER_INPUT=$(zenity --forms --title="Authentication Required" --text="NSL Plugin requires an update or needs installation! Please enter your sudo password to proceed:" --separator="|" --add-password="Password")
USER_PASSWORD=$(echo $USER_INPUT | cut -d'|' -f1)
if [ -z "$USER_PASSWORD" ]; then
zenity --error --text="No password entered. Exiting." --timeout 5
exit 1
fi
echo "$USER_PASSWORD" | sudo -S echo "Password accepted" 2>/dev/null
if [ $? -eq 0 ]; then
break
else
zenity --error --text="Incorrect password. Please try again."
fi
done
# Remove existing plugin if it exists
if $NSL_PLUGIN_EXISTS; then if $NSL_PLUGIN_EXISTS; then
show_message "NSL Plugin detected. Deleting and updating..." show_message "Removing existing plugin..."
echo "Plugin directory exists. Removing..."
echo "$USER_PASSWORD" | sudo -S rm -rf "$LOCAL_DIR" echo "$USER_PASSWORD" | sudo -S rm -rf "$LOCAL_DIR"
fi fi
# Install or update plugin
sudo systemctl stop plugin_loader.service sudo systemctl stop plugin_loader.service
show_message "Creating base directory and setting permissions..." # Create directory and set permissions
echo "$USER_PASSWORD" | sudo -S mkdir -p "$LOCAL_DIR" echo "$USER_PASSWORD" | sudo -S mkdir -p "$LOCAL_DIR"
echo "$USER_PASSWORD" | sudo -S chmod -R u+rw "$LOCAL_DIR" echo "$USER_PASSWORD" | sudo -S chmod -R u+rw "$LOCAL_DIR"
echo "$USER_PASSWORD" | sudo -S chown -R $USER:$USER "$LOCAL_DIR" echo "$USER_PASSWORD" | sudo -S chown -R $USER:$USER "$LOCAL_DIR"
echo "Downloading and extracting the repository..." # Download and extract repository
curl -L "$REPO_URL" -o /tmp/NonSteamLaunchersDecky.zip curl -L "$REPO_URL" -o /tmp/NonSteamLaunchersDecky.zip
echo "$USER_PASSWORD" | sudo -S unzip -o /tmp/NonSteamLaunchersDecky.zip -d /tmp/ echo "$USER_PASSWORD" | sudo -S unzip -o /tmp/NonSteamLaunchersDecky.zip -d /tmp/
echo "$USER_PASSWORD" | sudo -S cp -r /tmp/NonSteamLaunchersDecky-main/* "$LOCAL_DIR" echo "$USER_PASSWORD" | sudo -S cp -r /tmp/NonSteamLaunchersDecky-main/* "$LOCAL_DIR"
echo "$USER_PASSWORD" | sudo -S rm -rf /tmp/NonSteamLaunchersDecky* echo "$USER_PASSWORD" | sudo -S rm -rf /tmp/NonSteamLaunchersDecky*
fi
# Check if update was done
if [ $? -eq 1 ]; then
set -x set -x
cd "$LOCAL_DIR"
show_message "Plugin installed. Switching to Game Mode..." # Switch to game mode and restart service
show_message " NSL Plugin installed. Switching to Game Mode..."
switch_to_game_mode switch_to_game_mode
sudo systemctl restart plugin_loader.service sudo systemctl restart plugin_loader.service
else
echo "No update needed. Skipping Game Mode switch."
fi fi