-
Notifications
You must be signed in to change notification settings - Fork 24
/
lug-helper.sh
executable file
·3321 lines (2944 loc) · 146 KB
/
lug-helper.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
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
############################################################################
# Star Citizen Linux Users Group Helper Script
############################################################################
#
# Greetings, Space Penguin!
#
# This script is designed to help you run Star Citizen on Linux.
#
# Please see the project's github repo for more information:
# https://github.com/starcitizen-lug/lug-helper
#
# made with <3
# Author: https://github.com/the-sane
# Contributor: https://github.com/Termuellinator
# Contributor: https://github.com/pstn
# Contributor: https://github.com/gort818
# Contributor: https://github.com/victort
# Contributor: https://github.com/Wrzlprnft
# Contributor: https://github.com/LovingMelody
# Contributor: https://github.com/mactan-sc
# Contributor: https://github.com/ProjectSynchro
# Runner Downloader inspired by:
# https://github.com/richardtatum/sc-runner-updater
#
# License: GPLv3.0
############################################################################
# Check if script is run as root
if [ "$(id -u)" -eq 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 "lug-helper.sh: The required package 'curl' was not found on this system.\n" 1>&2
notify-send "lug-helper" "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 chmod)" ] || [ ! -x "$(command -v sort)" ] || [ ! -x "$(command -v basename)" ] || [ ! -x "$(command -v realpath)" ] || [ ! -x "$(command -v dirname)" ] || [ ! -x "$(command -v cut)" ] || [ ! -x "$(command -v numfmt)" ] || [ ! -x "$(command -v tr)" ] || [ ! -x "$(command -v od)" ] || [ ! -x "$(command -v readlink)" ]; then
# coreutils
# Print to stderr and also try warning the user through notify-send
printf "lug-helper.sh: One or more required packages were not found on this system.\nPlease check that coreutils is installed!\n" 1>&2
notify-send "lug-helper" "One or more required packages were not found on this system.\nPlease check that coreutils is installed!\n" --icon=dialog-warning
exit 1
fi
if [ ! -x "$(command -v xargs)" ]; then
# findutils
# Print to stderr and also try warning the user through notify-send
printf "lug-helper.sh: One or more required packages were not found on this system.\nPlease check that the following findutils packages are installed:\n- xargs\n" 1>&2
notify-send "lug-helper" "One or more required packages were not found on this system.\nPlease check that the following findutils packages are installed:\n- xargs\n" --icon=dialog-warning
exit 1
fi
if [ ! -x "$(command -v cabextract)" ] || [ ! -x "$(command -v unzip)" ]; then
# winetricks dependencies
# Print to stderr and also try warning the user through notify-send
printf "lug-helper.sh: One or more required packages were not found on this system.\nPlease check that the following winetricks dependencies (or winetricks itself) are installed:\n- cabextract\n- unzip\n" 1>&2
notify-send "lug-helper" "One or more required packages were not found on this system.\nPlease check that the following winetricks dependencies (or winetricks itself) are installed:\n- cabextract\n- unzip\n" --icon=dialog-warning
exit 1
fi
# Checks for NixOS for NixOS specific options
if (grep '^NAME=NixOS' /etc/os-release -q 2> /dev/null ); then
is_nixos=1
else
is_nixos=0
fi
######## Config ############################################################
wine_conf="winedir.conf"
game_conf="gamedir.conf"
firstrun_conf="firstrun.conf"
# Use XDG base directories if defined
if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/user-dirs.dirs" ]; then
# Source the user's xdg directories
source "${XDG_CONFIG_HOME:-$HOME/.config}/user-dirs.dirs"
fi
conf_dir="${XDG_CONFIG_HOME:-$HOME/.config}"
data_dir="${XDG_DATA_HOME:-$HOME/.local/share}"
# .config subdirectory
conf_subdir="starcitizen-lug"
# Flatpak lutris directory
lutris_flatpak_dir="$HOME/.var/app/net.lutris.Lutris"
# Lutris native game configs directory
lutris_native_conf_dir="$conf_dir/lutris/games"
# Lutris flatpak game configs directory
lutris_flatpak_conf_dir="$lutris_flatpak_dir/config/lutris/games"
# Helper directory
helper_dir="$(realpath "$0" | xargs -0 dirname)"
# Temporary directory
tmp_dir="$(mktemp -d -t "lughelper.XXXXXXXXXX")"
trap 'rm -r --interactive=never "$tmp_dir"' EXIT
# Set a maximum number of versions to display from each download url
max_download_items=25
######## Game Directories ##################################################
# The game's base directory name
sc_base_dir="StarCitizen"
# The default install location within a WINE prefix:
default_install_path="drive_c/Program Files/Roberts Space Industries"
# The names of the live/ptu/eptu directories
live_dir="LIVE"
ptu_dir="PTU"
eptu_dir="EPTU"
# Location in the WINE prefix where shaders are stored
appdata_path="drive_c/users/$USER/AppData/Local/Star Citizen"
# The shaders subdirectory name
shaders_subdirs=(
"shaders"
"Shaders"
"VulkanShaderCache"
)
# Remaining directory paths are set at the end of the getdirs() function
######## Bundled Files #####################################################
rsi_icon_name="rsi-launcher.png"
wine_launch_script_name="sc-launch.sh"
# Default to files in the Helper directory for a git download
rsi_icon="$helper_dir/$rsi_icon_name"
lutris_install_script="$helper_dir/lib/lutris-starcitizen.json"
wine_launch_script="$helper_dir/lib/$wine_launch_script_name"
# Build our array of search paths, supporting packaged versions of this script
# Search XDG_DATA_DIRS and fall back to /usr/share/
IFS=':' read -r -a data_dirs_array <<< "$XDG_DATA_DIRS:/usr/share/"
# Locate our files in the search array
for searchdir in "${data_dirs_array[@]}"; do
# Check if we've found all our files and break the loop
if [ -f "$rsi_icon" ] && [ -f "$lutris_install_script" ] && [ -f "$wine_launch_script" ]; then
break
fi
# rsi-launcher.png
if [ ! -f "$rsi_icon" ] && [ -f "$searchdir/icons/hicolor/256x256/apps/$rsi_icon_name" ]; then
rsi_icon="$searchdir/icons/hicolor/256x256/apps/$rsi_icon_name"
fi
# lutris-starcitizen.json
if [ ! -f "$lutris_install_script" ] && [ -f "$searchdir/lug-helper/lutris-starcitizen.json" ]; then
lutris_install_script="$searchdir/lug-helper/lutris-starcitizen.json"
fi
# sc-launch.sh
if [ ! -f "$wine_launch_script" ] && [ -f "$searchdir/lug-helper/$wine_launch_script_name" ]; then
wine_launch_script="$searchdir/lug-helper/$wine_launch_script_name"
fi
done
######## Runners ###########################################################
# Lutris native wine runners directory
runners_dir_native="$data_dir/lutris/runners/wine"
# Lutris flatpak wine runners directory
runners_dir_flatpak="$lutris_flatpak_dir/data/lutris/runners/wine"
# URLs for downloading Lutris runners
# Elements in this array must be added in quoted pairs of: "description" "url"
# The first string in the pair is expected to contain the runner description
# The second is expected to contain the api releases url
# ie. "RawFox" "https://api.github.com/repos/rawfoxDE/raw-wine/releases"
runner_sources=(
"Kron4ek" "https://api.github.com/repos/Kron4ek/Wine-Builds/releases"
"GloriousEggroll" "https://api.github.com/repos/GloriousEggroll/wine-ge-custom/releases"
"RawFox" "https://api.github.com/repos/starcitizen-lug/raw-wine/releases"
)
# Set the default runner to install when the system wine doesn't meet requirements
# default_runner_source corresponds to an even number index in runner_sources above
default_runner="wine-9.20-amd64.tar.xz"
default_runner_source=0
######## DXVK ##############################################################
# Lutris native dxvk directory
dxvk_dir_native="$data_dir/lutris/runtime/dxvk"
# Lutris flatpak dxvk directory
dxvk_dir_flatpak="$lutris_flatpak_dir/data/lutris/runtime/dxvk"
# URLs for downloading dxvk versions
# Elements in this array must be added in quoted pairs of: "description" "url"
# The first string in the pair is expected to contain the runner description
# The second is expected to contain the api releases url
# ie. "Sporif Async" "https://api.github.com/repos/Sporif/dxvk-async/releases"
# ie. "Ph42oN GPL+Async" "https://gitlab.com/api/v4/projects/Ph42oN%2Fdxvk-gplasync/releases"
dxvk_sources=(
"doitsujin (standard dxvk)" "https://api.github.com/repos/doitsujin/dxvk/releases"
"Ph42oN GPL+Async" "https://gitlab.com/api/v4/projects/Ph42oN%2Fdxvk-gplasync/releases"
)
######## Requirements ######################################################
# Wine minimum version
wine_required="9.4"
# Lutris minimum version
lutris_required="0.5.17"
# Minimum amount of RAM in GiB
memory_required="16"
# Minimum amount of combined RAM + swap in GiB
memory_combined_required="40"
######## Links / Versions ##################################################
# LUG Wiki
lug_wiki="https://starcitizen-lug.github.io"
# NixOS section in Wiki
lug_wiki_nixos="https://github.com/starcitizen-lug/knowledge-base/wiki/Tips-and-Tricks#nixos"
# RSI Installer version and url
rsi_installer="RSI Launcher-Setup-2.1.0.exe"
rsi_installer_url="https://install.robertsspaceindustries.com/rel/2/$rsi_installer"
# Winetricks download url
winetricks_url="https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks"
# Github repo and script version info
repo="starcitizen-lug/lug-helper"
releases_url="https://github.com/$repo/releases"
current_version="v3.4"
############################################################################
############################################################################
############################################################################
# Try to execute a supplied command as root
# Expects one string argument
try_exec() {
# This function expects one string argument
if [ "$#" -lt 1 ]; then
printf "\nScript error: The try_exec() function expects an argument. Aborting.\n"
read -n 1 -s -p "Press any key..."
exit 0
fi
# Use pollkit's pkexec for gui authentication with a fallback to sudo
if [ -x "$(command -v pkexec)" ]; then
pkexec sh -c "$1"
# Check the exit status
if [ "$?" -eq 126 ] || [ "$?" -eq 127 ]; then
# User cancel or error
debug_print continue "pkexec returned an error. Falling back to sudo..."
else
# Successful execution, return here
return 0
fi
fi
# Fall back to sudo if pkexec is unavailable or returned an error
if [ -x "$(command -v sudo)" ]; then
sudo sh -c "$1"
# Check the exit status
if [ "$?" -eq 1 ]; then
# Error
return 1
fi
else
# We don't know how to perform this operation with elevated privileges
printf "\nNeither Polkit nor sudo appear to be installed. Unable to execute the command with the required privileges.\n"
return 1
fi
return 0
}
# 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%s\n" "$2"
;;
"exit")
# Write an error to stderr and exit
printf "%s\n" "lug-helper.sh: $2" 1>&2
read -n 1 -s -p "Press any key..."
exit 1
;;
*)
printf "%s\n" "lug-helper.sh: Unknown argument provided to debug_print function. Aborting." 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 at least 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" "--no-wrap" "--text=")
shift 1 # drop the message type argument and shift up to the text
;;
"warning")
# warning message
# call format: message warning "text to display"
margs=("--warning" "--text=")
shift 1 # drop the message type argument and shift up to the text
;;
"error")
# error message
# call format: message error "text to display"
margs=("--error" "--text=")
shift 1 # drop the message type argument and shift up to the text
;;
"question")
# question
# call format: if message question "question to ask?"; then...
margs=("--question" "--text=")
shift 1 # drop the message type argument and shift up to the text
;;
"options")
# formats the buttons with two custom options
# call format: if message options left_button_name right_button_name "which one do you want?"; then...
# The right button returns 0 (ok), the left button returns 1 (cancel)
if [ "$#" -lt 4 ]; then
debug_print exit "Script error: The options type in the message function expects four arguments. Aborting."
fi
margs=("--question" "--cancel-label=$2" "--ok-label=$3" "--text=")
shift 3 # drop the type and button label arguments and shift up to the text
;;
*)
debug_print exit "Script Error: Invalid message type passed to the message function. Aborting."
;;
esac
# Display the message
zenity "${margs[@]}""$@" --width="420" --title="Star Citizen LUG Helper"
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"
printf "\n$2\n\n"
if [ "$cmd_line" != "true" ]; then
# Don't pause if we've been invoked via command line arguments
read -n 1 -s -p "Press any key..."
fi
;;
"warning")
# warning message
# call format: message warning "text to display"
printf "\n$2\n\n"
read -n 1 -s -p "Press any key..."
;;
"error")
# error message. Does not clear the screen
# call format: message error "text to display"
printf "\n$2\n\n"
read -n 1 -s -p "Press any key..."
;;
"question")
# question
# call format: if message question "question to ask?"; then...
printf "\n$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
;;
"options")
# Choose from two options
# call format: if message options left_button_name right_button_name "which one do you want?"; then...
printf "\n$4\n1: $3\n2: $2\n"
while read -p "[1/2]: " option; do
case "$option" in
1*)
return 0
;;
2*)
return 1
;;
*)
printf "Please type '1' or '2'\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 the following variables:
# - 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 string "menu_type" should contain either "radiolist" or "checklist".
# - The string "cancel_label" should contain the text of the cancel button.
#
# 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 before calling the menu function. Aborting."
elif [ "${#menu_actions[@]}" -eq 0 ]; then
debug_print exit "Script error: The array 'menu_actions' was not set before calling the menu function. Aborting."
elif [ -z "$menu_text_zenity" ]; then
debug_print exit "Script error: The string 'menu_text_zenity' was not set before calling the menu function. Aborting."
elif [ -z "$menu_text_terminal" ]; then
debug_print exit "Script error: The string 'menu_text_terminal' was not set before calling the menu function. Aborting."
elif [ -z "$menu_height" ]; then
debug_print exit "Script error: The string 'menu_height' was not set before calling the menu function. Aborting."
elif [ "$menu_type" != "radiolist" ] && [ "$menu_type" != "checklist" ]; then
debug_print exit "Script error: Unknown menu_type in menu() function. Aborting."
elif [ -z "$cancel_label" ]; then
debug_print exit "Script error: The string 'cancel_label' was not set before 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"
unset zen_options
for (( i=0; i<"${#menu_options[@]}"-1; i++ )); do
if [ "$i" -eq 0 ]; then
# Set the first element
if [ "$menu_type" = "radiolist" ]; then
# Select the first radio button by default
zen_options=("TRUE")
else
# Don't select the first checklist item
zen_options=("FALSE")
fi
else
# Deselect all remaining items
zen_options+=("FALSE")
fi
# Add the menu list item
zen_options+=("${menu_options[i]}")
done
# Display the zenity radio button menu
choice="$(zenity --list --"$menu_type" --width="510" --height="$menu_height" --text="$menu_text_zenity" --title="Star Citizen LUG Helper" --hide-header --cancel-label "$cancel_label" --column="" --column="Option" "${zen_options[@]}")"
# Match up choice with an element in menu_options
matched="false"
if [ "$menu_type" = "radiolist" ]; then
# Loop through the options array to match the chosen option
for (( i=0; i<"${#menu_options[@]}"; i++ )); do
if [ "$choice" = "${menu_options[i]}" ]; then
# Execute the corresponding action for a radiolist menu
${menu_actions[i]}
matched="true"
break
fi
done
elif [ "$menu_type" = "checklist" ]; then
# choice will be empty if no selection was made
# Unfortunately, it's also empty when the user presses cancel
# so we can't differentiate between those two states
# Convert choice string to array elements for checklists
IFS='|' read -r -a choices <<< "$choice"
# Fetch the function to be called
function_call="$(echo "${menu_actions[0]}" | awk '{print $1}')"
# Loop through the options array to match the chosen option(s)
unset arguments_array
for (( i=0; i<"${#menu_options[@]}"; i++ )); do
for (( j=0; j<"${#choices[@]}"; j++ )); do
if [ "${choices[j]}" = "${menu_options[i]}" ]; then
arguments_array+=("$(echo "${menu_actions[i]}" | awk '{print $2}')")
matched="true"
fi
done
done
# Call the function with all matched elements as arguments
if [ "$matched" = "true" ]; then
$function_call "${arguments_array[@]}"
fi
fi
# 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
clear
# Execute the corresponding action
${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"
}
# Get paths to the user's wine prefix, game directory, and a backup directory
# Returns 3 if the user was asked to select new directories
getdirs() {
# Sanity checks
if [ ! -d "$conf_dir" ]; then
message error "Config directory not found. The Helper is unable to proceed.\n\n$conf_dir"
return 1
fi
if [ ! -d "$conf_dir/$conf_subdir" ]; then
mkdir -p "$conf_dir/$conf_subdir"
fi
# Initialize a return value
retval=0
# Check if the config files already exist
if [ -f "$conf_dir/$conf_subdir/$wine_conf" ]; then
wine_prefix="$(cat "$conf_dir/$conf_subdir/$wine_conf")"
if [ ! -d "$wine_prefix" ]; then
debug_print continue "The saved wine prefix does not exist, ignoring."
wine_prefix=""
rm --interactive=never "${conf_dir:?}/$conf_subdir/$wine_conf"
fi
fi
if [ -f "$conf_dir/$conf_subdir/$game_conf" ]; then
game_path="$(cat "$conf_dir/$conf_subdir/$game_conf")"
# Note: We check for the parent dir here because the game may not have been fully installed yet
# which means sc_base_dir may not yet have been created. But the parent RSI dir must exist
if [ ! -d "$(dirname "$game_path")" ] || [ "$(basename "$game_path")" != "$sc_base_dir" ]; then
debug_print continue "Unexpected game path found in config file, ignoring."
game_path=""
rm --interactive=never "${conf_dir:?}/$conf_subdir/$game_conf"
fi
fi
# If we don't have the directory paths we need yet,
# ask the user to provide them
if [ -z "$wine_prefix" ] || [ -z "$game_path" ]; then
message info "At the next screen, please select the directory where you installed Star Citizen (your Wine prefix)\nIt will be remembered for future use.\n\nDefault install path: ~/Games/star-citizen"
if [ "$use_zenity" -eq 1 ]; then
# Using Zenity file selection menus
# Get the wine prefix directory
while [ -z "$wine_prefix" ]; do
wine_prefix="$(zenity --file-selection --directory --title="Select your Star Citizen Wine prefix directory" --filename="$HOME/Games/star-citizen" 2>/dev/null)"
if [ "$?" -eq -1 ]; then
message error "An unexpected error has occurred. The Helper is unable to proceed."
return 1
elif [ -z "$wine_prefix" ]; then
# User clicked cancel
message warning "Operation cancelled.\nNo changes have been made to your game."
return 1
fi
if ! message question "You selected:\n\n$wine_prefix\n\nIs this correct?"; then
wine_prefix=""
fi
done
# Get the game path
if [ -z "$game_path" ]; then
if [ -d "$wine_prefix/$default_install_path" ]; then
# Default: prefix/drive_c/Program Files/Roberts Space Industries/StarCitizen
game_path="$wine_prefix/$default_install_path/$sc_base_dir"
else
message info "Unable to detect the default game install path!\n\n$wine_prefix/$default_install_path/$sc_base_dir\n\nDid you change the install location in the RSI Setup?\nDoing that is generally a bad idea but, if you are sure you want to proceed,\nselect your '$sc_base_dir' game directory on the next screen"
while true; do
game_path="$(zenity --file-selection --directory --title="Select your Star Citizen directory" --filename="$wine_prefix/$default_install_path" 2>/dev/null)"
if [ "$?" -eq -1 ]; then
message error "An unexpected error has occurred. The Helper is unable to proceed."
return 1
elif [ -z "$game_path" ]; then
# User clicked cancel or something else went wrong
message warning "Operation cancelled.\nNo changes have been made to your game."
return 1
elif [ "$(basename "$game_path")" != "$sc_base_dir" ]; then
message warning "You must select the base game directory named '$sc_base_dir'\n\nie. [prefix]/drive_c/Program Files/Roberts Space Industries/StarCitizen"
else
# All good
break
fi
done
fi
fi
else
# No Zenity, use terminal-based menus
clear
# Get the wine prefix directory
if [ -z "$wine_prefix" ]; then
printf "Enter the full path to your Star Citizen Wine prefix directory (case sensitive)\n"
printf "ie. /home/USER/Games/star-citizen\n"
while read -rp ": " wine_prefix; do
if [ ! -d "$wine_prefix" ]; then
printf "That directory is invalid or does not exist. Please try again.\n\n"
else
break
fi
done
fi
# Get the game path
if [ -z "$game_path" ]; then
if [ -d "$wine_prefix/$default_install_path/s" ]; then
# Default: prefix/drive_c/Program Files/Roberts Space Industries/StarCitizen
game_path="$wine_prefix/$default_install_path/$sc_base_dir"
else
printf "\nUnable to detect the default game install path!\nDid you change the install location in the RSI Setup?\nDoing that is generally a bad idea but, if you are sure you want to proceed...\n\n"
printf "Enter the full path to your $sc_base_dir installation directory (case sensitive)\n"
printf "ie. /home/USER/Games/star-citizen/drive_c/Program Files/Roberts Space Industries/StarCitizen\n"
while read -rp ": " game_path; do
if [ ! -d "$game_path" ]; then
printf "That directory is invalid or does not exist. Please try again.\n\n"
elif [ "$(basename "$game_path")" != "$sc_base_dir" ]; then
printf "You must enter the full path to the directory named '%s'\n\n" "$sc_base_dir"
else
break
fi
done
fi
fi
fi
# Set a return code to indicate to other functions in this script that the user had to select new directories here
retval=3
fi
# Save the paths to config files
if [ ! -f "$conf_dir/$conf_subdir/$wine_conf" ]; then
echo "$wine_prefix" > "$conf_dir/$conf_subdir/$wine_conf"
fi
if [ ! -f "$conf_dir/$conf_subdir/$game_conf" ]; then
echo "$game_path" > "$conf_dir/$conf_subdir/$game_conf"
fi
######## Set remaining directory paths #####################################
# $game_version is set in the version_menu() function
############################################################################
# The game's user directory
if [ -d "$game_path/$game_version/USER/Client" ]; then
# Backwards compatibility for older installs
user_dir="$game_path/$game_version/USER/Client/0"
else
user_dir="$game_path/$game_version/user/client/0"
fi
# The location within the USER directory to which the game exports keybinds
keybinds_dir="$user_dir/Controls/Mappings"
# Shaders directory
shaders_dir="$wine_prefix/$appdata_path"
# Custom characters directory
custom_characters_dir="$user_dir/CustomCharacters"
# dxvk cache file
dxvk_cache="$game_path/$game_version/StarCitizen.dxvk-cache"
# Where to store backed up keybinds
backup_path="$conf_dir/$conf_subdir"
return "$retval"
}
############################################################################
######## begin preflight check functions ###################################
############################################################################
# Check that the system is optimized for Star Citizen
# Accepts an optional string argument, "lutris" or "wine"
# This argument is used by the install functions to indicate which
# Preflight Check functions should be called and cause the Preflight Check
# to only output problems that must be fixed
preflight_check() {
# Initialize variables
unset preflight_pass
unset preflight_fail
unset preflight_action_funcs
unset preflight_actions
unset preflight_fix_results
unset preflight_manual
unset preflight_followup
unset preflight_fail_string
unset preflight_pass_string
unset preflight_fix_results_string
unset install_mode
retval=0
# Capture optional argument that determines which install function called us
install_mode="$1"
# Check the optional argument for valid values
if [ -n "$install_mode" ] && [ "$install_mode" != "wine" ] && [ "$install_mode" != "lutris" ]; then
debug_print exit "Script error: Unexpected argument passed to the preflight_check function. Aborting."
fi
# Call the optimization functions to perform the checks
if [ "$install_mode" != "wine" ]; then
# Don't check for lutris if called from the wine install function
lutris_check
fi
wine_check
memory_check
avx_check
mapcount_check
filelimit_check
# Populate info strings with the results and add formatting
if [ "${#preflight_fail[@]}" -gt 0 ]; then
# Failed checks
preflight_fail_string="Failed Checks:"
for (( i=0; i<"${#preflight_fail[@]}"; i++ )); do
if [ "$i" -eq 0 ]; then
preflight_fail_string="$preflight_fail_string\n- ${preflight_fail[i]//\\n/\\n }"
else
preflight_fail_string="$preflight_fail_string\n\n- ${preflight_fail[i]//\\n/\\n }"
fi
done
# Add extra newlines if there are also passes to report
if [ "${#preflight_pass[@]}" -gt 0 ]; then
preflight_fail_string="$preflight_fail_string\n\n"
fi
fi
if [ "${#preflight_pass[@]}" -gt 0 ]; then
# Passed checks
preflight_pass_string="Passed Checks:"
for (( i=0; i<"${#preflight_pass[@]}"; i++ )); do
preflight_pass_string="$preflight_pass_string\n- ${preflight_pass[i]//\\n/\\n }"
done
fi
for (( i=0; i<"${#preflight_manual[@]}"; i++ )); do
# Instructions for manually fixing problems
if [ "$i" -eq 0 ]; then
preflight_manual_string="${preflight_manual[i]}"
else
preflight_manual_string="$preflight_manual_string\n\n${preflight_manual[i]}"
fi
done
# Format a message heading
message_heading="Preflight Check Results"
if [ "$use_zenity" -eq 1 ]; then
message_heading="<big><b>$message_heading</b></big>"
fi
# Display the results of the preflight check
if [ -z "$preflight_fail_string" ]; then
# If install_mode was set by an install function, we won't bother the user when all checks pass
if [ -z "$install_mode" ]; then
# All checks pass!
message info "$message_heading\n\nYour system is optimized for Star Citizen!\n\n$preflight_pass_string"
fi
return 0
else
if [ "${#preflight_action_funcs[@]}" -eq 0 ]; then
# We have failed checks, but they're issues we can't automatically fix
message warning "$message_heading\n\n$preflight_fail_string$preflight_pass_string"
elif message question "$message_heading\n\n$preflight_fail_string$preflight_pass_string\n\nWould you like these configuration issues to be fixed for you?"; then
# We have failed checks, but we can fix them for the user
# Call functions to build fixes for any issues found
for (( i=0; i<"${#preflight_action_funcs[@]}"; i++ )); do
${preflight_action_funcs[i]}
done
# Populate a string of actions to be executed
for (( i=0; i<"${#preflight_actions[@]}"; i++ )); do
if [ "$i" -eq 0 ]; then
preflight_actions_string="${preflight_actions[i]}"
else
preflight_actions_string="$preflight_actions_string; ${preflight_actions[i]}"
fi
done
# Execute the actions set by the functions
if [ -n "$preflight_actions_string" ]; then
# Try to execute the actions as root
try_exec "$preflight_actions_string"
if [ "$?" -eq 1 ]; then
message error "Authentication failed or there was an error.\nSee terminal for more information.\n\nReturning to main menu."
return 0
fi
fi
# Call any followup functions
for (( i=0; i<"${#preflight_followup[@]}"; i++ )); do
${preflight_followup[i]}
done
# Populate the results string
for (( i=0; i<"${#preflight_fix_results[@]}"; i++ )); do
if [ "$i" -eq 0 ]; then
preflight_fix_results_string="${preflight_fix_results[i]}"
else
preflight_fix_results_string="$preflight_fix_results_string\n\n${preflight_fix_results[i]}"
fi
done
# Display the results
message info "$preflight_fix_results_string"
else
# User declined to automatically fix configuration issues
# Show manual configuration options
if [ -n "$preflight_manual_string" ]; then
message info "$preflight_manual_string"
fi
fi
return 1
fi
}
# Check the installed lutris version
lutris_check() {
lutris_detect
if [ "$lutris_installed" = "false" ]; then
preflight_fail+=("Lutris does not appear to be installed.\nFor non-Lutris installs, this may be ignored.")
return 1
fi
# Check the native lutris version number
if [ "$lutris_native" = "true" ]; then
lutris_current="$(lutris -v 2>/dev/null | awk -F '-' '{print $2}')"
if [ -z "$lutris_current" ]; then
preflight_fail+=("Unable to detect Lutris version info.\nVersion $lutris_required or newer is required.")
elif [ "$lutris_required" != "$lutris_current" ] &&
[ "$lutris_current" = "$(printf "%s\n%s" "$lutris_current" "$lutris_required" | sort -V | head -n1)" ]; then
preflight_fail+=("Lutris is out of date.\nVersion $lutris_required or newer is required.")
else
preflight_pass+=("Lutris is installed and sufficiently up to date.")
fi
fi
# Check the flatpak lutris version number
if [ "$lutris_flatpak" = "true" ]; then
lutris_current="$(flatpak run net.lutris.Lutris -v 2>/dev/null | awk -F '-' '{print $2}')"
if [ -z "$lutris_current" ]; then
preflight_fail+=("Unable to detect Flatpak Lutris version info.\nVersion $lutris_required or newer is required.")
elif [ "$lutris_required" != "$lutris_current" ] &&
[ "$lutris_current" = "$(printf "%s\n%s" "$lutris_current" "$lutris_required" | sort -V | head -n1)" ]; then
preflight_fail+=("Flatpak Lutris is out of date.\nVersion $lutris_required or newer is required.")
else
preflight_pass+=("Flatpak Lutris is installed and sufficiently up to date.")
fi
fi
}
# Detect if lutris is installed
lutris_detect() {
lutris_installed="false"
lutris_native="false"
lutris_flatpak="false"
# Detect native lutris
if [ -x "$(command -v lutris)" ]; then
lutris_installed="true"
lutris_native="true"
fi
# Detect flatpak lutris
if [ -x "$(command -v flatpak)" ] && flatpak list --app | grep -q Lutris; then
lutris_installed="true"
lutris_flatpak="true"
fi
}
# Check the system Wine version
# Tells the preflight check whether or not wine is installed
# Additionally sets system_wine_ok if system wine meets the minimum version requirement
wine_check() {
# Initialize variable
system_wine_ok="false"
# Is wine installed?
if [ ! -x "$(command -v wine)" ]; then
preflight_fail+=("Wine does not appear to be installed.\nPlease refer to our Quick Start Guide:\n$lug_wiki")
return 1
else
preflight_pass+=("Wine is installed on your system.")
fi
# Get the current wine version
wine_current="$(wine --version 2>/dev/null | awk '{print $1}' | awk -F '-' '{print $2}')"
# Check it against the required version
if [ -z "$wine_current" ]; then
system_wine_ok="false"
elif [ "$wine_required" != "$wine_current" ] &&
[ "$wine_current" = "$(printf "%s\n%s" "$wine_current" "$wine_required" | sort -V | head -n1)" ]; then
system_wine_ok="false"
else
system_wine_ok="true"
fi
# If system wine passes the above checks, also check for the new wow64 mode that currently does not work
if [ "$system_wine_ok" = "true" ]; then
# Get paths to wine and wineserver binaries
wine_bin="$(command -v wine)"
wineserver_bin="$(command -v wineserver)"
wineboot_bin="$(command -v wineboot)"
# Determine the architecture of wine binary
wine_bin_arch="$(get_file_arch "${wine_bin}")"
# If unable to determine architecture, attempt alternative methods
if [ -z "${wine_bin_arch}" ]; then
if [ -x "${wineboot_bin}" ]; then
wine_bin_dir="$(dirname "$(readlink -f "${wineboot_bin}" 2>/dev/null)" 2>/dev/null)"
if [ -x "${wine_bin_dir}/wine" ]; then
wine_bin_arch="$(get_file_arch "${wine_bin_dir}/wine")"
fi