-
Notifications
You must be signed in to change notification settings - Fork 0
/
proton-community-updater.sh
executable file
·766 lines (675 loc) · 30 KB
/
proton-community-updater.sh
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
#!/usr/bin/env bash
############################################################################
# Proton Community Build download and management script
############################################################################
#
#
#
#
# made with <3
# Author: https://github.com/Termuellinator
#
# Based on https://github.com/the-sane/lug-helper
# and
# https://github.com/richardtatum/sc-runner-updater
############################################################################
###################### Variables to be changed by user #####################
# steam default directory
steam_dir_default="$HOME/.local/share/Steam"
# ubuntu uses a different directory if steam is installed via repo
steam_dir_ubuntu="$HOME/.steam/debian-installation"
# steam flatpak is also a thing
steam_dir_flatpak="$HOME/.var/app/com.valvesoftware.Steam/.local/share/Steam"
# URLs for downloading Proton builds
# Elements in this array must be added in quoted pairs of: "description" "url"
# The first string in the pair is expected to contain the proton description
# The second is expected to contain the github api releases url
# ie. "GloriousEggroll" "https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases"
proton_sources=(
"GloriousEggroll" "https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases"
"TKG" "https://api.github.com/repos/Frogging-Family/wine-tkg-git/releases"
)
# Set a maximum number of proton versions to display from each url
max_versions=20
############################################################################
# Check if script is run as root
if [ "$(id -u)" = 0 ]; then
echo "This script is not supposed to be run as root!"
exit 1
fi
# Check for dependencies
if [ ! -x "$(command -v curl)" ]; then
# Print to stderr and also try warning the user through notify-send
printf "proton-community-updater.sh: The required package 'curl' was not found on this system.\n" 1>&2
notify-send "proton-community-updater" "The required package 'curl' was not found on this system.\n" --icon=dialog-warning
exit 1
fi
if [ ! -x "$(command -v mktemp)" ] || [ ! -x "$(command -v basename)" ]; then
# Print to stderr and also try warning the user through notify-send
printf "proton-community-updater.sh: One or more required packages were not found on this system.\nPlease check that the following packages are installed:\n- mktemp (part of gnu coreutils)\n- basename (part of gnu coreutils)\n" 1>&2
notify-send "proton-community-updater" "One or more required packages were not found on this system.\nPlease check that the following packages are installed:\n- mktemp (part of gnu coreutils)\n- basename (part of gnu coreutils)\n" --icon=dialog-warning
exit 1
fi
# Temporary directory
tmp_dir="$(mktemp -d --suffix=".proton-community-updater")"
trap 'rm -r "$tmp_dir"' EXIT
############################################################################
# Pixels to add for each Zenity menu option
# used to dynamically determine the height of menus
menu_option_height="25"
# Use logo installed by a packaged version of this script if available
# Otherwise, default to the logo in the same directory
if [ -f "/usr/share/pixmaps/proton-community-updater-icon.png" ]; then
pcu_logo="/usr/share/pixmaps/proton-community-updater-icon.png"
elif [ -f "proton-community-updater-icon.png" ]; then
pcu_logo="proton-community-updater-icon.png"
else
pcu_logo="info"
fi
############################################################################
############################################################################
# Echo a formatted debug message to the terminal and optionally exit
# Accepts either "continue" or "exit" as the first argument
# followed by the string to be echoed
debug_print() {
# This function expects two string arguments
if [ "$#" -lt 2 ]; then
printf "\nScript error: The debug_print function expects two arguments. Aborting.\n"
read -n 1 -s -p "Press any key..."
exit 0
fi
# Echo the provided string and, optionally, exit the script
case "$1" in
"continue")
printf "\n$2\n"
;;
"exit")
# Write an error to stderr and exit
printf "proton-community-updater.sh: $2\n" 1>&2
read -n 1 -s -p "Press any key..."
exit 1
;;
*)
printf "proton-community-updater.sh: Unknown argument provided to debug_print function. Aborting.\n" 1>&2
read -n 1 -s -p "Press any key..."
exit 0
;;
esac
}
# Display a message to the user.
# Expects the first argument to indicate the message type, followed by
# a string of arguments that will be passed to zenity or echoed to the user.
#
# To call this function, use the following format: message [type] "[string]"
# See the message types below for instructions on formatting the string.
message() {
# Sanity check
if [ "$#" -lt 2 ]; then
debug_print exit "Script error: The message function expects two arguments. Aborting."
fi
# Use zenity messages if available
if [ "$use_zenity" -eq 1 ]; then
case "$1" in
"info")
# info message
# call format: message info "text to display"
margs=("--info" "--window-icon=$pcu_logo" "--no-wrap" "--text=")
;;
"warning")
# warning message
# call format: message warning "text to display"
margs=("--warning" "--window-icon=$pcu_logo" "--text=")
;;
"question")
# question
# call format: if message question "question to ask?"; then...
margs=("--question" "--window-icon=$pcu_logo" "--text=")
;;
*)
debug_print exit "Script Error: Invalid message type passed to the message function. Aborting."
;;
esac
# Display the message
shift 1 # drop the first argument and shift the remaining up one
zenity "${margs[@]}""$@" --width="400" --title="Proton Community Updater" 2>/dev/null
else
# Fall back to text-based messages when zenity is not available
case "$1" in
"info")
# info message
# call format: message info "text to display"
clear
printf "\n$2\n\n"
read -n 1 -s -p "Press any key..."
;;
"warning")
# warning message
# call format: message warning "text to display"
clear
printf "\n$2\n\n"
read -n 1 -s -p "Press any key..."
return 0
;;
"question")
# question
# call format: if message question "question to ask?"; then...
clear
printf "$2\n"
while read -p "[y/n]: " yn; do
case "$yn" in
[Yy]*)
return 0
;;
[Nn]*)
return 1
;;
*)
printf "Please type 'y' or 'n'\n"
;;
esac
done
;;
*)
debug_print exit "Script Error: Invalid message type passed to the message function. Aborting."
;;
esac
fi
}
# Display a menu to the user.
# Uses Zenity for a gui menu with a fallback to plain old text.
#
# How to call this function:
#
# Requires two arrays to be set: "menu_options" and "menu_actions"
# two string variables: "menu_text_zenity" and "menu_text_terminal"
# and one integer variable: "menu_height".
#
# - The array "menu_options" should contain the strings of each option.
# - The array "menu_actions" should contain function names to be called.
# - The strings "menu_text_zenity" and "menu_text_terminal" should contain
# the menu description formatted for zenity and the terminal, respectively.
# This text will be displayed above the menu options.
# Zenity supports Pango Markup for text formatting.
# - The integer "menu_height" specifies the height of the zenity menu.
#
# The final element in each array is expected to be a quit option.
#
# IMPORTANT: The indices of the elements in "menu_actions"
# *MUST* correspond to the indeces in "menu_options".
# In other words, it is expected that menu_actions[1] is the correct action
# to be executed when menu_options[1] is selected, and so on for each element.
#
# See MAIN at the bottom of this script for an example of generating a menu.
menu() {
# Sanity checks
if [ "${#menu_options[@]}" -eq 0 ]; then
debug_print exit "Script error: The array 'menu_options' was not set\nbefore calling the menu function. Aborting."
elif [ "${#menu_actions[@]}" -eq 0 ]; then
debug_print exit "Script error: The array 'menu_actions' was not set\nbefore calling the menu function. Aborting."
elif [ -z "$menu_text_zenity" ]; then
debug_print exit "Script error: The string 'menu_text_zenity' was not set\nbefore calling the menu function. Aborting."
elif [ -z "$menu_text_terminal" ]; then
debug_print exit "Script error: The string 'menu_text_terminal' was not set\nbefore calling the menu function. Aborting."
elif [ -z "$menu_height" ]; then
debug_print exit "Script error: The string 'menu_height' was not set\nbefore calling the menu function. Aborting."
elif [ -z "$cancel_label" ]; then
debug_print exit "Script error: The string 'cancel_label' was not set\nbefore calling the menu function. Aborting."
fi
# Use Zenity if it is available
if [ "$use_zenity" -eq 1 ]; then
# Format the options array for Zenity by adding
# TRUE or FALSE to indicate default selections
# ie: "TRUE" "List item 1" "FALSE" "List item 2" "FALSE" "List item 3"
for (( i=0; i<"${#menu_options[@]}"-1; i++ )); do
if [ "$i" -eq 0 ]; then
# Select the first radio button by default
zen_options=("TRUE")
zen_options+=("${menu_options[i]}")
else
zen_options+=("FALSE")
zen_options+=("${menu_options[i]}")
fi
done
# Display the zenity radio button menu
choice="$(zenity --list --radiolist --width="480" --height="$menu_height" --text="$menu_text_zenity" --title="Proton Community Updater" --hide-header --cancel-label "$cancel_label" --window-icon=$pcu_logo --column="" --column="Option" "${zen_options[@]}" 2>/dev/null)"
# Loop through the options array to match the chosen option
matched="false"
for (( i=0; i<"${#menu_options[@]}"; i++ )); do
if [ "$choice" = "${menu_options[i]}" ]; then
# Execute the corresponding action
${menu_actions[i]}
matched="true"
break
fi
done
# If no match was found, the user clicked cancel
if [ "$matched" = "false" ]; then
# Execute the last option in the actions array
"${menu_actions[${#menu_actions[@]}-1]}"
fi
else
# Use a text menu if Zenity is not available
clear
printf "\n$menu_text_terminal\n\n"
PS3="Enter selection number: "
select choice in "${menu_options[@]}"
do
# Loop through the options array to match the chosen option
matched="false"
for (( i=0; i<"${#menu_options[@]}"; i++ )); do
if [ "$choice" = "${menu_options[i]}" ]; then
# Execute the corresponding action
printf "\n\n"
${menu_actions[i]}
matched="true"
break
fi
done
# Check if we're done looping the menu
if [ "$matched" = "true" ]; then
# Match was found and actioned, so exit the menu
break
else
# If no match was found, the user entered an invalid option
printf "\nInvalid selection.\n"
continue
fi
done
fi
}
# Called when the user clicks cancel on a looping menu
# Causes a return to the main menu
menu_loop_done() {
looping_menu="false"
}
#------------------------- begin Proton Builds functions ----------------------------#
# Inform about needed restart
steam_restart() {
if [ "$steam_needs_restart" = "true" ] && [ "$(pgrep steam)" ]; then
message info "Steam must be restarted to detect changes in installed Proton versions."
fi
steam_needs_restart="false"
}
# Delete the selected proton
proton_delete() {
# This function expects an index number for the array
# installed_proton to be passed in as an argument
if [ -z "$1" ]; then
debug_print exit "Script error: The proton_delete function expects an argument. Aborting."
fi
proton_to_delete="$1"
if message question "Are you sure you want to delete the following Proton Build?\n\n${installed_proton[$proton_to_delete]}"; then
rm -rf "${installed_proton[$proton_to_delete]}"
debug_print continue "Deleted ${installed_proton[$proton_to_delete]}"
steam_needs_restart="true"
fi
}
# List installed Proton Builds for deletion
proton_select_delete() {
# Configure the menu
menu_text_zenity="Select the Proton build you want to remove:"
menu_text_terminal="Select the Proton build you want to remove:"
menu_text_height="65"
goback="Return to the Proton management menu"
unset installed_proton
unset menu_options
unset menu_actions
# Create an array containing all directories in the proton_dir
for proton_list in "$proton_dir"/*; do
if [ -d "$proton_list" ]; then
installed_proton+=("$proton_list")
fi
done
# Create menu options for the installed proton builds
for (( i=0; i<"${#installed_proton[@]}"; i++ )); do
menu_options+=("$(basename "${installed_proton[i]}")")
menu_actions+=("proton_delete $i")
done
# Complete the menu by adding the option to go back to the previous menu
menu_options+=("$goback")
menu_actions+=(":") # no-op
# Calculate the total height the menu should be
menu_height="$(($menu_option_height * ${#menu_options[@]} + $menu_text_height))"
if [ "$menu_height" -gt "400" ]; then
menu_height="400"
fi
# Set the label for the cancel button
cancel_label="Go Back"
# Call the menu function. It will use the options as configured above
menu
}
# Download and install the selected proton build
# Note: The variables proton_versions, contributor_url, and proton_url_type
# are expected to be set before calling this function
proton_install() {
# This function expects an index number for the array
# proton_versions to be passed in as an argument
if [ -z "$1" ]; then
debug_print exit "Script error: The proton_install function expects a numerical argument. Aborting."
fi
# Get the proton build filename including file extension
proton_file="${proton_versions[$1]}"
# Get the selected proton build name minus the file extension
# To add new file extensions, handle them here and in
# the proton_select_install function below
case "$proton_file" in
*.tar.gz)
proton_name="$(basename "$proton_file" .tar.gz)"
;;
*.tgz)
proton_name="$(basename "$proton_file" .tgz)"
;;
*.tar.xz)
proton_name="$(basename "$proton_file" .tar.xz)"
;;
*)
debug_print exit "Unknown archive filetype in proton_install function. Aborting."
;;
esac
# Get the selected proton build url
# To add new sources, handle them here and in the
# proton_select_install function below
if [ "$proton_url_type" = "github" ]; then
proton_dl_url="$(curl -s "$contributor_url" | grep "browser_download_url.*$proton_file" | cut -d \" -f4)"
else
debug_print exit "Script error: Unknown api/url format in proton_sources array. Aborting."
fi
# Sanity check
if [ -z "$proton_dl_url" ]; then
message warning "Could not find the requested Proton build. The source API may be down or rate limited."
return 1
fi
# Download the proton build to the tmp directory
debug_print continue "Downloading $proton_dl_url into $tmp_dir/$proton_file..."
if [ "$use_zenity" -eq 1 ]; then
# Format the curl progress bar for zenity
mkfifo "$tmp_dir/protonpipe"
cd "$tmp_dir" && curl -#LO "$proton_dl_url" > "$tmp_dir/protonpipe" 2>&1 & curlpid="$!"
stdbuf -oL tr '\r' '\n' < "$tmp_dir/protonpipe" | \
grep --line-buffered -ve "100" | grep --line-buffered -o "[0-9]*\.[0-9]" | \
(
trap 'kill "$curlpid"' ERR
zenity --progress --auto-close --title="Proton Community Updater" --text="Downloading Proton build. This might take a moment.\n" 2>/dev/null
)
if [ "$?" -eq 1 ]; then
# User clicked cancel
debug_print continue "Download aborted. Removing $tmp_dir/$proton_file..."
rm "$tmp_dir/$proton_file"
rm "$tmp_dir/protonpipe"
return 1
fi
rm "$tmp_dir/protonpipe"
else
# Standard curl progress bar
(cd "$tmp_dir" && curl -LO "$proton_dl_url")
fi
# Sanity check
if [ ! -f "$tmp_dir/$proton_file" ]; then
debug_print exit "Script error: The requested proton build file was not downloaded. Aborting"
fi
# Check if the archive has /files/ folder at top level and deciding wheather or not to create a subfolder
if tar tf "$tmp_dir/$proton_file" | grep -m 1 -E "^files" > /dev/null; then
# Create subfolder by the name of $proton_name and extract archive there
debug_print continue "Installing Proton into $proton_dir/$proton_name..."
if [ "$use_zenity" -eq 1 ]; then
# Use Zenity progress bar
mkdir -p "$proton_dir/$proton_name" && tar -xf "$tmp_dir/$proton_file" -C "$proton_dir/$proton_name" | \
zenity --progress --pulsate --no-cancel --auto-close --title="Proton Community Updater" --text="Installing Proton build...\n" 2>/dev/null
else
mkdir -p "$proton_dir/$proton_name" && tar -xf "$tmp_dir/$proton_file" -C "$proton_dir/$proton_name"
fi
steam_needs_restart="true"
else
# Extract archive without a subfolder as archive seems to contain subfolder already
debug_print continue "Installing Proton into $proton_dir..."
if [ "$use_zenity" -eq 1 ]; then
# Use Zenity progress bar
mkdir -p "$proton_dir" && tar -xf "$tmp_dir/$proton_file" -C "$proton_dir" | \
zenity --progress --pulsate --no-cancel --auto-close --title="Proton Community Updater" --text="Installing Proton build...\n" 2>/dev/null
else
mkdir -p "$proton_dir" && tar -xf "$tmp_dir/$proton_file" -C "$proton_dir"
fi
steam_needs_restart="true"
fi
# Cleanup tmp download
debug_print continue "Removing $tmp_dir/$proton_file..."
rm "$tmp_dir/$proton_file"
}
# List available Proton builds for download
proton_select_install() {
# This function expects an element number for the array
# proton_sources to be passed in as an argument
if [ -z "$1" ]; then
debug_print exit "Script error: The proton_select_install function expects a numerical argument. Aborting."
fi
# Store the url from the selected contributor
contributor_url="${proton_sources[$1+1]}"
# Check the provided contributor url to make sure we know how to handle it
# To add new sources, add them here and handle in the if statement
# just below and the proton_install function above
case "$contributor_url" in
https://api.github.com*)
proton_url_type="github"
;;
*)
debug_print exit "Script error: Unknown api/url format in proton_sources array. Aborting."
;;
esac
# Check for GlibC-Version if TKG is selected, as he requires 2.33
if [ "$contributor_url" = "https://api.github.com/repos/Frogging-Family/wine-tkg-git/releases" ]; then
printf "checking for glibc \n"
system_glibc=($(ldd --version | awk '/ldd/{print $NF}'))
printf "system glibc-versuib: $system_glibc \n"
required_glibc="2.33"
if [ "$(bc <<< "$required_glibc>$system_glibc")" == "1" ]; then
message warning "Your glibc version is too low, TKG requires v$required_glibc "
proton_manage
fi
fi
# Fetch a list of proton versions from the selected contributor
# To add new sources, handle them here, in the if statement
# just above, and the proton_install function above
if [ "$proton_url_type" = "github" ]; then
proton_versions=($(curl -s "$contributor_url" | awk '/browser_download_url/ {print $2}' | grep -vE "*.sha512sum" | xargs basename -a))
else
debug_print exit "Script error: Unknown api/url format in proton_sources array. Aborting."
fi
# Sanity check
if [ "${#proton_versions[@]}" -eq 0 ]; then
message warning "No proton versions were found. The source API may be down or rate limited."
return 1
fi
# Configure the menu
menu_text_zenity="Select the Proton build you want to install:"
menu_text_terminal="Select the Proton build you want to install:"
menu_text_height="65"
goback="Return to the Proton management menu"
unset menu_options
unset menu_actions
# Iterate through the versions, check if they are installed,
# and add them to the menu options
# To add new file extensions, handle them here and in
# the proton_install function above
for (( i=0; i<"$max_versions" && i<"${#proton_versions[@]}"; i++ )); do
# Get the proton name minus the file extension
case "${proton_versions[i]}" in
*.tar.gz)
proton_name="$(basename "${proton_versions[i]}" .tar.gz)"
;;
*.tgz)
proton_name="$(basename "${proton_versions[i]}" .tgz)"
;;
*.tar.xz)
proton_name="$(basename "${proton_versions[i]}" .tar.xz)"
;;
*)
proton_name="skip"
;;
esac
# Add the proton names to the menu
if [ $proton_name = "skip" ]; then
continue
elif [ -d "$proton_dir/$proton_name" ]; then
menu_options+=("$proton_name [installed]")
else
menu_options+=("$proton_name")
fi
menu_actions+=("proton_install $i")
done
# Complete the menu by adding the option to go back to the previous menu
menu_options+=("$goback")
menu_actions+=(":") # no-op
# Calculate the total height the menu should be
menu_height="$(($menu_option_height * ${#menu_options[@]} + $menu_text_height))"
if [ "$menu_height" -gt "400" ]; then
menu_height="400"
fi
# Set the label for the cancel button
cancel_label="Go Back"
# Call the menu function. It will use the options as configured above
menu
}
# Manage Proton Builds
#
# This function expects the following variables to be set:
#
# - The string proton_sources is a formatted array containing the URLs
# of items to download. It should be pointed to the appropriate
# array set at the top of the script using indirect expansion.
# See proton_sources at the top and proton_manage() below for examples.
# - The string proton_dir should contain the location the downloaded item
# will be installed to.
proton_manage() {
# Check if Steam is installed
if [ ! -x "$(command -v steam)" ]; then
message info "Steam does not appear to be installed."
return 0
fi
# Check if the proton_dir exists and create it if not
if [ ! -d "$proton_dir" ]; then
mkdir -p "$proton_dir"
fi
# The proton management menu will loop until the user cancels
looping_menu="true"
while [ "$looping_menu" = "true" ]; do
# Configure the menu
menu_text_zenity="<b><big>Manage Your Proton Builds</big>\n\nThe Proton Builds listed below are custom builds not affiliated with Valve</b>\n\nYou may choose from the following options:"
menu_text_terminal="Manage Your Proton Builds\n\nThe Proton Builds listed below are custom builds not affiliated with Valve\nYou may choose from the following options:"
menu_text_height="140"
# Configure the menu options
delete="Remove an installed Proton build"
back="Return to the main menu"
unset menu_options
unset menu_actions
# Loop through the proton_sources array and create a menu item
# for each one. Even numbered elements will contain the proton build name
for (( i=0; i<"${#proton_sources[@]}"; i=i+2 )); do
# Set the options to be displayed in the menu
menu_options+=("Install a Proton build from ${proton_sources[i]}")
# Set the corresponding functions to be called for each of the options
menu_actions+=("proton_select_install $i")
done
# Set the label for the cancel button
if [ "$steam_detected" = "true" ] && [ "$flatpak_detected" = "true" ]; then
cancel_label="Go Back"
# Complete the menu by adding options to remove an installed proton build
# or go back to the previous menu
menu_options+=("$delete" "$back")
menu_actions+=("proton_select_delete" "menu_loop_done")
else
# if there is only steam OR flatpak installed, there is no main menu
cancel_label="Quit"
menu_options+=("$delete" "$quit_msg")
menu_actions+=("proton_select_delete" "quit")
fi
# Calculate the total height the menu should be
menu_height="$(($menu_option_height * ${#menu_options[@]} + $menu_text_height))"
# Call the menu function. It will use the options as configured above
menu
done
}
manage_local() {
proton_dir="$local_dir"
proton_manage
}
manage_flatpak() {
proton_dir="$flatpak_dir"
proton_manage
}
#-------------------------- end Proton builds functions -----------------------------#
# Credits for this go to https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c
get_latest_release() {
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}
quit() {
steam_restart # display message that steam needs to be restarted if new builds have been installed and steam ins running
exit 0
}
############################################################################
# MAIN
############################################################################
# Check if Zenity is available
use_zenity=0
if [ -x "$(command -v zenity)" ]; then
use_zenity=1
fi
# check if the default or ubuntu-directory are present
if [ -d "$steam_dir_default" ]; then
local_dir="$steam_dir_default/compatibilitytools.d/"
steam_detected="true"
elif [ -d "$steam_dir_ubuntu" ]; then
local_dir="$steam_dir_ubuntu/compatibilitytools.d/"
steam_detected="true"
elif [ -d "$steam_dir_flatpak" ]; then # if there is no normal steam dir, there can still be flatpak
steam_detected="false"
else
message warning "no Steam-directory found. If Steam is installed into a custom directory, change it at line 21."
exit 0
fi
# check if flatpaked steam is installed
if [ -d "$steam_dir_flatpak" ]; then
flatpak_dir="$steam_dir_flatpak/compatibilitytools.d/"
flatpak_detected="true"
else
flatpak_detected="false"
fi
# Set some defaults
steam_needs_restart="false"
# Check if a new Verison of the script is available
repo="Termuellinator/Proton-Community-Updater"
current_version="v1.3"
latest_version=$(get_latest_release "$repo")
if [ "$latest_version" != "$current_version" ]; then
# Print to stdout and also try warning the user through message
printf "New version available, check https://github.com/Termuellinator/Proton-Community-Updater/releases \n"
message info "New version available, check <a href='https://github.com/Termuellinator/Proton-Community-Updater/releases'>https://github.com/Termuellinator/Proton-Community-Updater/releases</a> \n"
fi
# Loop the main menu until the user selects quit
while true; do
# Configure the menu
menu_text_zenity="<b><big>Welcome, fellow Penguin, to the Proton Community Updater!</big>\n\nThis Helper is designed to help manage custom Proton builds</b>\n\nYou may choose from the following options:"
menu_text_terminal="Welcome, fellow Penguin, to the Proton Community Updater!\n\nThis Helper is designed to help manage custom Proton builds\nYou may choose from the following options:"
menu_text_height="140"
# Configure the menu options
local_msg="Download or delete custom Proton builds"
flatpak_msg="Download or delete custom Proton builds in the flatpak installation"
quit_msg="Quit"
# Set the options to be displayed in the menu
menu_options=("$local_msg" "$flatpak_msg" "$quit_msg")
# Set the corresponding functions to be called for each of the options
menu_actions=("manage_local" "manage_flatpak" "quit")
# Calculate the total height the menu should be
menu_height="$(($menu_option_height * ${#menu_options[@]} + $menu_text_height))"
# Set the label for the cancel button
cancel_label="Quit"
# show a selection menu if both local and flatpaked steam are installed, otherwise call manage directly
if [ "$steam_detected" = "true" ] && [ "$flatpak_detected" = "true" ]; then
menu
elif [ "$steam_detected" = "true" ]; then
manage_local
elif [ "$flatpak_detected" = "true" ]; then
manage_flatpak
fi
done