-
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathNSLPluginInstaller.sh
More file actions
145 lines (117 loc) · 4.06 KB
/
NSLPluginInstaller.sh
File metadata and controls
145 lines (117 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
# ENVIRONMENT VARIABLES
logged_in_user=$(logname 2>/dev/null || whoami)
logged_in_home=$(eval echo "~${logged_in_user}")
# Function to prompt for sudo password
prompt_for_sudo() {
password=$(zenity --password --title="Authentication Required" --text="Please enter your password to proceed with installation/update.")
# Validate password
echo "$password" | sudo -S -v >/dev/null 2>&1
if [ $? -ne 0 ]; then
zenity --error --text="Incorrect password or sudo failed. Exiting."
exit 1
fi
}
# Function to switch to Game Mode
switch_to_game_mode() {
echo "Switching to Game Mode..."
rm -rf "${logged_in_home}/.config/systemd/user/nslgamescanner.service"
unlink "${logged_in_home}/.config/systemd/user/default.target.wants/nslgamescanner.service"
systemctl --user daemon-reload
qdbus org.kde.Shutdown /Shutdown org.kde.Shutdown.logout
}
# Function to display Zenity messages
show_message() {
zenity --notification --text="$1" --timeout=1
}
show_update_message() {
zenity --notification --text="Updating from $1 to $2..." --timeout=5
}
# Set URLs and paths
REPO_URL="https://github.com/moraroy/NonSteamLaunchersDecky/archive/refs/heads/main.zip"
GITHUB_URL="https://raw.githubusercontent.com/moraroy/NonSteamLaunchersDecky/main/package.json"
LOCAL_DIR="${logged_in_home}/homebrew/plugins/NonSteamLaunchers"
# Ask the user
zenity --question --text="Would you like to install or update the NonSteamLaunchers Decky Plugin?" --title="Install/Update Plugin" --ok-label="Yes" --cancel-label="No"
if [ $? -eq 1 ]; then
echo "User canceled the installation/update."
exit 0
fi
# Prompt for sudo once
prompt_for_sudo
# Check for existing directories
DECKY_LOADER_EXISTS=false
NSL_PLUGIN_EXISTS=false
if [ -d "${logged_in_home}/homebrew/plugins" ]; then
DECKY_LOADER_EXISTS=true
fi
if [ -d "$LOCAL_DIR" ] && [ -n "$(ls -A "$LOCAL_DIR")" ]; then
NSL_PLUGIN_EXISTS=true
fi
# Version extraction from JSON (no jq)
extract_version() {
grep -o '"version": *"[^"]*"' "$1" | sed 's/.*"version": *"\([^"]*\)".*/\1/'
}
fetch_github_version() {
version=$(curl -s "$GITHUB_URL" | grep -o '"version": *"[^"]*"' | sed 's/.*"version": *"\([^"]*\)".*/\1/')
echo "$version"
}
fetch_local_version() {
if [ -f "$LOCAL_DIR/package.json" ]; then
version=$(extract_version "$LOCAL_DIR/package.json")
echo "$version"
fi
}
compare_versions() {
if [ ! -f "$LOCAL_DIR/package.json" ]; then
return 1
fi
local_version=$(fetch_local_version)
github_version=$(fetch_github_version)
if [ "$local_version" == "$github_version" ]; then
return 0
else
return 1
fi
}
# Main logic
set +x
# Sanity checks
if $DECKY_LOADER_EXISTS; then
if ! $NSL_PLUGIN_EXISTS; then
zenity --info --text="Decky Loader is detected but no NSL plugin found. It will now be injected into Game Mode."
fi
else
zenity --error --text="Decky Loader not found. Please install it and re-run the script."
exit 1
fi
# Version check
compare_versions
if [ $? -eq 0 ]; then
show_message "No update needed. The plugin is already up-to-date."
else
local_version=$(fetch_local_version)
github_version=$(fetch_github_version)
show_update_message "$local_version" "$github_version"
if $NSL_PLUGIN_EXISTS; then
show_message "NSL Plugin detected. Deleting and updating..."
echo "$password" | sudo -S rm -rf "$LOCAL_DIR"
fi
show_message "Creating base directory and setting permissions..."
echo "$password" | sudo -S mkdir -p "$LOCAL_DIR"
echo "$password" | sudo -S chmod -R u+rw "$LOCAL_DIR"
echo "$password" | sudo -S chown -R "$logged_in_user:$logged_in_user" "$LOCAL_DIR"
curl -L "$REPO_URL" -o /tmp/NonSteamLaunchersDecky.zip
unzip -o /tmp/NonSteamLaunchersDecky.zip -d /tmp/
cp -r /tmp/NonSteamLaunchersDecky-main/* "$LOCAL_DIR"
rm -rf /tmp/NonSteamLaunchersDecky*
fi
set -x
cd "$LOCAL_DIR"
# Ask to switch to Game Mode
zenity --question --text="Plugin installed or updated. Do you want to switch to Game Mode now?" --title="Switch to Game Mode?" --ok-label="Yes" --cancel-label="No"
if [ $? -eq 0 ]; then
switch_to_game_mode
else
show_message "Remaining in Desktop Mode."
fi