forked from MadByteDE/SPT-Linux-Guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspt-additions
More file actions
executable file
·1697 lines (1437 loc) · 61.2 KB
/
spt-additions
File metadata and controls
executable file
·1697 lines (1437 loc) · 61.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
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
# # # # # # # # #
# SPT-ADDITIONS #
# # # # # # # # #
# exit codes:
# 1: general error | 10: -d check failed | 11: -f check failed | 12: empty string | 13: m_7z failed
# 14: case char mismatch
# We don't want to run as root
if [[ "$( id -u )" -eq 0 ]]; then
echo "This script is not supposed to be run as root!"
exit 1
fi
# Shell options
shopt -s extglob
# Make sure to throw an error and exit on SIGINT
trap int INT; int() { warn "Interrupt received" && m_exit; }
TITLE="spt-additions"; AUTHOR="MadByte"; LICENSE="MIT"
VERSION="0.7.12"; DATE="2025-10-13"
# ANSI codes
BOLD="\e[1m"; UNDERLINE="\e[2m"; RESET="\e[0m"
RED="\e[31m"; GREEN="\e[32m"; BLUE="\e[36m"
YELLOW="\e[33m"; GRAY="\e[90m"
# System directories
readonly DATA_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}"
readonly CACHE_HOME="${XDG_CACHE_HOME:-${HOME}/.cache}"
readonly CONFIG_HOME="${XDG_CONFIG_HOME:-${HOME}/.config}"
readonly DATA_DIR="${DATA_HOME}/${TITLE}"
readonly CACHE_DIR="${CACHE_HOME}/${TITLE}"
readonly CONFIG_DIR="${CONFIG_HOME}/${TITLE}"
readonly RUNTIME_DIR="${DATA_DIR}/runtime"
readonly TMP_DIR="$( mktemp -d "/tmp/spt-XXXXX" )"
readonly ICO_DIR="${DATA_HOME}/icons/hicolor/256x256/apps"
readonly APP_DIR="${DATA_HOME}/applications"
# Default setting variables
readonly DEFAULT_PFX_DIR="${HOME}/Games/tarkov"
readonly DEFAULT_SPT_DIR="drive_c/SPTarkov"
readonly DEFAULT_INSTALL_MODE="native"
declare -A FAUGUS CONFIG ENV CACHE URL
FAUGUS[config_dir]="${CONFIG_HOME}/faugus-launcher"
FAUGUS[flatpak_config_dir]="${HOME}/.var/app/io.github.Faugus.faugus-launcher/config/faugus-launcher"
FAUGUS[json_path]="${FAUGUS[config_dir]}/games.json"
FAUGUS[flatpak_json_path]="${FAUGUS[flatpak_config_dir]}/games.json"
readonly -A FAUGUS
# File path variables
readonly LOG_PATH="${CACHE_DIR}/installer.log"
readonly SCRIPT_PATH="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" && pwd )"
readonly UMU_PATH=$( command -v umu-run || echo "${RUNTIME_DIR}/umu-run" )
readonly CONFIG_PATH="${CONFIG_DIR}/app.conf"
readonly ENV_PATH="${CONFIG_DIR}/env.conf"
readonly MOD_PATH="${CACHE_DIR}/SPT"
readonly PATCHER_PATH="${CACHE_DIR}/patcher"
readonly MOD_JSON_PATH="${CACHE_DIR}/release.json"
readonly PATCHER_JSON_PATH="${CACHE_DIR}/mirrors.json"
# Libraries / Tools
URL[umu-launcher]="https://github.com/Open-Wine-Components/umu-launcher/releases/download/1.2.9/umu-launcher-1.2.9-zipapp.tar"
URL[7zzs]="https://github.com/ip7z/7zip/releases/download/25.01/7z2501-linux-x64.tar.xz"
URL[hpatchz]="https://github.com/sisong/HDiffPatch/releases/download/v4.11.1/hdiffpatch_v4.11.1_bin_linux64.zip"
URL[jq]="https://github.com/jqlang/jq/releases/download/jq-1.8.1/jq-linux-amd64"
URL[xxd]="http://ftp.de.debian.org/debian/pool/main/v/vim/xxd_9.1.1230-2_amd64.deb"
# Installers
URL[bsg-launcher]="https://prod.escapefromtarkov.com/launcher/download"
URL[spt-installer]="https://ligma.waffle-lord.net/SPTInstaller.exe"
URL[aspnet-windows]="https://builds.dotnet.microsoft.com/dotnet/aspnetcore/Runtime/9.0.9/aspnetcore-runtime-9.0.9-win-x64.exe"
# Scripts
URL[installer-script]="https://raw.githubusercontent.com/MadByteDE/SPT-Linux-Guide/main/scripts/spt-additions"
URL[server-script]="https://raw.githubusercontent.com/MadByteDE/SPT-Linux-Guide/main/scripts/launch-server.sh"
# Icons
URL[bsg-launcher-ico]="https://cdn2.steamgriddb.com/icon/33686c2d8930be81c843ffb7d4312605/32/256x256.png"
URL[spt-launcher-ico]="https://cdn2.steamgriddb.com/icon_thumb/ddd4f86cd0f978e85155cfa6c9f94e0c.png"
URL[spt-server-ico]="https://cdn2.steamgriddb.com/icon_thumb/9f7431ea593b8e57401c08f40adc6e34.png"
# Metadata
URL[patcher-json]="https://slugma.waffle-lord.net/mirrors.json"
URL[mod-json]="https://spt-releases.modd.in/release.json"
# Links
URL[guide-repo]="https://github.com/MadByteDE/SPT-Linux-Guide"
URL[discord]="https://discord.com/invite/Xn9msqQZan"
URL[forge]="https://forge.sp-tarkov.com"
readonly -A URL
# # # # # # # # # #
# Alias functions #
# # # # # # # # # #
m_exit() {
local status=${1:-$?}
m_rmdir "${TMP_DIR}"
exit "${status}"
}
m_chmod() { chmod "$@" &>> "${LOG_PATH}" || err "Command \"chmod $*\" failed" "$?"; }
m_mkdir() { mkdir -p "$@" &>> "${LOG_PATH}" || err "Command \"mkdir $*\" failed" "$?"; }
m_ls() { ls "$@" 2>> "${LOG_PATH}" || err "Command \"ls $*\" failed" "$?"; }
m_mv() { mv "$@" &>> "${LOG_PATH}" || err "Command \"mv $*\" failed" "$?"; }
m_curl() { curl --connect-timeout 30 -f "$@" || err "Command \"curl $*\" failed" "$?"; }
m_umu() { "${UMU_PATH}" "$@" 2>> "${LOG_PATH}" || err "Command \"umu-run $*\" failed" "$?"; }
m_rm() {
local path="$(realpath -m "${1%/}")" && shift
[[ -d "${path}" ]] && err "Cannot remove directories. Use \"m_rmdir\" instead."
rm "${path}" "$@" &>> "${LOG_PATH}" || err "Command \"rm $*\" failed"
}
m_rmdir() {
local path="$(realpath -m "${1%/}")" && shift
[[ -f "${path}" ]] && warn "Cannot remove single files. Use \"m_rm\" instead." && exit 1
case "${path}" in
*"${CONFIG[prefix_dir]}"*|*"${DATA_DIR}"*|*"${CACHE_DIR}"*|*"${CONFIG_DIR}"*|*"/tmp/spt"*)
if [[ ! -d "${path}" ]]; then return; fi
rm -r "${path}" "$@" || exit 1
;;
*) warn "Failed to remove \"${path}\": Invalid directory path"; exit 1 ;;
esac
}
m_cp() {
local source_path="${1}"; local target_path="${2}"
# Check if the target path is inside a valid directory
case "${target_path}" in
*"${CONFIG[prefix_dir]}"* | *"${CACHE_DIR}"* | *"${DATA_DIR}"* | *"${HOME}/bin"* | *"${HOME}/.local/bin"*) ;;
*) err "Invalid target directory \"${target_path}\"" ;;
esac
# Create missing directories
m_mkdir "${target_path}"
local files_total progress=1
files_total=$( find "${source_path}" \( -type f -printf x \) | wc -c )
if [[ -d "${source_path}" ]]; then
# Iterate files & copy to target directory
echo; find "${source_path}" \( -type f \) -print0 | while IFS= read -r -d '' source; do
local filename="${source/#$source_path}"
local output="${target_path}/${filename}"
local progress_string="[${progress}/${files_total}]"
msg -o "${progress_string} Copying: ${filename##*/}"
[[ ! -d "${output%/*}" ]] && m_mkdir "${output%/*}"
cp --reflink=auto "${source}" "${output}" &>> "${LOG_PATH}" || err "Command \"cp $*\" failed" "$?"
progress=$((progress+1))
done
elif [[ -f "${source_path}" ]]; then
cp --reflink=auto "${source_path}" "${target_path}" &>> "${LOG_PATH}" || err "Command \"cp $*\" failed" "$?"
fi
}
m_7z() {
archive_path="$(realpath -m "${1%/}")"; local target_path="$(realpath -m "${2%/}")"
filename="${archive_path##*/}"
7zzs x -aoa "${archive_path}" -o"${target_path}" 1>/dev/null
[[ "$?" != 0 ]] && err "Failed to extract \"${filename}\""
}
# # # # # # # # # # #
# Helper functions #
# # # # # # # # # # #
msg() {
local mode filtered_str
case "$1" in
# Override mode
-o) mode="o"; shift ;;
esac
local output="$*"
filtered_str=$( echo -e "${output}" | sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g' )
# Print to terminal
case ${NO_ANSI} in
1) echo "${filtered_str}" ;;
*)
case ${mode} in
o) echo -e "\r\033[1A\033[0K│ ${output}" ;;
*) echo -e "│ ${output}" ;;
esac
;;
esac
# Write to log file
if [[ -d "${CACHE_DIR}" ]] && [[ "${mode}" != "o" ]] ; then
echo "[$TITLE] ${filtered_str}" &>> "${LOG_PATH}"
fi
}
warn() {
msg "${YELLOW}Warn: ${RESET}$1"
}
err() {
local message="$1"; local status="${2:-"1"}"
local pfx="${BOLD}${RED}ERROR ${FUNCNAME[1]}: ${RESET}"
msg "${pfx}${message} (Exit code: ${status})" 1>&2
msg "${pfx}See \"${LOG_PATH}\" for more details.${RESET}" 1>&2
m_exit "$status"
}
yesno() {
msg "${BOLD}${BLUE}[Q] $*${RESET} [y/n] "
if [[ $NO_PROMPT == 1 ]]; then
msg "NO_PROMPT variable set - returning 0"
return 0
fi
while true; do
read -r -p "│ > " yn
case $yn in
[Yy]*) return 0 ;;
[Nn]*) return 1 ;;
esac
done
}
read_input() {
read -e -r -p "│ > " input; printf "$input\n"
}
wrap_run() {
printf "%s\n" "$( "$@" )"; local status=$?
return $status
}
set_value() {
local array_name="${1}"
local keyval="${2}" || err "Missing argument: set_value [array_name] [keyval]"
local key value
key="$( echo "${keyval}" | cut -d '=' -f 1 )"
value="$( echo "${keyval//["\""]}" | cut -d '=' -f 2- )"
# Filter for invalid keys/values
[[ -z "${key}" ]] && err "Missing key for array \"${array_name}\""
[[ ! "${key}" =~ ^[A-Za-z0-9_]+$ ]] && err "Key contains invalid characters: \"${key}\""
[[ -n "${value}" ]] && [[ ! "${value}" =~ ^[A-Za-z0-9/_=-]+$ ]] && err "Value contains invalid characters: \"${value}\""
# Set value
case "${array_name}" in
config)
[[ -z "${value}" ]] && err "Missing value for array \"${array_name}\""
CONFIG[$key]="${value%/}" && save_array config
;;
env)
ENV[$key]="${value%/}"
export "${key}=${value%/}" && save_array env
;;
*) err "Invalid array name: \"${array_name}\""
esac
}
unset_value() {
local array_name="${1}"
local keyval="${2}" || err "Missing argument: set_value [array_name] [keyval]"
local key value
key="$( echo "${keyval}" | cut -d '=' -f 1 )"
value="$( echo "${keyval//["\""]}" | cut -d '=' -f 2- )"
# Filter for invalid keys
[[ -z "$key" ]] && err "Missing key: \"${array_name}\""
# Unset key
case "${array_name}" in
config) unset CONFIG[$key]; save_array config ;;
env) unset ENV[$key]; unset "${key}"; save_array env ;;
*) err "Invalid array name: \"${array_name}\""
esac
}
load_array() {
local path
local array_name="${1}" || err "Missing argument: load_array [array_name]"
case "${array_name}" in
config) path="${CONFIG_PATH}" ;;
env) path="${ENV_PATH}" ;;
*) err "Invalid argument \"${array_name}\"";;
esac
# Warn if the file does not exist
if [[ ! -f "${path}" ]]; then
warn "Failed to load \"${path}\": File does not exist" && return
fi
# Read lines & load values
while read -r line; do
case "${line}" in
*=*) set_value "${array_name}" "${line}" ;;
*) err "Cannot load setting \"${line}\": Invalid format" ;;
esac
done < "${path}"
}
save_array() {
local array_name="${1}" || err "Missing argument: \"array_name\""
case "${array_name}" in
config)
[[ -f "${CONFIG_PATH}" ]] && m_rm "${CONFIG_PATH}"
for key in "${!CONFIG[@]}"; do
echo "${key}=\"${CONFIG[$key]}\"" >> "${CONFIG_PATH}"
done
;;
env)
[[ -f "${ENV_PATH}" ]] && m_rm "${ENV_PATH}"
for key in "${!ENV[@]}"; do
echo "${key}=${ENV[$key]}" >> "${ENV_PATH}"
done
;;
*) ;;
esac
}
set_prefix() {
# Validate path
check_prefix_path "${1%/}"
local path="$( realpath -m "${1%/}" )"
# Update WINEPREFIX environment variable
export WINEPREFIX="${path}"
# Update prefix config
set_value config "prefix_dir=${path}"
# Update prefix paths
check_spt_path "${CONFIG[spt_dir]}"
SPT_DIR="${CONFIG[prefix_dir]%/}/${CONFIG[spt_dir]%/}"
BSG_DIR="${CONFIG[prefix_dir]%/}/drive_c/Battlestate Games"
EFT_DIR=$( get_eft_path )
msg "Prefix path has been set to \"${CONFIG[prefix_dir]}\""
}
init_prefix() {
if [[ -d "${CONFIG[prefix_dir]}" ]]; then return; fi
msg "Initializing wine prefix..." && m_umu wineboot -u
}
get_env() {
printf "$( while read line; do printf "$line "; done < "${ENV_PATH}" )\n"
}
# # # # # # # # # # # # #
# EFT Helper functions #
# # # # # # # # # # # # #
get_eft_path() {
local entry path
# get windows path
[[ ! -f "${CONFIG[prefix_dir]}/system.reg" ]] && exit 11
entry=$( sed -n '/Uninstall\\\\EscapeFromTarkov/,/^$/p' "${CONFIG[prefix_dir]}/system.reg" )
path=$( echo "${entry}" | grep -o "\"InstallLocation\"=\"[^}]*" | cut -d "\"" -f4 2>/dev/null )
[[ -z "${path}" ]] && exit 12
# Replace backslashes with slashes
path="${path//\\\\/\/}"
# Finally assemble the full path & return it
printf "%s/%s\n" "${CONFIG[prefix_dir]}" "${path//C:/drive_c}"
}
get_eft_version() {
local version
[[ ! -d "${EFT_DIR}" ]] && exit 10
[[ ! -f "${EFT_DIR}/EscapeFromTarkov.exe" ]] && exit 11
# Extract metadata
m_7z "${EFT_DIR}/EscapeFromTarkov.exe" "${TMP_DIR}" 1>/dev/null
# Get the EFT version from the version.txt file
version=$( cat "${TMP_DIR}/.rsrc/0/version.txt" | head -1 | tr -d '\0\r' | cut -d "," -f4 2>/dev/null )
[[ -z "${version}" ]] && exit 12
printf "%s\n" "${version}"
}
# # # # # # # # # # # # # # #
# Patcher Helper functions #
# # # # # # # # # # # # # # #
get_patcher_urls() {
local urls
local json_path="${1:-"${PATCHER_JSON_PATH}"}"
local index="${2}"
urls=$( cat "${json_path}" | jq -r '.Mirrors[].Link' )
[[ -z "${urls}" ]] && exit 12
# Return single url
if [[ -n "${index}" ]]; then
echo "${urls}" | sed "${index}q;d" 2>/dev/null; return 0
fi
# Return list
printf "%s\n" "${urls}"
}
get_patcher_eft_version() {
local url filename version
local json_path="${1:-"${PATCHER_JSON_PATH}"}"
url=$( get_patcher_urls "${json_path}" 1 ) || exit 1
# Split filename to get version infos from it
filename=$( echo "${url##*/}" | tr "_." " " )
# get target EFT version
version=$( echo "${filename}" | cut -d " " -f5 )
# Check returned value
case "${version}" in
""|*[!0-9]*) exit 14 ;;
*) printf "%s\n" "${version}" ;;
esac
}
# # # # # # # # # # #
# Check functions #
# # # # # # # # # # #
check_verb() {
local pfx_dir="${CONFIG[prefix_dir]}"
[[ ! -d "${pfx_dir}" ]] && err "Prefix directory \"${pfx_dir}\" does not exist"
if ! cat "${pfx_dir}/winetricks.log" 2>/dev/null | grep -q "$1"; then
return 1
fi
}
check_disk_space() {
local total_gb=${1}; local path="${CONFIG[prefix_dir]}"
[[ -z "${path}" ]] && err "Missing path argument"
# Get required values
local free_kb total_kb eft_kb free_gb total_gb
free_kb=$( df -k "${path}" | tail -1 | awk '{print $4}' )
free_gb=$( echo "${free_kb}" | awk '{ free = $1/1024/1024 ; printf("%.2fGiB\n", free) }' )
# If no total size is defined, use size of the EFT game files
if [[ -n "${total_gb}" ]]; then
total_kb=$(( 1024*1024*total_gb ))
else
local eft_kb=$( du -cs "${EFT_DIR}" | head -1 | cut -d$'\t' -f1 )
total_kb=$((eft_kb + 1024*1024*10))
fi
total_gb=$( echo "${total_kb}" | awk '{ total = $1/1024/1024 ; printf("%.2fGiB\n", total) }' )
# Check if there's enough space
[[ $free_kb -le $total_kb ]] && err "Not enough free disk space! (${free_gb} free < ${total_gb} needed)"
msg "Enough free disk space available! (${free_gb} free > ${total_gb} needed)"
}
check_prefix_path() {
local status=0 path
local prefix_path="${1%/}"
[[ ! "${prefix_path:0:1}" =~ ^[./~]+$ ]] && err "Invalid path format: \"${prefix_path}\""
prefix_path="$(realpath -m "${prefix_path}")"
local check_paths=("${prefix_path}/system.reg" "${prefix_path}/dosdevices" "${prefix_path}/drive_c")
while true; do
[[ -f "${prefix_path}" ]] && status=1 && break
# Check for write permissions
local recursive_path="${prefix_path}"
while [[ ! -d "${recursive_path}" ]]; do
recursive_path="${recursive_path%/*}"
[[ "${recursive_path}" == "" ]] && status=2 && break
done
[[ ! -w "${recursive_path}" ]] && status=3 && break
# Check directory content
if [[ -d "${prefix_path}" ]] && [[ -n "$( m_ls -A "${prefix_path}" )" ]]; then
for path in "${check_paths[@]}"; do
[[ ! -f "${path}" ]] && [[ ! -d "${path}" ]] && status=4 && break
done
fi
break
done
if [[ $status != 0 ]]; then
case $status in
1) err "Given path is a file: \"${prefix_path}\"" ;;
2) err "Failed to resolve prefix path: \"${prefix_path}\"" ;;
3) err "No write permission for directory: \"${prefix_path}\"" ;;
4) err "Given directory is not empty or the prefix is corrupted: \"${prefix_path}\"" ;;
esac
fi
}
check_spt_path() {
local spt_path="${1%/}"
if [[ "${spt_path}" != *"drive_c"* ]]; then
# Reset to default path
set_value config "spt_dir=${DEFAULT_SPT_DIR}"
err "Invalid spt path: \"${spt_path}\""
fi
}
check_faugus() {
if command -v "faugus-launcher" &>/dev/null; then
# Native
config_dir="${FAUGUS[config_dir]}"
json_path="${FAUGUS[json_path]}"
elif flatpak list 2>/dev/null | grep -q faugus-launcher &>/dev/null; then
# Flatpak
config_dir="${FAUGUS[flatpak_config_dir]}"
json_path="${FAUGUS[flatpak_json_path]}"
else
return 1
fi
}
check_aspnet() {
if ! dotnet --list-runtimes 2>/dev/null | grep "AspNet" | grep "9.0" &>/dev/null; then
warn "\"ASP.NET Runtime 9.0\" is not installed."
msg "> ${YELLOW}Please install it first & retry running this script.${RESET}"
err "\"ASP.NET Runtime 9.0\" is not installed"
fi
}
check_native_deps() {
local status
local cmds=( "7zzs" "xxd" "hpatchz" "jq" )
msg "Checking for native dependencies..."
for cmd in "${cmds[@]}"; do
if command -v "${cmd}" &>/dev/null; then continue; fi
case ${cmd} in
jq|hpatchz|xxd|7zzs) wrap_run install_dep "${cmd}" "${URL[${cmd}]}" || status=1 ;;
esac
done
[ "$status" = 1 ] && err "Please install all missing dependencies & try again."
}
check_eft_running() {
local apps=( "BsgLauncher.exe" "EscapeFromTarko" )
for app in "${apps[@]}"; do
if [[ -z $( pidof "${app}" ) ]]; then continue; fi
warn "It looks like \"${app}\" is currently running on your system!"
msg "> ${YELLOW} Please close the application & retry.${RESET}"
err "\"${app}\" process found"
done
}
check_hash() {
local file_hash
local file_path="$(realpath -m "${1%/}")"; local expected_hash="${2}"
# Check arguments
[[ ! -f "${file_path}" ]] && err "File \"${file_path}\" does not exist"
[[ -z "${expected_hash}" ]] && err "Missing \"expected_hash\" argument"
# use file to calculate MD5 hash and ENCODE in base64
msg "Calculating checksum for file: \"${file_path##*/}\""
file_hash=$( md5sum "${file_path}" | cut -d ' ' -f 1 | xxd -r -p | base64 2>/dev/null )
[[ -z "${file_hash}" ]] && err "Failed to calculate hash"
# Compare
if [[ "${file_hash}" != "${expected_hash}" ]]; then
warn "Hash check mismatch (File: \"${file_hash}\" != Expected: \"${expected_hash}\")"
return 1
fi
msg "Hash check successful"
}
check_cached() {
local cached_path="$(realpath -m "${1%/}")"; [[ -z "${cached_path}" ]] && err "Missing cached path argument"
local expected_hash="${2}"; [[ -z "${expected_hash}" ]] && err "Missing expected hash argument"
# Make sure the path actually is in CACHE_PATH
[[ "$cached_path" == *"${CACHE_DIR}"* ]] || err "File is not in \"${CACHE_DIR}\""
# Verify the file is there and valid
local filename=${cached_path##*/}
if [[ -f "${cached_path}" ]]; then
msg "Found \"${filename}\" in cache directory"
# Check hash
if ! check_hash "${cached_path}" "${expected_hash}"; then
msg "Removing cached file \"${filename}\""
m_rm "${cached_path}"
return 1
fi
else
msg "\"${cached_path}\" is not cached"
return 1
fi
}
check_ttl() {
local c_time m_time e_time
local file_path="$(realpath -m "${1%/}")"; local ttl="${2:-"3600"}"
# Check if file exists, if not - fail the check
[[ ! -f "${file_path}" ]] && msg "File \"${file_path}\" does not exist" && return 1
# Calculate time elapsed since last modified
c_time=$( date +%s )
m_time=$( date -r "${file_path}" +%s )
((e_time = c_time - m_time))
# If elapsed time >= TTL - fail the check
if [[ $e_time -ge $ttl ]]; then
warn "File \"${file_path}\" is out of date"
return 1
fi
}
# # # # # # # # # # # # #
# Installer functions #
# # # # # # # # # # # # #
install_verb() {
local verb="${1}"; local text="${2}"
if ! check_verb "${verb}"; then
msg "${text}..."; m_umu winetricks -q "${verb}" 1>> "${LOG_PATH}"
fi
}
install_dep() {
local cmd_name="$1"; local url="$2"; local filename="${url##*/}"
local source_path="${3:-$TMP_DIR}"; local target_path="${4:-$RUNTIME_DIR}"
# Download
msg "Downloading \"${filename}\"..."
cd "${TMP_DIR}" && m_curl -s -L "${url}" -o "${filename}"
case "${filename}" in
# Extract archive
*.zip*|*.7z*) m_7z "${filename}" "${TMP_DIR}" ;;
*.tar*) tar -xf "${filename}" || err "Failed to extract tar archive" ;;
*.deb*)
m_7z "${filename}" "${TMP_DIR}"
tar -xf "data.tar" || err "Failed to extract tar archive"
;;
# Single file workarounds
*jq-linux-amd64*) mv "jq-linux-amd64" "jq" ;;
*) ;;
esac
# Search executable inside the extracted directory
local file_path=$( find "${source_path}" \( -name "${cmd_name}" -type f \) | head -1 )
[[ -z "${file_path}" ]] && err "Cannot find \"${cmd_name}\" in \"${source_path}\""
# Change permissions
m_chmod +x "${file_path}"
# Move to target directory
m_mv -f "${file_path}" "$target_path/${cmd_name}"
}
install_eft() {
msg "Starting \"Escape from Tarkov\" setup..."
check_disk_space 60
# HACK: Fresh prefixes created with GE-Proton-10 contain reg keys for .NET 4.0,
# causing the `dotnet40` verb to fail because "v4.0 is already installed".
if ! check_verb "dotnet40"; then
msg "Apply Proton \"dotnet48\" installer workaround..."
$( m_umu reg delete "HKLM\\Software\\Wow6432Node\\Microsoft\\NET Framework Setup\\NDP\\v4" /f 1>> "${LOG_PATH}" ) \
|| warn "Failed to apply \"dotnet40\" installer workaround"
fi
# Install game dependencies
install_verb "dotnet48" "Installing .NET 4.8 Runtime (this might take a while)"
install_verb "vcrun2022" "Installing Microsoft Visual C++ 2015-2022 Redistributable"
# Add prefix update pop-up workaround
msg "Adding \"RUNDLL32\" pop-up workaround..."
m_umu reg add "HKLM\\Software\\Microsoft\\.NETFramework" /v "OnlyUseLatestCLR" /t "REG_DWORD" /d 0001 /f 1>> "${LOG_PATH}"
# Add mouse focus workaround
msg "Adding mouse focus workaround..."
m_umu reg add "HKCU\\Software\\Wine\\X11 Driver" /v "UseTakeFocus" /t "REG_SZ" /d "N" /f 1>> "${LOG_PATH}"
# Download BSG Launcher setup file
if [[ ! -f "${CACHE_DIR}/BsgLauncher.exe" ]]; then
msg "Downloading BSG Launcher..."
cd "${CACHE_DIR}" && m_curl -L "${URL[bsg-launcher]}" -o "BsgLauncher.exe"
fi
# Install BSG Launcher
if [[ ! -d "${BSG_DIR}/BsgLauncher" ]]; then
msg "Installing BSG Launcher..."
m_umu "${CACHE_DIR}/BsgLauncher.exe" /VERYSILENT
fi
# Download icon to icons directory
if [[ ! -f "${ICO_DIR}/bsg_launcher.png" ]]; then
msg "Getting app icon from SteamGridDB..."
cd "${ICO_DIR}" && m_curl -s -L "${URL[bsg-launcher-ico]}" -o "bsg_launcher.png"
fi
# Create application shortcut
opt_shortcut bsg-launcher
msg "${GREEN}Done!${RESET}"
}
install_spt() {
local install_mode="${1:-"${CONFIG[install_mode]}"}"
msg "Launching \"SPTarkov\" setup..."
msg "Selected install mode is \"${install_mode}\"..."
if [[ ! -d "${EFT_DIR}" ]]; then
warn "Escape from Tarkov is not installed."
msg "> ${YELLOW}make sure to install the game inside the BSG Launcher & try again!${RESET}"
err "Escape from Tarkov not found."
elif [[ -d "${SPT_DIR}" ]]; then
warn "SPTarkov directory already exists."
msg "> ${YELLOW}If you want to reinstall, make sure to remove the old installation first!${RESET}"
err "SPTarkov directory already exists."
fi
check_eft_running; check_aspnet; check_disk_space
# Install dependencies
install_verb "dotnetdesktop6" "Installing .NET Desktop 6 Runtime"
install_verb "dotnetdesktop8" "Installing .NET Desktop 8 Runtime"
install_verb "dotnetdesktop9" "Installing .NET Desktop 9 Runtime"
# Add DLL overrides
msg "Adding \"winhttp\" DLL override..."
m_umu reg add "HKCU\\Software\\Wine\\DllOverrides" /v "winhttp" /t "REG_SZ" /d "native,builtin" /f 1>> "${LOG_PATH}"
# Install SPT
case "$install_mode" in
native|faugus) install_spt_native ;;
lutris)
# Add prefix update pop-up workaround
msg "Adding \"RUNDLL32\" pop-up workaround..."
m_umu reg add "HKLM\\Software\\Microsoft\\.NETFramework" /v "OnlyUseLatestCLR" /t "REG_DWORD" /d 0001 /f 1>> "${LOG_PATH}"
# Install SPT
install_spt_native
;;
proton)
# The SPTInstaller needs GE-Proton instead of UMU-Latest
export PROTONPATH="GE-Proton"
# Download ASP.NET Runtime
if ! [[ -f "${CACHE_DIR}/aspnetcore-runtime.exe" ]]; then
msg "Downloading Microsoft ASP.NET Runtime 9..."
cd "${CACHE_DIR}" && m_curl -L "${URL[aspnet-windows]}" -o "aspnetcore-runtime.exe"
fi
# Install ASP.NET Runtime
msg "Installing Microsoft ASP.NET Runtime 9..."
m_umu "${CACHE_DIR}/aspnetcore-runtime.exe" /q
# Download SPT Installer
if ! [[ -f "${CACHE_DIR}/SPTInstaller.exe" ]]; then
msg "Downloading SPTInstaller.exe..."
cd "${CACHE_DIR}" && m_curl -LO "${URL[spt-installer]}"
fi
# Symlink SPTInstaller cache directory to script cache directory
local cache_dir="${CONFIG[prefix_dir]}/drive_c/users/steamuser/Application Data/spt-installer/cache"
if [[ -d "${cache_dir}" ]]; then
[[ $(readlink "${cache_dir}") != "${CACHE_DIR}" ]] && m_rmdir "${cache_dir}"
fi
[[ ! -d "${cache_dir}" ]] && m_mkdir "${cache_dir%/*}"
ln -s -n "${CACHE_DIR}" "${cache_dir}" &>> "${LOG_PATH}"
# Convert SPT directory path to windows path
local path="${CONFIG[spt_dir]//\//\\}"
path="${path//drive_c/C:}"
# Run SPT Installer
msg "Launching SPT Installer..."
m_umu "${CACHE_DIR}/SPTInstaller.exe" installpath="${path}"
# Make the Linux server executable
m_chmod +x "${SPT_DIR}/SPT/SPT.Server.Linux"
;;
""|*) err "Invalid install mode \"${install_mode}\"" ;;
esac
# Install the latest server launch script
msg "Downloading latest \"launch-server.sh\" script..."
cd "${SPT_DIR}" && m_curl -s -LO "${URL[server-script]}"
m_chmod +x "${SPT_DIR}/launch-server.sh"
# Create launcher shortcut inside the root directory
ln -s "${SPT_DIR}/SPT/SPT.Launcher.exe" "${SPT_DIR}" &>> "${LOG_PATH}"\
|| warn "Failed to create symbolic link for \"SPT.Launcher.exe\""
case "${install_mode}" in
native|proton)
# Download icons to icons directory
if [[ ! -f "${ICO_DIR}/spt_launcher.png" ]] || [[ ! -f "${ICO_DIR}/spt_server.png" ]]; then
msg "Getting app icons from SteamGridDB..."
cd "${ICO_DIR}" && m_curl -s -L "${URL[spt-launcher-ico]}" -o "spt_launcher.png"
cd "${ICO_DIR}" && m_curl -s -L "${URL[spt-server-ico]}" -o "spt_server.png"
fi
# Create application shortcuts
opt_shortcut spt
;;
faugus) opt_shortcut faugus ;;
lutris) ;;
""|*) err "Invalid install mode \"${install_mode}\"" ;;
esac
msg "${GREEN}Done!${RESET}"
}
install_spt_native() {
# Pre-Checks
check_native_deps
# Get required metadata for mod and patcher releases
if ! check_ttl "${MOD_JSON_PATH}" || ! check_ttl "${PATCHER_JSON_PATH}"; then
msg "Downloading metadata..."
m_curl -s -L "${URL[mod-json]}" -o "${MOD_JSON_PATH}"
m_curl -s -L "${URL[patcher-json]}" -o "${PATCHER_JSON_PATH}"
fi
# Fetch some juicy data
local installed_eft patcher_eft mod_eft mod_version
local mod_url mod_hash patcher_hash
installed_eft=$( get_eft_version ) || err "Failed to get EFT version" "$?"
mod_eft=$( jq -r '.ClientVersion' "${MOD_JSON_PATH}" ) || err "Failed to get required EFT version for SPT" "$?"
mod_version=$( jq -r '.AkiVersion' "${MOD_JSON_PATH}" ) || err "Failed to get SPT version" "$?"
mod_url=$( jq -r '.Mirrors[].DownloadUrl' "${MOD_JSON_PATH}" ) || err "Failed to get SPT download url" "$?"
mod_hash=$( jq -r '.Mirrors[].Hash' "${MOD_JSON_PATH}" ) || err "Failed to get mod hash" "$?"
patcher_hash=$( jq -r '.Mirrors[].Hash' "${PATCHER_JSON_PATH}" | head -1 ) || err "Failed to get patcher hash" "$?"
patcher_eft=$( get_patcher_eft_version ) || err "Failed to get required EFT version for patcher" "$?"
# Check for cached mod archive
if ! check_cached "${MOD_PATH}" "${mod_hash}"; then
msg "Downloading mod archive..."
m_curl -L "${mod_url}" -o "${MOD_PATH}"
# Make sure the file is good to use
check_hash "${MOD_PATH}" "${mod_hash}" || err "File \"${MOD_PATH}\" is corrupted"
fi
msg "Latest SPT release is \"${mod_version}\""
# Check if we need to patch the game files
msg "Comparing installed EFT <--> required EFT versions"
if [[ "${installed_eft}" -ne "${mod_eft}" ]]; then
msg "Incompatible EFT version found - Checking latest downpatcher"
# Check if target EFT version is lower, greater or equal to required EFT version
if [[ "${patcher_eft}" -lt "${installed_eft}" ]]; then
# No patcher available yet!
warn "Looks like there's no patcher available for your EFT version"
msg " > This usually happens when EFT has been updated recently."
msg " > Please wait for the SPT team to generate a new patcher."
msg " > Usually, this will take less then 24 hours."
err "No patcher available"
elif [[ "${patcher_eft}" -gt "${installed_eft}" ]]; then
# EFT is outdated!
warn "Looks like your installed EFT version is out-of-date"
msg " > Please update your live EFT installation & try again"
err "EFT is out-of-date"
elif [[ "${patcher_eft}" -eq "${installed_eft}" ]]; then
# Downpatcher is compatible!
msg "Patcher is compatible"
# Check for cached patcher archive
if ! check_cached "${PATCHER_PATH}" "${patcher_hash}"; then
# Set global variable for patcher mirror urls
local urls
urls=$( get_patcher_urls ) || err "Failed to get patcher mirrors" "$?"
# Try to download from first to last
echo "${urls}" | while read -r url; do
msg "Downloading \"${url}\"..."
m_curl -L "${url}" -o "${PATCHER_PATH}" && break
done
# Check archive
check_hash "${PATCHER_PATH}" "${patcher_hash}" || err "File \"${PATCHER_PATH}\" is corrupted"
fi
# Extract downpatcher to temp directory
msg "Extracting \"patcher\" archive..."
m_7z "${PATCHER_PATH}" "${TMP_DIR}/patcher"
# Copy EFT files
msg "Copying game files to \"${SPT_DIR}\""
m_cp "${EFT_DIR}/" "${SPT_DIR}"
# Move patcher files to install directory
msg "Copying patch files to \"${SPT_DIR}\""
local patch_dir="$(find "${TMP_DIR}/patcher" -type d -name '*SPT_Patches*')"
m_cp "${patch_dir}" "${SPT_DIR}/SPT_Patches" || err "Failed to copy patch files"
# Patch game files
opt_patch "${SPT_DIR}"
fi
else
msg "Installed EFT version is compatible with \"SPT ${mod_version}\""
msg "Copying game files to \"${SPT_DIR}\""
m_cp "${EFT_DIR}/" "${SPT_DIR}"
fi
# Extract mod archive to install directory
msg "Extracting \"mod\" archive..."
m_7z "${MOD_PATH}" "${SPT_DIR}"
}
uninstall_eft() {
local no_prompt="${1:-$NO_PROMPT}"
[[ ! -d "${BSG_DIR}" ]] && msg "EFT is not installed" && return 0
# Ask for confirmation
if [[ "${no_prompt}" != 1 ]]; then
msg "${BOLD}This action will uninstall \"Escape from Tarkov\" from your system!${RESET}"
msg "Prefix directory: ${UNDERLINE}${CONFIG[prefix_dir]}${RESET}"
yesno "Do you want to continue?" || m_exit 0
fi
msg "Uninstalling \"Escape from Tarkov\"..."
m_rmdir "${BSG_DIR}"
msg "Removing \"BSG Launcher\" shortcut..."
app_path="${APP_DIR}/BSG - Launcher.desktop"
[[ -f "${app_path}" ]] && m_rm "${app_path}"
[[ "${no_prompt}" != 1 ]] && msg "${GREEN}Done!${RESET}"
}
uninstall_spt() {
local no_prompt="${1:-$NO_PROMPT}"
[[ ! -d "${SPT_DIR}" ]] && msg "SPT is not installed" && return 0
# Ask for confirmation
if [[ "${no_prompt}" != 1 ]]; then
msg "${BOLD}This action will uninstall \"SPTarkov\" from your system!${RESET}"
msg "SPT directory: ${UNDERLINE}${SPT_DIR}${RESET}"
yesno "Do you want to continue?" || m_exit 0
fi
msg "Uninstalling \"SPTarkov\"..."
m_rmdir "${SPT_DIR}"
msg "Removing \"SPTarkov\" shortcuts..."
local apps=( "SPT - Launcher.desktop" "SPT - Server.desktop" )
for app in "${apps[@]}"; do
local app_path="${APP_DIR}/${app}"
[[ -f "${app_path}" ]] && m_rm "${app_path}"
done
[[ "${no_prompt}" != 1 ]] && msg "${GREEN}Done!${RESET}"
}
uninstall_prefix() {
local no_prompt="${1:-$NO_PROMPT}"
[[ ! -d "${CONFIG[prefix_dir]}" ]] && msg "Prefix directory does not exist" && return 0
msg "Removing Prefix directory: \"${CONFIG[prefix_dir]}\""
m_rmdir "${CONFIG[prefix_dir]}"
[[ "${no_prompt}" != 1 ]] && msg "${GREEN}Done!${RESET}"
}
# # # # # # # # # # # #
# Option functions #
# # # # # # # # # # # #
opt_patch() {
msg "Patching game files..."
local files_total
local target_path="${1:-"${SPT_DIR}"}"
local source_path="${2:-"${SPT_DIR}"}"
target_path=$( realpath -m "${target_path%/}" )
source_path=$( realpath -m "${source_path%/}" )
# Fail if the target director does not exist
[[ ! -d "${target_path}" ]] && err "Target directory \"${target_path}\" does not exist"