Repository navigation
Expand file tree
/
Copy pathslssteam
More file actions
executable file
·323 lines (274 loc) · 9.56 KB
/
Copy pathslssteam
File metadata and controls
executable file
·323 lines (274 loc) · 9.56 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#!/usr/bin/env bash
# SLSsteam Manager & Auto-Updater CLI
REPO="AceSLS/SLSsteam"
INSTALL_DIR="$HOME/.local/share/SLSsteam"
VERSION_FILE="$INSTALL_DIR/.version"
FLATPAK_APP_ID="com.valvesoftware.Steam"
FLATPAK_SLSDIR="$HOME/.var/app/$FLATPAK_APP_ID/.local/share/SLSsteam"
get_latest_release() {
curl -sL -H "User-Agent: SLSsteamManager" "https://api.github.com/repos/$REPO/releases/latest"
}
get_installed_version() {
if [[ -f "$VERSION_FILE" ]]; then
cat "$VERSION_FILE"
elif [[ -f "$FLATPAK_SLSDIR/.version" ]]; then
cat "$FLATPAK_SLSDIR/.version"
elif [[ -f "$INSTALL_DIR/SLSsteam.so" || -f "$FLATPAK_SLSDIR/SLSsteam.so" ]]; then
echo "Installed (Unversioned)"
else
echo "Not Installed"
fi
}
pause_and_return() {
echo ""
# Flush leftover stdin buffer
read -t 0.1 -n 10000 _discard 2>/dev/null || true
echo -e "\033[1;33mPress any key to return to main menu...\033[0m"
read -rsn1 _key
}
do_install_or_update() {
echo -e "\033[1;34m=== Updating / Installing SLSsteam ===\033[0m"
local installed
installed=$(get_installed_version)
echo "Fetching release details from GitHub..."
local release_json
release_json=$(get_latest_release)
local latest_tag
latest_tag=$(echo "$release_json" | jq -r '.tag_name // empty' 2>/dev/null)
local download_url
download_url=$(echo "$release_json" | jq -r '.assets[] | select(.name | test("SLSsteam-Any(-release)?\\.7z")) | .browser_download_url // empty' 2>/dev/null | head -n 1)
if [[ -z "$latest_tag" || -z "$download_url" ]]; then
echo -e "\033[1;31mError: Could not retrieve release assets from GitHub.\033[0m"
return 1
fi
echo -e "Latest version: \033[1;32m$latest_tag\033[0m"
echo -e "Current status: \033[1;33m$installed\033[0m"
local tmp_dir
tmp_dir=$(mktemp -d -t slssteam-mgr-XXXXXX)
trap 'rm -rf "$tmp_dir"' EXIT
echo "Downloading $download_url..."
curl -sL -H "User-Agent: SLSsteamManager" "$download_url" -o "$tmp_dir/package.7z"
echo "Extracting release archive..."
7z x -o"$tmp_dir" "$tmp_dir/package.7z" > /dev/null
cd "$tmp_dir"
if [[ ! -f "setup.sh" ]]; then
echo -e "\033[1;31mError: Invalid archive structure (setup.sh missing).\033[0m"
return 1
fi
chmod +x setup.sh
# Perform installation based on system setup
local has_flatpak=false
if command -v flatpak >/dev/null 2>&1; then
if flatpak info "$FLATPAK_APP_ID" >/dev/null 2>&1; then
has_flatpak=true
fi
fi
if [[ -d "$FLATPAK_SLSDIR" || "$has_flatpak" == true ]]; then
echo "Installing/Updating for Steam Flatpak..."
./setup.sh flatpak-install || true
fi
if [[ -d "$INSTALL_DIR" || "$has_flatpak" == false ]]; then
echo "Installing/Updating standard Steam installation..."
./setup.sh install || true
fi
mkdir -p "$INSTALL_DIR"
echo "$latest_tag" > "$VERSION_FILE"
if [[ -d "$FLATPAK_SLSDIR" ]]; then
echo "$latest_tag" > "$FLATPAK_SLSDIR/.version"
fi
echo ""
echo -e "\033[1;32mSuccessfully updated/installed SLSsteam ($latest_tag)!\033[0m"
echo "Please restart Steam for changes to take effect."
}
check_status() {
echo -e "\033[1;34m=== SLSsteam Status ===\033[0m"
local installed
installed=$(get_installed_version)
echo -e "Installed version: \033[1;33m$installed\033[0m"
echo -n "Checking GitHub for latest release... "
local release_json
release_json=$(get_latest_release)
local latest_tag
latest_tag=$(echo "$release_json" | jq -r '.tag_name // empty' 2>/dev/null)
if [[ -z "$latest_tag" ]]; then
echo -e "\033[1;31mError fetching latest release from GitHub.\033[0m"
return
fi
echo -e "\033[1;32m$latest_tag\033[0m"
echo ""
if [[ "$installed" == "$latest_tag" ]]; then
echo -e "\033[1;32m[OK] You are already on the latest version ($installed)!\033[0m"
else
if [[ "$installed" == "Not Installed" ]]; then
echo -e "\033[1;33mSLSsteam is not currently installed.\033[0m"
else
echo -e "\033[1;36m[!] A new version of SLSsteam is available!\033[0m"
echo -e " Current: \033[1;33m$installed\033[0m"
echo -e " Latest: \033[1;32m$latest_tag\033[0m"
fi
echo ""
read -rp "Would you like to install/update now? [Y/n]: " choice
if [[ -z "$choice" || "$choice" =~ ^[Yy]$ ]]; then
echo ""
do_install_or_update
fi
fi
}
do_uninstall() {
echo -e "\033[1;31m=== Uninstalling SLSsteam ===\033[0m"
local tmp_dir
tmp_dir=$(mktemp -d -t slssteam-uninstall-XXXXXX)
trap 'rm -rf "$tmp_dir"' EXIT
echo "Fetching setup.sh for clean uninstallation..."
curl -sL -H "User-Agent: SLSsteamManager" "https://raw.githubusercontent.com/$REPO/main/setup.sh" -o "$tmp_dir/setup.sh"
chmod +x "$tmp_dir/setup.sh"
cd "$tmp_dir"
echo "Running SLSsteam uninstaller..."
./setup.sh uninstall || true
./setup.sh flatpak-uninstall 2>/dev/null || true
rm -f "$VERSION_FILE"
if [[ -d "$FLATPAK_SLSDIR" ]]; then
rm -f "$FLATPAK_SLSDIR/.version"
fi
echo ""
echo -e "\033[1;32mSLSsteam has been uninstalled.\033[0m"
echo "Please restart Steam for changes to take effect."
}
# TUI Arrow Key Selector
select_option() {
local prompt="$1"
shift
local options=("$@")
local cur=0
local count=${#options[@]}
local key=""
local rest=""
# Hide cursor
printf "\033[?25l"
trap 'printf "\033[?25h"' EXIT INT TERM
echo -e "$prompt\n"
# Render initial list
for i in "${!options[@]}"; do
if [[ $i -eq $cur ]]; then
echo -e " \033[1;36m❯ ${options[$i]}\033[0m"
else
echo -e " \033[0;37m${options[$i]}\033[0m"
fi
done
while true; do
read -rsn1 key || key=""
if [[ "$key" == $'\x1b' ]]; then
read -rsn2 -t 0.05 rest || rest=""
case "$rest" in
"[A") # Up
((cur--)) || true
if [[ $cur -lt 0 ]]; then cur=$((count - 1)); fi
;;
"[B") # Down
((cur++)) || true
if [[ $cur -ge $count ]]; then cur=0; fi
;;
esac
elif [[ "$key" == "" ]]; then # Enter key
break
elif [[ "$key" == "k" || "$key" == "K" ]]; then # Vim up
((cur--)) || true
if [[ $cur -lt 0 ]]; then cur=$((count - 1)); fi
elif [[ "$key" == "j" || "$key" == "J" ]]; then # Vim down
((cur++)) || true
if [[ $cur -ge $count ]]; then cur=0; fi
elif [[ "$key" =~ [1-9] ]] && [[ "$key" -le "$count" ]]; then
cur=$((key - 1))
break
fi
# Move cursor up N lines and redraw
printf "\033[%dA" "$count"
for i in "${!options[@]}"; do
printf "\033[K"
if [[ $i -eq $cur ]]; then
echo -e " \033[1;36m❯ ${options[$i]}\033[0m"
else
echo -e " \033[0;37m${options[$i]}\033[0m"
fi
done
done
# Restore cursor
printf "\033[?25h"
trap - EXIT INT TERM
SELECTED_CHOICE=$cur
}
show_menu() {
while true; do
clear 2>/dev/null || true
local installed
installed=$(get_installed_version)
echo -e "\033[1;35m========================================\033[0m"
echo -e "\033[1;37m SLSsteam Manager \033[0m"
echo -e "\033[1;35m========================================\033[0m"
echo -e " Installed Version: \033[1;32m$installed\033[0m"
echo -e "\033[1;35m----------------------------------------\033[0m"
echo ""
local options=(
"Install / Update SLSsteam"
"Uninstall SLSsteam"
"Check Version & Status"
"Exit"
)
select_option "\033[1;33mUse ↑/↓ arrows (or 1-4) and press Enter to select:\033[0m" "${options[@]}"
local choice=$SELECTED_CHOICE
clear 2>/dev/null || true
case "$choice" in
0)
do_install_or_update
pause_and_return
;;
1)
read -rp "Are you sure you want to uninstall SLSsteam? [y/N]: " confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
do_uninstall
else
echo "Uninstallation cancelled."
fi
pause_and_return
;;
2)
check_status
pause_and_return
;;
3)
echo -e "\nGoodbye!"
exit 0
;;
esac
done
}
# Entrypoint / CLI parsing
ACTION="${1:-}"
case "$ACTION" in
update|install|--update|--install)
do_install_or_update
;;
remove|uninstall|--remove|--uninstall)
do_uninstall
;;
status|--status)
check_status
;;
help|--help|-h)
echo "Usage: slssteam [COMMAND]"
echo ""
echo "Commands:"
echo " (no args) Launch interactive TUI menu"
echo " update Update or reinstall SLSsteam to the latest version"
echo " uninstall Remove/uninstall SLSsteam"
echo " status Check installed version vs latest GitHub release"
;;
"")
show_menu
;;
*)
echo "Unknown command: $ACTION"
echo "Run 'slssteam --help' for usage."
exit 1
;;
esac