This repository has been archived by the owner on Mar 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ge-install-manager.partially_updated
executable file
·3851 lines (3362 loc) · 148 KB
/
ge-install-manager.partially_updated
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
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# vim: set ft=shell nowrap expandtab shiftwidth=4 tabstop=4 smarttab softtabstop=0
#
################################################################################
# #
# Toazd 2020 Unlicense https://unlicense.org/ #
# #
# GloriousEggroll proton-ge-custom installation manager #
# Easily manage proton-ge-custom installations #
# https://github.com/GloriousEggroll/proton-ge-custom #
# #
################################################################################
# -e Exit immediately if a command exits with a non-zero status.
set +e # WARNING: DO NOT set -e
# -h Remember the location of commands as they are looked up. Default is on.
# -u Treat unset variables as an error when substituting. Default is off.
# -o pipefail The return value of a pipeline is the status of the last command
# to exit with a non-zero status, or zero if no command exited with
# a non-zero status. Default is off.
set -huo pipefail
################################################################################
# "Things that would be nice, but aren't required for main features" list
# -Install function (currently automatic if any main function is used)
# -Replace getopts with a custom parser
# -Support for using jq in addition to sed
################################################################################
# Initialize global variables
# NOTE: Script constants (read only variables) are all upper-case
declare -gr SCRIPT_VERSION=0.7.10
declare -gr SCRIPT_FULL_NAME=${0##*/}
declare -gr SCRIPT_CODENAME="Cochrane Bonaventure" # The Bonaventure (10281NCC), according to Montgomery Scott, "was the first ship to have warp drive installed."
declare -gr PROJECT_URL="https://github.com/toazd/ge-install-manager" # CheckForScriptUpdate
declare -gr CHECK_LATEST=0
declare -gr CURL_HEADER_CONTENT_TYPE="Content-Type: application/json"
declare -gr CURL_HEADER_GITHUB_MEDIATYPE="Accept: application/vnd.github.v3.text+json"
declare -gr CURL_HEADER_USER_AGENT="User-Agent: toazd/$SCRIPT_FULL_NAME/$SCRIPT_VERSION"
declare -gr TEMP_PREFIX=${SCRIPT_FULL_NAME}.tmp.
# NOTE: Script global variables are all prefixed with g_
declare -g g_command_rm # Configuration file: rm_command
declare -g g_download_version=""
declare -g g_file_latest_json=""
declare -g g_file_releases_json=""
declare -g g_script_raw_url="https://raw.githubusercontent.com/toazd/ge-install-manager/master/ge-install-manager"
declare -g g_file_script_raw=""
declare -g g_script_config_path=${XDG_CONFIG_HOME:-$HOME/.config}/$SCRIPT_FULL_NAME
declare -g g_file_script_config=$g_script_config_path/$SCRIPT_FULL_NAME.conf
declare -g g_file_sed_unminify_script=$g_script_config_path/unminify-JSON.sed
declare -g g_install_path="" # Configuration file: install_path
declare -g g_install_version=""
declare -g g_latest_version=""
declare -g g_latest_version_url="" # Configuration file: latest_version_url
declare -g g_override_default_install_path=""
declare -g g_releases_url="" # Configuration file: releases_url
declare -g g_remove_version=""
declare -g g_remove_saved_version=""
declare -g g_report_version=""
declare -g g_script_cache_path="" # Configuration file: cache_path
declare -g g_temp_base_path=/tmp # Configuration file: temp_path
declare -g g_verify_version=""
declare -g g_show_release_notes_version=""
declare -gi g_check_update=0
declare -gi g_verbose=0
declare -gi g_download=0
declare -gi g_flag_sigint_caught=0
declare -gi g_force=0
declare -gi g_install=0
declare -gi g_integration_testing=0
declare -gi g_list_installed_versions=0
declare -gi g_real_exit_status=0
declare -gi g_remove_all_saved_packages=0
declare -gi g_remove_installed_version=0
declare -gi g_remove_install_path=0
declare -gi g_remove_saved_package=0
declare -gi g_report_install_path_usage=0
declare -gi g_report_version_usage=0
declare -gi g_show_help=0
declare -gi g_show_usage=0
declare -gi g_size_bytes_sed_unminify_script=146
declare -gi g_update=0
declare -gi g_verify=0
declare -gi g_releases_update_interval=3600 # (seconds) 60 minutes
declare -gi g_script_update_interval=43200 # (seconds) 12 hours
declare -gi g_list_available_versions=0
declare -gi g_show_release_notes=0
declare -gi g_show_all_release_notes=0
declare -gi g_uninstall_script=0
declare -gi g_script_update_check=0
declare -gi g_automated_mode=0
# Bash escape sequences
# https://www.shellcheck.net/wiki/SC2034
# shellcheck disable=SC2034
{
declare -g g_color_red="\033[1;31m"
declare -g g_color_green="\033[1;32m"
declare -g g_color_yellow="\033[1;33m"
declare -g g_color_blue="\033[1;34m"
declare -g g_color_magenta="\033[1;35m"
declare -g g_color_cyan="\033[1;36m"
declare -g g_color_white="\033[1;37m"
declare -g g_color_reset="\033[m"
}
################################################################################
# Purpose: Print the help text to stderr
# Input: None
# Output: None
# Return: Always 0
ShowHelp() {
cat <<HELP_HEREDOC 1>&2
$SCRIPT_FULL_NAME v$SCRIPT_VERSION "$SCRIPT_CODENAME"
Configuration file: $g_script_config_path/$SCRIPT_FULL_NAME.conf
Required: Bash 3.2+, curl, sed, tar, gzip, stat, wc, touch, file
Optional: date, du, pgrep, sort, cmp, envsubst, trash
-h - Show this help
-H - Show usage notes, formats, and examples
-l - List installed versions and saved packages
Saved package sizes are also checked (backports)
-L - List all releases available to install
-n <version> - Show release notes for <version>
Combined with -N, -n will be ignored
-N - Show release notes for all versions
-S - Report file count and disk usage of install path
-s <version> - Report file count and disk usage of <version>
-U - Check for and install the latest release
-u - Check for the latest release and report installed status
Combined with -U, -u will be ignored
-i <version> - Download and install <version>
-R <version> - Remove installed <version>
-r <version> - Remove saved package <version> (proton-ge tarball)
-V - Verify each installation using its saved package
Combined with -v, -V will be ignored
-v <version> - Verify <version> using its saved package
-d <version> - Download and save the package for <version>
-D - Remove cache and config files created by this script
To also remove all proton-ge-custom installations, use -XD.
-x - Remove all saved packages (proton-ge tarballs)
-X - Remove the entire install path
NOTE: Saved packages are currently stored in the installation path
-f - Force install, upgrade, or remove
Combined with -U and/or -i, remove saved package and download a new copy
-A - Automated mode (skip/disable certain prompts)
Skips prompting to edit a newly created config file
Skips prompt for creating a symlink to the script
-z - Enable verbose output mode (to stderr)
Format: (calling line)[function trace]: message
HELP_HEREDOC
return 0
}
################################################################################
# Purpose: Print the usage text to stderr
# Input: None
# Output: None
# Return: Always 0
ShowUsage() {
cat <<USAGE_HEREDOC 1>&2
Usage:
- Acceptable formats for <version>:
5.9-GE-3-ST, Proton-5.9-GE-3-ST, Proton-5.9-GE-3-ST.tar.gz (case-insensitive)
- Most parameters can be combined with other unique parameters.
> NOTE: arguments must directly follow parameters that require arguments
Example (both produce the same result):
./$SCRIPT_FULL_NAME -Hh
./$SCRIPT_FULL_NAME -h -H
Result: Show help and then show usage
Example (both produce the same result):
./$SCRIPT_FULL_NAME -lSui 5.9-GE-3-ST
./$SCRIPT_FULL_NAME -lS -i 5.9-GE-3-ST -u
Result: Check for the latest version and install it,
install version 5.9-GE-3-ST, list installed versions, then
report file and disk usage for the install path
Example: (assume the latest version is 5.9-GE-3-ST)
./$SCRIPT_FULL_NAME -z -u -i Proton-5.11-GE-1-MF -Xf
Result: enable verbose mode, remove the installation path,
update to the latest version 5.9-GE-3-ST, and then install version 5.11-GE-1-MF.
Example (both produce the same result):
./$SCRIPT_FULL_NAME -s 5.6-GE-3-ST -S
./$SCRIPT_FULL_NAME -Ss 5.6-GE-3-ST
Result: report disk usage and file count for the install path,
and then report disk usage and file count for version 5.6-GE-3-ST
- The order of parameters is not significant except:
> If during invocation multiple identical parameters are supplied.
Example:
./$SCRIPT_FULL_NAME -s 5.11-GE-1-MF -s 5.9-GE-3-ST
Result: Only the right-most parameter will be processed (-s 5.9-GE-3-ST).
- The order of parameters is not significant except:
> If during invocation multiple identical parameters are supplied.
Example:
./ge-install-manager -s 5.11-GE-1-MF -s 5.9-GE-3-ST
Result: Only the right-most parameter and argument will be processed (-s 5.9-GE-3-ST).
- Order of operations if multiple unique parameters are supplied:
> NOTE: -h and/or -H, and -fzZ/-fzT will exit irrespective of other parameters
Show help,
Show usage,
Check for latest release,
Show all releases available,
Show release notes for all versions,
Show release notes for a version,
Remove install path,
Remove saved packages (if remove install path is not active),
Uninstall script (remove g_script_cache_path g_script_config_path),
Remove installed version (if remove install path is not active),
Remove saved package (if remove install path is not active),
Download,
Update,
Install,
List installed,
Report install path disk usage,
Report specific version disk usage
Verify
USAGE_HEREDOC
return 0
}
################################################################################
# Purpose: Check the access time of a specified file and determine whether the
# specified interval has elapsed.
# Input: 1 (required) File to check
# 2 (required) Interval in seconds
# Output: None
# Return: 0 (The specified interval has elapsed since the last access, or an error occured)
# 1 (The specified interval has not elapsed since the last access)
CheckAccessTime() {
local -i current_seconds=0 last_check_seconds=0 interval=${2:-0}
local file=${1-}
# If the file doesn't exist, return success (it needs to be created)
[[ ! -f $file ]] && return 0
[[ -z $file || ! -r $file || $interval -lt 1 ]] && { ((g_verbose)) && vMsg "Parameter error (file: $file interval: $interval" r; exit 1; }
((g_verbose)) && vMsg "Checking $file (interval: $interval)"
# Using the access time of file, determine if the specified interval has elapsed or not
current_seconds=$(date +%s)
last_check_seconds=$(stat -c '%X' -- "$file") # --cached=never not available on Ubuntu 20.04.1 LTS
if (( (current_seconds - last_check_seconds) <= interval ))
then
((g_verbose)) && vMsg "Access denied. $(( interval - (current_seconds - last_check_seconds) )) seconds remaining." y
return 1
else
((g_verbose)) && vMsg "Access granted. Access was restored $(( (current_seconds - last_check_seconds) - interval )) seconds ago." g
return 0
fi
return 0
}
################################################################################
# Purpose: Compare and report if the size of the remote version of this script
# does not match the size of the local version of this script.
# Input: None
# Output: None
# Return: 0 (local and remote sizes are equal) Update not available
# 1 (local and remote sizes do not match) Update available
CheckForScriptUpdate() {
local -i local_script_size_bytes=0 remote_script_size_bytes=0
(( g_script_update_check )) || return 0
((g_verbose)) && vMsg "Checking $g_file_script_raw"
if CheckAccessTime "$g_file_script_raw" "$g_script_update_interval"
then
if [[ -f $g_file_script_raw ]]
then
CreateBackup "$g_file_script_raw"
($g_command_rm -- "$g_file_script_raw")
fi
if ! RequestURL "$g_script_raw_url" "$g_file_script_raw"
then
((g_verbose)) && vMsg "RequestURL returned failure" r
[[ -f $g_file_script_raw ]] && ($g_command_rm -- "$g_file_script_raw")
return 0
fi
else
((g_verbose)) && vMsg "CheckAccessTime returned failure" y
fi
# If RequestURL failed, skip the checks
[[ ! -f $g_file_script_raw ]] && return 0
local_script_size_bytes=$(stat -c '%s' "$(realpath "$0" 2> /dev/null)" 2> /dev/null)
remote_script_size_bytes=$(stat -c '%s' "$(realpath "$g_file_script_raw" 2> /dev/null)" 2> /dev/null)
if ((g_verbose))
then
vMsg "Local script size bytes : $local_script_size_bytes"
vMsg "Remote script size bytes: $remote_script_size_bytes"
fi
return $(( (local_script_size_bytes != remote_script_size_bytes) ? 1 : 0 ))
}
################################################################################
# Purpose: Check for minimum required external commands for basic functionality
# and report if any are missing.
# Input: None
# Output: None
# Return: 0 (Success) All required commands were found
# 1 (Failure) Any one required command was not found
# TODO Add checks for optional commands and report features that won't work if
# any are not found.
CheckRequirements() {
local cur_cmd=''
local -i flag_failed=0 flag_apt=0 flag_pacman=0 flag_dnf=0
local -a required_commands=(curl sed tar gzip stat wc touch file)
# Detect package managers for basic missing command advice
command -v pacman > /dev/null && { ((g_verbose)) && vMsg "pacman found" g; flag_pacman=1; }
command -v apt > /dev/null && { ((g_verbose)) && vMsg "apt found" g; flag_apt=1; }
command -v dnf > /dev/null && { ((g_verbose)) && vMsg "dnf found" g; flag_dnf=1; }
while IFS= read -r --
do
# Report the command path if it is found
if [[ ${REPLY,,} == *'is'* ]]
then
((g_verbose)) && vMsg "$REPLY" y
continue
fi
# Report if a command is not found
if [[ ${REPLY,,} == *'not found'* ]]
then
REPLY=${REPLY#*:} # remove script_name:
REPLY=${REPLY#*:} # remove lineno:
# Remove a leading space if found
[[ ${REPLY:0:1} = [[:space:]] ]] && REPLY=${REPLY/#[[:space:]]}
# Remove all but the current command
cur_cmd=${REPLY#*": "}
cur_cmd=${cur_cmd%": "*}
# Give basic install advice depending on which package manager is found
if (( flag_apt == 1 && flag_pacman == 0 && flag_dnf == 0 ))
then
echo "Required $REPLY (sudo apt install $cur_cmd -y)"
elif (( flag_apt == 0 && flag_pacman == 0 && flag_dnf == 1 ))
then
echo "Required $REPLY (sudo dnf install $cur_cmd -y)"
elif (( flag_apt == 0 && flag_pacman == 1 && flag_dnf == 0 ))
then
echo "Required $REPLY (sudo pacman -Syu $cur_cmd)"
else
echo "Required $REPLY"
fi
flag_failed=1
fi
done < <(command -V -- "${required_commands[@]}" 2>&1)
if ((g_verbose))
then
if ((flag_failed))
then
vMsg "One or more requirements not met" r
else
vMsg "All requirements satisfied" g
fi
fi
return $(( flag_failed ? 1 : 0 ))
}
################################################################################
# Purpose: Remove any temporary files/paths created by the script
# Input: None
# Output: None
# Return: 0 (Always) Unless SIGINT was caught (then it's value is carried over)
# which defaults to 0 on my system (varies by environment).
CleanUp() {
local node
# If SIGINT was caught, attempt to prevent the cleanup from being interupted
((g_flag_sigint_caught)) && trap '' ABRT CHLD FPE INT QUIT TERM TSTP USR1 USR2 TRAP CONT HUP
if [[ $g_verbose -eq 0 ]]
then
for node in "$g_temp_base_path/$TEMP_PREFIX"*
do
# Paths
if [[ -d $node ]]
then
if rm -fr -- "$node" > /dev/null
then
((g_verbose)) && vMsg "Removed temporary path: $node" g
else
vMsg "Failed to remove temporary path: $node" r
fi
fi
# Files
if [[ -f $node ]]
then
if rm -f -- "$node" > /dev/null
then
((g_verbose)) && vMsg "Removed temporary file: $node" g
else
vMsg "Failed to remove temporary file: $node" r
fi
fi
done
fi
# Handle the received SIGINT properly by terminating the script/process group with SIGINT
if ((g_flag_sigint_caught))
then
kill -s SIGINT $$ || kill -2 0
fi
return 0
}
################################################################################
# Purpose: When invoked, "clean" a version string stored in the variable version.
# Input: None
# Output: None
# Return: 0 (Success) Always
# NOTE: This function takes advantage of Bash's dynamic scoping
CleanUpVersion() {
# $version must be set in the calling function
[[ -z $version ]] && { ((g_verbose)) && vMsg "version is NULL" r; printf ''; return 1; }
((g_verbose)) && vMsg "Before: \"$version\""
# Remove spaces/tabs
version=${version//[[:space:]]}
# Convert all characters to lower-case
version=${version,,}
# anchored left, remove the string "Proton-" and anything to the left of it
version=${version//'proton-'}
# anchored right, remove the string ".tar.gz" and anything to the right of it
version=${version//'.tar.gz'*}
# Remove any and all colons
version=${version//':'}
# Replace ge with GE
version=${version//'-ge-'/'-GE-'}
# Fix for Proton naming scheme change 030322
version=${version//'ge-proton'/'GE-Proton'}
# Fix for Proton-5.0-GE-1-no-mouse-coord
#version=${version//'-NO-MOUSE-COORD'/'-no-mouse-coord'}
[[ $version = '5.0-GE-1' ]] && version='5.0-GE-1-no-mouse-coord'
((g_verbose)) && vMsg "After: \"$version\""
return 0
}
################################################################################
# Purpose: Backup a file/path in tar.gz format supporting upto a configurable
# number (n) of backups with a basename (sans extension) suffix of _n.
# The newest backup is the lowest index (n) and the oldest backup is
# the highest index (n). The backups are stored in the parent path of
# the file/path to be backed up.
# Input: 1 (required) The file or path to backup
# Output: None
# Return: 0 Success
# 1 Failure
CreateBackup() {
local backup_target=${1-} backup_target_basename backup_target_path backup_index file
local -i max_backups=3 backups_counter=0 flag_rename_backups=0
local -a files_existing_backups
shopt -s nullglob dotglob
[[ -z $backup_target ]] && { ((g_verbose)) && vMsg "Parameter error (NULL)" r; return 1; }
((g_verbose)) && vMsg "Backup requested for $backup_target"
# Check that backup_target is either an existing file or an existing path
if [[ ! -f $backup_target ]]
then
##((g_verbose)) && vMsg "backup_target is not a file"
if [[ ! -d $backup_target ]]
then
((g_verbose)) && vMsg "Parameter error (not a file or a path)" r
return 1
fi
fi
# If a relative file/path was given
if [[ ${backup_target:0:1} != "/" || ${backup_target:0:2} == "./" ]]
then
##((g_verbose)) && vMsg "Resolving relative path"
backup_target=$(realpath -- "$backup_target" 2> /dev/null)
fi
# If backup_target is a file, get the path to it
if [[ ! -d $backup_target && -f $backup_target ]]
then
backup_target_path=${backup_target%/*}
else
# If its a path, get the parent path of backup_target
backup_target_path=$(realpath -- "$(dirname -- "$backup_target" 2> /dev/null)" 2> /dev/null)
fi
backup_target_basename=${backup_target##*/}
# Determine the basename suffix to use {1..$max_backups}
for file in "$backup_target_path/$backup_target_basename"_?.tar.gz
do
if [[ $file =~ ^.*[^_]_[[:digit:]]{1}\.tar\.gz$ ]]
then
backup_index=${file##*_}
backup_index=${backup_index/%.tar.gz}
((g_verbose)) && vMsg "backup_index is $backup_index"
if [[ $backup_index =~ ^[[:digit:]]+$ ]]
then
((backups_counter++))
files_existing_backups+=("$file")
##((g_verbose)) && vMsg "Valid backup file found at $file" g
if ((backup_index == 1))
then
##((g_verbose)) && vMsg "Index 1 found, existing backups will be renamed" y
flag_rename_backups=1
fi
fi
fi
done
##((g_verbose)) && vMsg "Found $backups_counter backups"
if ((flag_rename_backups))
then
backup_index=$backups_counter
if ((backup_index >= max_backups))
then
# Remove the oldest (highest index) backup until max_backups is reached
while ((backup_index >= max_backups))
do
if ($g_command_rm -- "${files_existing_backups[backup_index-1]}")
then
##((g_verbose)) && vMsg "Removed highest index greater than $max_backups: ${files_existing_backups[backup_index-1]}"
backup_index=$((backup_index - 1))
else
vMsg "Failed to remove backup file ${files_existing_backups[backup_index-1]}" r
return 1
fi
done
fi
# Rename existing backups, leaving room for a new index 1 (increment each existing index by +1)
for ((backup_index; backup_index>=1; backup_index--))
do
if ! mv -- "${files_existing_backups[backup_index-1]}" "${files_existing_backups[backup_index-1]/${backup_index}/$((backup_index+1))}"; then
vMsg "Failed to rename backup file: ${files_existing_backups[backup_index-1]}" r
return 1
fi
done
fi
if tar -C "$backup_target_path" -cf "$backup_target_path/${backup_target_basename}_1.tar.gz" -z "$backup_target_basename"
then
((g_verbose)) && vMsg "Created new backup at $backup_target_path/${backup_target_basename}_1.tar.gz" g
return 0
else
((g_verbose)) && vMsg "Backup failed: $backup_target_path/${backup_target_basename}_1.tar.gz" r
return 1
fi
return 0
}
################################################################################
# Purpose: If g_file_script_config is not found, create a default
# Input: None
# Output: None
# Return: 0 Success
# 1 (Failure) mkdir returned failure status.
CreateDefaultConfigFile() {
local rm_command path
# If the config path doesn't exist, create it
path=$(dirname "$g_file_script_config")
if [[ ! -d $path ]]
then
if ! mkdir -p -- "$path"
then
vMsg "Failed to create config file path at $path" r
return 1
fi
fi
cat <<DEFAULT_CONFIG > "$g_file_script_config" # This section is subject to expansion
#
# ${SCRIPT_FULL_NAME} v${SCRIPT_VERSION} Default configuration file
#
# Quick start format:
# #comment
# key=value #comment
#
# Lines begining with an octothorpe "#" are considered comment lines and are ignored.
# Any characters that follow a space and an octothorpe " #" are considered comments.
# Empty lines and lines that begin with space/tab are ignored.
# Lines that contain one or more semi-colon(s) ";" will be ignored.
# Lines that contain potential escape sequences are ignored.
# A key with a null value and a value with a null key are ignored (eg. "key=" and "=value").
#
# Paths (install, cache, and tmp) do not have to exist but
# the script will need write permission to create them for you.
#
# When install_path is set to the special value "auto", the script will
# attempt to auto-detect the Steam installation path.
#
# Environment variables and script global variables will be expanded.
# \$SCRIPT_FULL_NAME is a script global variable that is always set to the basename of the script.
# Setting tmp_path to the same path as install_path is currently not supported (eg. tmp_path=\$g_install_path).
#
# Do not quote variables outside parameter expansions (:+, :-, :=, or :?) unless
# you want the quotes included in the value.
#
DEFAULT_CONFIG
cat <<"DEFAULT_CONFIG" >> "$g_file_script_config" # This section is not subject to expansion
# Default install path
install_path=auto
# Default cache path
cache_path=${XDG_CACHE_HOME:-$HOME/.cache}/$SCRIPT_FULL_NAME
# Default URL used to retrieve 'latest' JSON
latest_version_url=https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases/latest
# Default URL used to retrieve 'releases' JSON
releases_url=https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases
# Default temporary file path
tmp_path=/tmp
DEFAULT_CONFIG
# If trash is found (trash-cli), use it instead of rm
if command -v trash > /dev/null
then
rm_command='trash'
else
rm_command='rm'
fi
cat <<DEFAULT_CONFIG >> "$g_file_script_config" # This section is subject to variable expansion
# Default command used instead of rm (for removing all but temporary files)
# NOTE: Any command and its parameters that support the last parameter being either a file or a path is supported
rm_command=$rm_command
DEFAULT_CONFIG
return 0
}
################################################################################
# Purpose: If the sed script g_file_sed_unminify_script is not found or it's size
# in bytes does not match an expected value, create/overwrite it
# Input: None
# Output: None
# Return: 0 (Success) sed script was created successfully or already exists
# 1 (Failure) Failed to create the sed script at g_file_sed_unminify_script
CreateSedUnminifyJSONscript() {
if [[ ! -f $g_file_sed_unminify_script ]] || (($(stat -c '%s' -- "$g_file_sed_unminify_script") != g_size_bytes_sed_unminify_script))
then
cat <<"END_OF_SED_SCRIPT" > "$g_file_sed_unminify_script"
## begin minimum required for ge-install-manager
# replace: ","
# with: ",newline"
s|","|"\n"|g
## end minimum required for ge-install-manager
END_OF_SED_SCRIPT
# Report that the file was created successfuly and whether or not it is the correct size
if [[ -f $g_file_sed_unminify_script ]]
then
if (($(stat -c '%s' -- "$g_file_sed_unminify_script") == g_size_bytes_sed_unminify_script))
then
((g_verbose)) && vMsg "sed script created at $g_file_sed_unminify_script" g
else
((g_verbose)) && vMsg "sed script at $g_file_sed_unminify_script wrong size" r
($g_command_rm -- "$g_file_sed_unminify_script")
fi
else
vMsg "Failed to create sed script at $g_file_sed_unminify_script" r
return 1
fi
fi
return 0
}
################################################################################
# Purpose: Attempt to auto-detect the Steam installation path and set the
# global variable g_override_default_install_path to it. That variable
# is then read by ParseConfigFile to set g_install_path in the config
# file. If multiple potential install paths are detected the user will
# be prompted to choose one of them. If none/exit is chosen or an abort
# occurs install_path will remain set to auto (which triggers this function
# being called from ParseConfigFile).
# Input: None
# Output: None
# Return: 0 (Success) Always
#
# NOTE: ~/.steam/root/compatibilitytools.d # proton-ge-custom install notes
# /usr/share/steam/compatibilitytools.d
# /usr/local/share/steam/compatibilitytools.d
# flatpak
# ~/.var/app/com.valvesoftware.Steam/data/Steam/compatibilitytools.d/ # proton-ge-custom install notes
# ~/.var/app/com.valvesoftware.Steam/.local/share/Steam
# ~/.var/app/com.valvesoftware.Steam/.steam
# ~/.steam/root/compatibilitytools.d (steam install folder symlink) || ~/.local/share/Steam/compatibilitytools.d
# TODO: Colon-separated global paths in $STEAM_EXTRA_COMPAT_TOOLS_PATHS
# BUG: The script needs write access to the installation path (eg. /usr/share/steam) and the script
# will not run as root.
DetectSteamInstallPath () {
local check_path
local -i i=0
local -a valid_paths=()
local -a search_paths=("$HOME/.steam/root" "${XDG_DATA_HOME:-$HOME/.local/share/Steam}" \
"/usr/share/steam" "/usr/local/share/steam" \
"$HOME/.var/app/com.valvesoftware.Steam/data/Steam" \
"$HOME/.var/app/com.valvesoftware.Steam/.local/share/Steam" \
"$HOME/.var/app/com.valvesoftware.Steam/.steam")
# Report the set status of XDG vars
#
# XDG_DATA_HOME
##if [[ ${XDG_DATA_HOME-unset} != 'unset' ]]
##then
## ((g_verbose)) && vMsg "XDG_DATA_HOME: $XDG_DATA_HOME"
##else
## ((g_verbose)) && vMsg "XDG_DATA_HOME is unset" y
##fi
### XDG_CONFIG_HOME
##if [[ ${XDG_CONFIG_HOME-unset} != 'unset' ]]
##then
## ##((g_verbose)) && vMsg "XDG_CONFIG_HOME: $XDG_CONFIG_HOME"
##else
## ##((g_verbose)) && vMsg "XDG_CONFIG_HOME is unset" y
##fi
### XDG_CACHE_HOME
##if [[ ${XDG_CACHE_HOME-unset} != 'unset' ]]
##then
## ##((g_verbose)) && vMsg "XDG_CACHE_HOME: $XDG_CACHE_HOME"
##else
## ##((g_verbose)) && vMsg "XDG_CACHE_HOME is unset"
##fi
# Search each known possible Steam install path path for steam.sh
# NOTE: If steam.sh is found the path containing it is considered valid
#
# ~/.steam/root/compatibilitytools.d
##((g_verbose)) && vMsg "search_paths: ${#search_paths[@]}"
for check_path in "${search_paths[@]}"
do
##((g_verbose)) && vMsg "Checking $check_path"
if [[ -f $check_path/steam.sh ]]
then
((g_verbose)) && vMsg "steam.sh found in $check_path" g
valid_paths+=("$check_path")
else
((g_verbose)) && vMsg "steam.sh not found in $check_path" y
fi
done
##((g_verbose)) && vMsg "#valid_paths: ${#valid_paths[@]}"
##((g_verbose)) && vMsg "valid_paths[*]: ${valid_paths[*]}"
if ((${#valid_paths[@]} == 0))
then
vMsg "ERROR: Unable to detect Steam installation path" r
printf '%s\n%s\n' \
"You will need to configure install_path manually in the configuration file" \
"(default: ${XDG_CONFIG_HOME:-$HOME/.config}/$SCRIPT_FULL_NAME/$SCRIPT_FULL_NAME.conf)"
g_override_default_install_path='auto'
return 1
# Prefer to use the symlink if two paths were found and one is a link to the other
elif ((${#valid_paths[@]} == 1)) || [[ ${#valid_paths[@]} -eq 2 && ${valid_paths[0]} -ef ${valid_paths[1]} ]]
then
printf '%s\n' "Steam install path detected as ${valid_paths[0]}"
g_override_default_install_path=${valid_paths[0]}
# Multiple paths detected with or without the Steam home link pointing to one of them
elif [[ ${#valid_paths[@]} -gt 1 && ! ${valid_paths[0]} -ef ${valid_paths[1]} ]] || [[ ${#valid_paths[@]} -gt 2 && ${valid_paths[0]} -ef ${valid_paths[1]} ]]
then
echo "Multiple Steam install paths detected:"
for (( i=0; i < ${#valid_paths[@]}; i++ ))
do
echo "($(( i + 1 ))) ${valid_paths[i]}"
done
echo "Choose a path from above or enter exit/quit"
while ((! ${GEIM_TESTS-0} ))
do
read -rp "Enter a number from 1-${#valid_paths[@]}: " </dev/tty
if [[ $REPLY = @(exit|quit) ]]
then
g_override_default_install_path=''
break
fi
REPLY=${REPLY//[!0-9]/} # Remove characters that are not a digit
case $REPLY in
(*[[:digit:]]*)
if ((REPLY < 1 || REPLY >= $(( ${#valid_paths[@]} + 1 ))))
then
echo "Invalid choice"
else
##((g_verbose)) && vMsg "Setting g_override_default_install_path to ${valid_paths[$((REPLY-1))]}"
g_override_default_install_path=${valid_paths[$((REPLY-1))]}
printf '%s\n%s\n%s\n' \
"You have chosen the path $g_override_default_install_path" \
"If that is not correct then change install_path in the configuration file" \
"(default: ${XDG_CONFIG_HOME:-$HOME/.config}/$SCRIPT_FULL_NAME/$SCRIPT_FULL_NAME.conf)"
((g_verbose)) && vMsg "g_override_default_install_path set to $g_override_default_install_path" g
break
fi
;;
(*)
echo "Invalid choice"
;;
esac
done
if [[ -z $g_override_default_install_path ]]
then
printf '%s\n%s\n' \
"You will need to manually set install_path in the configuration file" \
"(default: ${XDG_CONFIG_HOME:-$HOME/.config}/$SCRIPT_FULL_NAME/$SCRIPT_FULL_NAME.conf)"
g_override_default_install_path="auto"
((g_verbose)) && vMsg "g_override_default_install_path set to $g_override_default_install_path" g
fi
fi
return 0
}
################################################################################
# Purpose: Using curl, download a proton-ge-custom release package to a
# temporary path and if the download size matches the expected size
# copy it to g_install_path
# Input: 1 (required) Proton-ge-custom version (in one of the acceptable formats described in usage)
# Output: None
# Return: 0 = (Success) The package was downloaded and extracted to the install
# path successfully.
# 1 = (Failure) QueryGEAttribute returned 1, the downloaded package size
# did not match the expected size, there is not enough
# free space on g_temp_base_path to download the package,
# the server responded Not Found or API limit exceeded,
# copying the package from g_temp_base_path to the install
# path failed, or curl returned failure.
DownloadGEPackage() {
local version=${1-} temp_path temp_package package_download_url
local -i temp_base_path_remaining_bytes=0 install_path_remaining_bytes=0 expected_size_bytes=0 downloaded_package_size_bytes=0
CleanUpVersion
[[ -z $version ]] && { ((g_verbose)) && vMsg "Parameter error (NULL)" r; return 1; }
# Get the download URL from the saved latest/releases JSON
package_download_url=$(QueryGEAttribute "$version" "browser_download_url")
# If QueryGEAttribute returned success but the URL is NULL, abort
[[ -z $package_download_url ]] && return 1
# Get the expected package size in bytes from the saved latest/releases JSON
expected_size_bytes=$(QueryGEAttribute "$version" "size")
# If QueryGEAttribute returned success and size is not only one or more digits, abort
[[ $expected_size_bytes =~ ^[[:digit:]]+$ ]] || return 1
# If a saved package already exists for the requested version
# Proton naming scheme change 030322
if [[ $version == *'GE-Proton'* ]]
then
if [[ -f $g_install_path/$version.tar.gz ]]
then
if (( $(stat -c '%s' "$g_install_path/$version.tar.gz") == expected_size_bytes )) && ((! g_force))
then
echo "A saved package for $version already exists and it is the expected size ($expected_size_bytes bytes)"
return 0
elif (( $(stat -c '%s' "$g_install_path/$version.tar.gz") != expected_size_bytes )) || ((g_force))
then
echo "Force mode is enabled. Existing saved package for $version will be replaced"
if ($g_command_rm -- "$g_install_path/$version.tar.gz")
then
((g_verbose)) && vMsg "Saved package removed: $g_install_path/$version.tar.gz" g
else
vMsg "Failed to remove saved package: $g_install_path/$version.tar.gz" r
return 1
fi
fi
fi
else
if [[ -f $g_install_path/Proton-$version.tar.gz ]]
then
if (( $(stat -c '%s' "$g_install_path/Proton-$version.tar.gz") == expected_size_bytes )) && ((! g_force))
then
echo "A saved package for Proton-$version already exists and it is the expected size ($expected_size_bytes bytes)"
return 0
elif (( $(stat -c '%s' "$g_install_path/Proton-$version.tar.gz") != expected_size_bytes )) || ((g_force))
then
echo "Force mode is enabled. Existing saved package for Proton-$version will be replaced"
if ($g_command_rm -- "$g_install_path/Proton-$version.tar.gz")
then
((g_verbose)) && vMsg "Saved package removed: $g_install_path/Proton-$version.tar.gz" g
else
vMsg "Failed to remove saved package: $g_install_path/Proton-$version.tar.gz" r
return 1
fi
fi
fi
fi
# Create a temporary path for the package
temp_path=$(MkTempPath)
# Define the temporary package name
temp_package=$temp_path/Proton-${version}.tar.gz
# Get the bytes remaining on the temp path
temp_base_path_remaining_bytes=$(SpaceRemaining "$g_temp_base_path" "b")
# Get the bytes remaining on the install path
install_path_remaining_bytes=$(SpaceRemaining "$g_install_path" "b")
# Check if there is enough free space to copy the package to g_install_path
if ((expected_size_bytes > install_path_remaining_bytes))
then
printf "%s\n%s\n" \
"WARNING: Not enough free space at $g_install_path" \
"Need at least $expected_size_bytes bytes but there is only $install_path_remaining_bytes bytes free"
return 1
fi
# If there is not enough free space remaining on the temp_path file system
# TODO: Use a different path as a fallback?
if ((temp_base_path_remaining_bytes < expected_size_bytes))
then
((g_verbose)) && vMsg "$temp_base_path_remaining_bytes bytes remaining on $g_temp_base_path"
printf "%s\n%s\n%s\n" \
"WARNING: Not enough free space on temp_path: $g_temp_base_path" \
"Need at least $expected_size_bytes bytes but there is only $temp_base_path_remaining_bytes bytes free" \
"Free up space or change temp_path in the configuration file"
return 1
fi
# Attempt to retrieve the package with curl
echo "Downloading $package_download_url"
if curl -# -L "$package_download_url" -o "$temp_package" 2>&1
then
# Get the downloaded file size in bytes
downloaded_package_size_bytes=$(stat -c '%s' -- "$temp_package")
((g_verbose)) && vMsg "downloaded_package_size_bytes: $downloaded_package_size_bytes"
# Not found
if ((downloaded_package_size_bytes == 9))
then
vMsg "Server responded \"Not Found\" for version $version" r
CleanUp
return 1
fi
# Github API request rate limit exceeded
if ((downloaded_package_size_bytes == 248))
then