-
-
Notifications
You must be signed in to change notification settings - Fork 119
/
njordmenu.sh
3534 lines (3116 loc) · 139 KB
/
njordmenu.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
#!/bin/bash
###############################################################################################
###############################################################################################
####
#### From: Zerobandwidth
####
#### Thank you for using the menu script, this started out as just me and blew up quickly.
#### If Frankenstein was a bash script, this is what you would get, so please help me improve it.
#### Feel free to use and change this as you wish just not for profit.
#### If you need anything, please visit our Discord Server: https://discord.gg/ejgQUfc
#### *** GLHF - V/r, Zerobandwidth and Team
####
###############################################################################################
####
#### File name: ldadvmenu.sh
####
###############################################################################################
####
#### Modifier: Lord/Ranger(Dumoss)
#### Forked from: Njord advancemenu.ld (beta) Updated: 29-APR-2021
####
#### I would like to thank "Dr." Zerobandwidth "Frankenstein"
#### and the development team of "Igor's" for putting
#### this wonderfull "monster" script together. :)
####
#### The main focus of this was to add Linux support for
#### Fedora-Cento-RHEL-OEL-yum/dnf based systems.
####
#### To allow control multiple Valheim servers running on a single node
#### based on WORLDNAME and is installed under "${worldpath}/${worldname}"
####
#### TO have some simple firewall security control related to these systems. - (WIP)
####
#### *** - Dumoss
####
###############################################################################################
###############################################################################################
#### Current Options: DE=German, EN=English, FR=French, SP=Spanish"
###############################################################################################
###############################################################################################
# All linux systems should have this
# If not .. <> install os-release
source /etc/os-release
if [ "$1" == "" ]
then
LANGUAGE=EN
else
LANGUAGE=$1
fi
source lang/$LANGUAGE.conf
#############################################################
######################## Santiy Check #####################
#############################################################
echo "$(tput setaf 4)"$DRAW60""
echo "$(tput setaf 0)$(tput setab 7)"$CHECKSUDO"$(tput sgr 0)"
echo "$(tput setaf 0)$(tput setab 7)"$CHECKSUDO1"$(tput sgr 0)"
echo "$(tput setaf 4)"$DRAW60""
# ######################################################
[[ "$EUID" -eq 0 ]] || exec sudo "$0" "$@"
clear
###############################################################
################### Default Variables #########################
###############################################################
### NOTE: Only change this if you know what you are doing ###
###############################################################
###############################################################
### Valheim Server Install location(Default)
valheimInstallPath=/home/steam/valheimserver
### Valheim World Data Path(Default)
worldpath=/home/steam/.config/unity3d/IronGate/Valheim
### Keeps a list of created Valheim Worlds
worldfilelist=/home/steam/worlds.txt
### Backup Directory ( Default )
backupPath=/home/steam/backups
###
### Configs for Advance Users ###
### This option is only for the steamcmd install where it
### is not included in the "steam" client install ... ie RH/OEL-yum
### Set this to delete all files from the /home/steam/steamcmd directory to install steamcmd fresh.
### Defaults are "n" on the below parameters.
### <n : no>
### <y : yes>
freshinstall="n"
### **** Firewall setup ***
### Do you use a firewall?
usefw="n"
### what firewall do you want to use?
#Change the following value to one listed in the fwsystems list below or use 'none'.
fwbeingused="firewalld"
# Do not changed this only add to it.
fwsystems=( arptables ebtables firewalld iptables ip6tables ufw )
###############################################################
debugmsg="n"
# if [ "$debugmsg" == "y" ] ; then echo "something" ; fi
###############################################################
# Set Menu Version for menu display
mversion="4.0-Thor"
ldversion="0.4.051120211500ET.dev"
### -- Use are your own risk --
### dev -- Still working on firewall code.
### -- Currently adding ufw commands.
### -- And then finish the firewall menu (make pro).
### alpha -- Dev team review.
### beta -- Public Testing.
###
### Please note that this is a play ground file for me and
### allows Zerobandwidth do determine what to pull into the main advance(menu).sh file.
###
### I have done a lot ( and still ) testing of this new code
### and it seams to be working as original intended, but
### now for OEL/REL/Fedora and centos tested.
###
### If you are using the above server versions of Linux and the added repos cause issues,
### I have provided the 3 most causes and fixes in the function ***linux_server_update*** text.
###
### I am still in design mode for the firewall stuff.
### Current it works 99% for FireWallD only at this time.
###
### Other Linux flavors and firewall systems to be added.
########################################################################
#############################Set COLOR VARS#############################
########################################################################
NOCOLOR='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
LIGHTRED='\033[1;31m'
LIGHTGREEN='\033[1;32m'
YELLOW='\033[1;33m'
WHITE='\033[1;37m'
clear='\e[0m'
##
# Color Functions
##
ColorRed(){
echo -ne $RED$1$clear
}
ColorGreen(){
echo -ne $GREEN$1$clear
}
ColorOrange(){
echo -ne $ORANGE$1$clear
}
ColorBlue(){
echo -ne $BLUE$1$clear
}
ColorPurple(){
echo -ne $PURPLE$1$clear
}
ColorCyan(){
echo -ne $CYAN$1$clear
}
ColorLightRed(){
echo -ne $LIGHTRED$1$clear
}
ColorLightGreen(){
echo -ne $LIGHTGREEN$1$clear
}
ColorYellow(){
echo -ne $LIGHTYELLOW$1$clear
}
ColorWhite(){
echo -ne $WHITE$1$clear
}
########################################################################
#####################Check for Menu Updates#############################
########################################################################
MENUSCRIPT="$(readlink -f "$0")"
SCRIPTFILE="$(basename "$MENUSCRIPT")"
SCRIPTPATH="$(dirname "$SCRIPT")"
SCRIPTNAME="$0"
ARGS=( "$@" )
BRANCH=$(git rev-parse --abbrev-ref HEAD)
UPSTREAM=$(git rev-parse --abbrev-ref --symbolic-full-name @{upstream})
function script_check_update() {
# Look for updates from repo tag
echo "1"
git fetch
# Check if there are updates available
if [ -n "$(git diff --name-only "$UPSTREAM" "$SCRIPTFILE")" ]; then
echo "$GIT_ECHO_CHECK"
sleep 1
git pull --force
git stash
git checkout "$BRANCH"
git pull --force
echo "$GIT_ECHO_UPDATING"
sleep 1
chmod +x *menu.sh
sleep 1
# Restart the script with the same arguments
exec "$SCRIPTNAME" "${ARGS[@]}"
# Exit the old instance
exit 1
else
echo "$GIT_ECHO_NO_UPDATES"
fi
}
########################################################################
##############MAIN VALHEIM SERVER ADMIN FUNCTIONS START#################
########################################################################
########################################################################
#####################Install Valheim Server START#######################
########################################################################
function valheim_server_steam_account_creation() {
# Create steam account
echo "$START_INSTALL_1_PARA"
while true; do
tput setaf 2; echo "$DRAW60" ; tput setaf 9;
tput setaf 2; echo "$STEAM_NON_ROOT_STEAM_PASSWORD" ; tput setaf 9;
tput setaf 2; echo "$DRAW60" ; tput setaf 9;
tput setaf 1; echo "$STEAM_PASS_MUST_BE" ; tput setaf 9;
tput setaf 1; echo "$STEAM_PASS_MUST_BE_1" ; tput setaf 9;
tput setaf 2; echo "$DRAW60" ; tput setaf 9;
tput setaf 2; echo "$STEAM_GOOD_EXAMPLE" ; tput setaf 9;
tput setaf 1; echo "$STEAM_BAD_EXAMPLE" ; tput setaf 9;
tput setaf 2; echo "$DRAW60" ; tput setaf 9;
echo ""
read -p "$STEAM_PLEASE_ENTER_STEAM_PASSWORD" userpassword
tput setaf 2; echo "$DRAW60" ; tput setaf 9;
if [[ ${#userpassword} -ge 6 && "$userpassword" == *[[:lower:]]* && "$userpassword" == *[[:upper:]]* && "$userpassword" =~ ^[[:alnum:]]+$ ]]; then
break
else
tput setaf 2; echo "$STEAM_PASS_NOT_ACCEPTED" ; tput setaf 9;
tput setaf 2; echo "$STEAM_PASS_NOT_ACCEPTED_1" ; tput setaf 9;
fi
done
echo ""
# Set the environment and bash profile information for steam user
tput setaf 1; echo "$INSTALL_BUILD_NON_ROOT_STEAM_ACCOUNT" ; tput setaf 9;
sleep 1
if command -v apt-get >/dev/null; then
useradd --create-home --shell /bin/bash --password "$userpassword" steam
cp /etc/skel/.bashrc /home/steam/.bashrc
cp /etc/skel/.profile /home/steam/.profile
elif command -v yum >/dev/null; then
useradd -mU -s /bin/bash -p "$userpassword" steam
# All files from /etc/skel/ are auto copied on RH.
else
echo "Package manager not recognized."
fi
tput setaf 2; echo "$ECHO_DONE" ; tput setaf 9;
}
function valheim_server_public_server_display_name() {
echo ""
# Display instructions for Valheim Server Public Display Name
for msg in "$DRAW60" "$PUBLIC_SERVER_DISPLAY_NAME" "$DRAW60" "$PUBLIC_SERVER_DISPLAY_NAME_1" \
"$PUBLIC_SERVER_DISPLAY_NAME_2" "$DRAW60" "$PUBLIC_SERVER_DISPLAY_GOOD_EXAMPLE" \
"$PUBLIC_SERVER_DISPLAY_GOOD_EXAMPLE_1" "$PUBLIC_SERVER_DISPLAY_BAD_EXAMPLE" "$DRAW60"; do
tput setaf 2; echo "$msg"; tput setaf 9;
done
echo ""
# Prompt user for Valheim Server Public Display Name
read -p "$PUBLIC_SERVER_ENTER_NAME" displayname
tput setaf 2; echo "------------------------------------------------------------"; tput setaf 9;
echo ""
}
function valheim_server_local_world_name() {
# Set world name function that will be used for .db and .fwl files
echo ""
while true; do
# Display instructions for setting the world name
for msg in "$DRAW60" "$WORLD_SET_WORLD_NAME_HEADER" "$DRAW60" "$WORLD_SET_CHAR_RULES" \
"$WORLD_SET_NO_SPECIAL_CHAR_RULES" "$DRAW60" "$WORLD_GOOD_EXAMPLE" \
"$WORLD_BAD_EXAMPLE" "$DRAW60"; do
tput setaf 2; echo "$msg"; tput setaf 9;
done
echo ""
read -p "$WORLD_SET_WORLD_NAME_VAR" worldname
tput setaf 2; echo "------------------------------------------------------------"; tput setaf 9;
# Validate the world name
if [[ ${#worldname} -ge 4 && "$worldname" =~ ^[[:alnum:]]+$ ]]; then
break
else
tput setaf 2; echo "$WORLD_SET_ERROR"; tput setaf 9;
tput setaf 2; echo "$WORLD_SET_ERROR_1"; tput setaf 9;
fi
done
clear
echo ""
}
function valheim_server_public_valheim_port() {
# Take user input for Valheim Server port and display instructions
echo ""
for msg in "$DRAW60" "$FUNCTION_VALHEIM_SERVER_INSTALL_LD_SETPORTNEW_HEADER" "$DRAW60" \
"$FUNCTION_VALHEIM_SERVER_INSTALL_LD_SETPORTNEW_INFO1" "$FUNCTION_VALHEIM_SERVER_INSTALL_LD_SETPORTNEW_INFO2" \
"$DRAW60" "$FUNCTION_VALHEIM_SERVER_INSTALL_LD_SETPORTNEW_INFO3" "$FUNCTION_VALHEIM_SERVER_INSTALL_LD_SETPORTNEW_INFO4" \
"$FUNCTION_VALHEIM_SERVER_INSTALL_LD_SETPORTNEW_INFO5" "$DRAW60"; do
tput setaf 2; echo "$msg"; tput setaf 9;
done
echo ""
while true; do
read -p "$FUNCTION_VALHEIM_SERVER_INSTALL_LD_SETPORTNEW_ENTER" portnumber
# Validate port number
if [[ ${#portnumber} -ge 4 && ${#portnumber} -le 6 ]] && [[ $portnumber -gt 1024 && $portnumber -le 65530 ]] && [[ "$portnumber" =~ ^[[:alnum:]]+$ ]]; then
break
fi
done
tput setaf 2; echo "------------------------------------------------------------"; tput setaf 9;
clear
echo ""
}
function valheim_server_public_listing() {
# Set public listing: 1 = Display Server, 0 = LAN or do not display server public
echo ""
for msg in "$DRAW60" "$PUBLIC_ENABLED_DISABLE_HEADER" "$DRAW60" "$PUBLIC_ENABLED_DISABLE_INFO" \
"$DRAW60" "$PUBLIC_ENABLED_DISABLE_EXAMPLE_SHOW" "$PUBLIC_ENABLED_DISABLE_EXAMPLE_LAN_NO_SHOW" "$DRAW60"; do
tput setaf 2; echo "$msg"; tput setaf 9;
done
echo ""
read -p "$PUBLIC_ENABLED_DISABLE_INPUT" publicList
tput setaf 2; echo "------------------------------------------------------------"; tput setaf 9;
echo ""
# Display credentials
echo "$CREDS_DISPLAY_CREDS_PRINT_OUT_HEADER"
tput setaf 2; echo "$DRAW60"; tput setaf 9;
tput setaf 2; echo "$CREDS_DISPLAY_CREDS_PRINT_OUT_STEAM_PASSWORD $userpassword"; tput setaf 9;
tput setaf 2; echo "$CREDS_DISPLAY_CREDS_PRINT_OUT_SERVER_NAME $displayname"; tput setaf 9;
tput setaf 2; echo "$CREDS_DISPLAY_CREDS_PRINT_OUT_WORLD_NAME $worldname"; tput setaf 9;
tput setaf 2; echo "Port number being used: $portnumber"; tput setaf 9;
tput setaf 2; echo "$CREDS_DISPLAY_CREDS_PRINT_OUT_ACCESS_PASS $password"; tput setaf 9;
tput setaf 2; echo "$CREDS_DISPLAY_CREDS_PRINT_OUT_SHOW_PUBLIC $publicList"; tput setaf 9;
tput setaf 2; echo "$DRAW60"; tput setaf 9;
echo ""
}
function valheim_server_public_access_password() {
# Added security for password complexity
echo ""
for msg in "$DRAW60" "$SERVER_ACCESS_PASS_HEADER" "$DRAW60" "$SERVER_ACCESS_INFO" \
"$DRAW60" "$SERVER_ACCESS_PUBLIC_NAME_INFO $displayname" "$SERVER_ACCESS_WORLD_NAME_INFO $worldname" "$DRAW60"; do
tput setaf 2; echo "$msg"; tput setaf 9;
done
while true; do
for msg in "$SERVER_ACCESS_WARN_INFO" "$SERVER_ACCESS_WARN_INFO_1" "$DRAW60" \
"$SERVER_ACCESS_GOOD_EXAMPLE" "$SERVER_ACCESS_BAD_EXAMPLE" "$DRAW60"; do
tput setaf 1; echo "$msg"; tput setaf 9;
done
read -p "$SERVER_ACCESS_ENTER_PASSWORD" password
tput setaf 2; echo "------------------------------------------------------------"; tput setaf 9;
# Validate password complexity
if [[ ${#password} -ge 5 && "$password" == *[[:lower:]]* && "$password" == *[[:upper:]]* && "$password" =~ ^[[:alnum:]]+$ ]]; then
break
else
tput setaf 2; echo "$SERVER_ACCESS_PASSWORD_ERROR"; tput setaf 9;
tput setaf 2; echo "$SERVER_ACCESS_PASSWORD_ERROR_1"; tput setaf 9;
fi
done
}
function valheim_server_set_crossplay() {
echo ""
for msg in "$DRAW60" "Set up Crossplay" "$DRAW60" \
"Crossplay allows you to play with friends on other platforms" \
"Crossplay 1 = Enabled" "Crossplay 0 = Disabled" \
"$DRAW60" "Do you wish to enable Crossplay?" "$DRAW60"; do
tput setaf 2; echo "$msg"; tput setaf 9;
done
echo ""
read -p "Enter 1 for Yes or 0 for No: " crossplay
tput setaf 2; echo "------------------------------------------------------------"; tput setaf 9;
echo ""
}
function build_configuration_env_files_set_permissions() {
# Populate Admin/config files
config_file="/home/steam/serverSetup.txt"
world_file="/home/steam/worlds.txt"
{
echo "$DRAW60"
echo "$CREDS_DISPLAY_CREDS_PRINT_OUT_STEAM_PASSWORD $userpassword"
echo "$CREDS_DISPLAY_CREDS_PRINT_OUT_SERVER_NAME $displayname"
echo "$CREDS_DISPLAY_CREDS_PRINT_OUT_WORLD_NAME $worldname"
echo "$CREDS_DISPLAY_CREDS_PRINT_OUT_PORT_USED $portnumber"
echo "$CREDS_DISPLAY_CREDS_PRINT_OUT_ACCESS_PASS $password"
echo "$CREDS_DISPLAY_CREDS_PRINT_OUT_SHOW_PUBLIC $publicList"
echo "CrossPlay Option 1 = Enabled - 0 = Disabled $crossplay"
echo "$DRAW60"
} >> "$config_file"
sleep 1
echo "$worldname" >> "$world_file"
sleep 1
chown steam:steam /home/steam/*.txt
clear
}
function valheim_server_install() {
clear
echo ""
# Initial setup for first-time installation
if [ "$newinstall" == "y" ]; then
for msg in "Thank you for using the Njord Menu system." \
"This appears to be the first time the menu has" \
"been run on this system." \
"Installing the first Valheim server started."; do
tput setaf 2; echo "$msg"; tput setaf 9;
done
linux_server_update
valheim_server_steam_account_creation
valheim_server_public_server_display_name
valheim_server_local_world_name
portnumber=2456
valheim_server_public_listing
valheim_server_public_access_password
valheim_server_set_crossplay
build_configuration_env_files_set_permissions
Install_steamcmd_client
else
# For adding another Valheim install on the same server skipping steam user creation
valheim_server_public_server_display_name
valheim_server_local_world_name
valheim_server_public_valheim_port
valheim_server_public_listing
valheim_server_public_access_password
valheim_server_set_crossplay
build_configuration_env_files_set_permissions
fi
nocheck_valheim_update_install
tput setaf 1; echo "$INSTALL_BUILD_SET_STEAM_PERM"; tput setaf 9;
chown steam:steam -Rf /home/steam/*
tput setaf 2; echo "$ECHO_DONE"; tput setaf 9;
sleep 1
# Configure firewall settings if enabled
if [ "${usefw}" == "y" ]; then
case "${fwbeingused}" in
ufw)
if command -v ufw >/dev/null; then
sudo ufw allow ${portnumber}:${portnumber+2}/udp
echo "Adding ports to the UFW system."
fi
;;
iptables)
if command -v iptables >/dev/null; then
# sudo iptables –A INPUT –p udp ––dport ${portnumber},${portnumber}+1,${portnumber}+2) –j ACCEPT
# sudo /sbin/iptables-save
echo "Configuring iptables."
fi
;;
firewalld)
if command -v firewalld >/dev/null; then
if [ "$is_firewall_enabled" == "y" ] && [ "$get_firewall_status" == "y" ]; then
sftc="val"
add_Valheim_server_public_ports
fi
fi
;;
*)
echo "No firewall configuration detected."
;;
esac
else
if [ "${is_firewall_enabled}" == "y" ]; then
disable_all_firewalls
fi
fi
tput setaf 2; echo "$ECHO_DONE"; tput setaf 9;
sleep 1
# Build config for start_valheim.sh
tput setaf 1; echo "$INSTALL_BUILD_DELETE_OLD_CONFIGS"; tput setaf 9;
tput setaf 1; echo "$INSTALL_BUILD_DELETE_OLD_CONFIGS_1"; tput setaf 9;
[ -e ${valheimInstallPath}/${worldname}/start_valheim_${worldname}.sh ] && rm ${valheimInstallPath}/${worldname}/start_valheim_${worldname}.sh
sleep 1
cat > ${valheimInstallPath}/${worldname}/start_valheim_${worldname}.sh <<EOF
#!/bin/bash
export templdpath=\$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=./linux64:\$LD_LIBRARY_PATH
export SteamAppId=892970
./valheim_server.x86_64 -name "${displayname}" -port "${portnumber}" -nographics -batchmode -world "${worldname}" -password "${password}" -public "${publicList}" -savedir "${worldpath}/${worldname}" -logfile "${worldpath}/${worldname}/valheim_server.log" -crossplay "${crossplay}"
export LD_LIBRARY_PATH=\$templdpath
EOF
tput setaf 2; echo "$ECHO_DONE"; tput setaf 9;
sleep 1
# Delete old check log script
tput setaf 1; echo "$INSTALL_BUILD_DELETE_OLD_SCRIPT"; tput setaf 9;
[ -e /home/steam/check_log.sh ] && rm /home/steam/check_log.sh
# Set execute permissions
tput setaf 1; echo "$INSTALL_BUILD_SET_PERM_ON_START_VALHEIM"; tput setaf 9;
chmod +x ${valheimInstallPath}/${worldname}/start_valheim_${worldname}.sh
tput setaf 2; echo "$ECHO_DONE"; tput setaf 9;
sleep 1
# Build systemctl configurations for execution of processes for Valheim Server
tput setaf 1; echo "$INSTALL_BUILD_DEL_OLD_SERVICE_CONFIG"; tput setaf 9;
tput setaf 1; echo "$INSTALL_BUILD_DEL_OLD_SERVICE_CONFIG_1"; tput setaf 9;
# Remove old Valheim Server Service
[ -e /etc/systemd/system/valheimserver_${worldname}.service ] && rm /etc/systemd/system/valheimserver_${worldname}.service
[ -e /lib/systemd/system/valheimserver_${worldname}.service ] && rm /lib/systemd/system/valheimserver_${worldname}.service
sleep 1
# Add new Valheim Server Service
cat > /lib/systemd/system/valheimserver_${worldname}.service <<EOF
[Unit]
Description=Valheim Server
Wants=network-online.target
After=syslog.target network.target nss-lookup.target network-online.target
[Service]
Type=simple
Restart=on-failure
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3
User=steam
Group=steam
ExecStartPre=$steamexe +login anonymous +force_install_dir ${valheimInstallPath}/${worldname} +app_update 896660 validate +exit
ExecStart=${valheimInstallPath}/${worldname}/start_valheim_${worldname}.sh
ExecReload=/bin/kill -s HUP \$MAINPID
KillSignal=SIGINT
WorkingDirectory=${valheimInstallPath}/${worldname}
LimitNOFILE=100000
[Install]
WantedBy=multi-user.target
EOF
tput setaf 2; echo "$ECHO_DONE"; tput setaf 9;
sleep 1
# Chown steam user permissions to all of user steam dir location
tput setaf 1; echo "$INSTALL_BUILD_SET_STEAM_PERMS"; tput setaf 9;
chown steam:steam -Rf /home/steam/*
tput setaf 2; echo "$ECHO_DONE"; tput setaf 9;
sleep 1
# Reload daemons
tput setaf 1; echo "$INSTALL_BUILD_RELOAD_DAEMONS"; tput setaf 9;
systemctl daemon-reload
tput setaf 2; echo "$ECHO_DONE"; tput setaf 9;
sleep 1
# Start server
tput setaf 1; echo "$INSTALL_BUILD_START_VALHEIM_SERVICE"; tput setaf 9;
systemctl start valheimserver_${worldname}.service
tput setaf 2; echo "$ECHO_DONE"; tput setaf 9;
sleep 1
# Enable server on restarts
tput setaf 1; echo "$INSTALL_BUILD_ENABLE_VALHEIM_SERVICE"; tput setaf 9;
systemctl enable valheimserver_${worldname}.service
tput setaf 2; echo "$ECHO_DONE"; tput setaf 9;
sleep 2
clear
tput setaf 2; echo "$INSTALL_BUILD_FINISH_THANK_YOU"; tput setaf 9;
echo ""
echo ""
}
########################################################################
#####################Install Valheim Server END#########################
########################################################################
########################################################################
############ Linux server update - requirement #############
########################################################################
# LordDumoss (LD): Add yum support. Might be a better way. But it works.
# LD: Changed where the steamcmd required libs are installed.
########################################################################
# SUDO?
#########
function linux_server_update() {
# Check for updates and upgrade the system automatically
echo "$ID"
echo "$VERSION"
echo "${VERSION:0:1}"
tput setaf 1; echo "$CHECK_FOR_UPDATES"; tput setaf 9;
# Update system based on package manager
if command -v apt-get >/dev/null; then
sudo apt update && sudo apt upgrade -y
elif command -v pkg >/dev/null; then
echo "Insert command here."
elif command -v yum >/dev/null; then
if [[ "$ID" == "fedora" ]] || [[ "$ID" =~ ^(centos|ol|rhel)$ && "${VERSION:0:1}" == "8" ]]; then
sudo dnf clean all && sudo dnf update -y && sudo dnf upgrade -y
elif [[ "$ID" =~ ^(centos|ol|rhel)$ && "${VERSION:0:1}" == "7" ]]; then
sudo yum clean all && sudo yum update -y && sudo yum upgrade -y
else
echo "Unsupported version for yum/dnf."
fi
else
echo "Unsupported package manager."
fi
tput setaf 2; echo "$ECHO_DONE"; tput setaf 9;
sleep 1
# Install additional packages
tput setaf 1; echo "$INSTALL_ADDITIONAL_FILES"; tput setaf 9;
if command -v apt-get >/dev/null; then
sudo apt install -y lib32gcc1 libsdl2-2.0-0 libsdl2-2.0-0:i386 git mlocate net-tools unzip curl isof
elif command -v yum >/dev/null; then
if [[ "$ID" == "fedora" ]] || [[ "$ID" =~ ^(centos|ol|rhel)$ && "${VERSION:0:1}" == "8" ]]; then
sudo dnf install -y glibc.i686 libstdc++.i686 git mlocate net-tools unzip curl isof
elif [[ "$ID" =~ ^(centos|ol|rhel)$ && "${VERSION:0:1}" == "7" ]]; then
sudo yum install -y glibc.i686 libstdc++.i686 git mlocate net-tools unzip curl isof
else
echo "Unsupported version for yum/dnf."
fi
else
echo "Unsupported package manager."
fi
tput setaf 2; echo "$ECHO_DONE"; tput setaf 9;
sleep 1
# Install software-properties-common for add-apt-repository command
tput setaf 1; echo "$INSTALL_SPCP"; tput setaf 9;
if command -v apt-get >/dev/null; then
sudo apt install -y software-properties-common
else
echo "$FUNCTION_LINUX_SERVER_UPDATE_YUM_REQUIRED_NO"
fi
tput setaf 2; echo "$ECHO_DONE"; tput setaf 9;
sleep 1
# Add the MULTIVERSE repo(s) per Linux Flavor
tput setaf 1; echo "$ADD_MULTIVERSE"; tput setaf 9;
if command -v apt-get >/dev/null; then
sudo add-apt-repository -y multiverse
elif command -v yum >/dev/null; then
if [[ "$ID" == "fedora" ]] || [[ "$ID" =~ ^(centos|ol|rhel)$ && "${VERSION:0:1}" == "8" ]]; then
sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf config-manager --add-repo=http://mirror.centos.org/centos/8/os/x86_64/
sudo dnf install -y https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm \
https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
sudo dnf config-manager --add-repo=https://negativo17.org/repos/fedora-negativo17.repo
elif [[ "$ID" =~ ^(centos|ol|rhel)$ && "${VERSION:0:1}" == "7" ]]; then
sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum-config-manager --add-repo=http://mirror.centos.org/centos/7/os/x86_64/
sudo yum localinstall --nogpgcheck -y https://mirrors.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm \
https://mirrors.rpmfusion.org/free/el/rpmfusion-nonfree-release-7.noarch.rpm
sudo yum-config-manager --add-repo=https://negativo17.org/repos/epel-negativo17.repo
else
echo "Unsupported version for yum/dnf."
fi
else
echo "Unsupported package manager."
fi
tput setaf 2; echo "$ECHO_DONE"; tput setaf 9;
sleep 1
# Add i386 architecture
tput setaf 1; echo "$ADD_I386"; tput setaf 9;
if command -v apt-get >/dev/null; then
sudo dpkg --add-architecture i386
else
echo "$FUNCTION_LINUX_SERVER_UPDATE_RHL_REQUIRED_NO"
fi
tput setaf 2; echo "$ECHO_DONE"; tput setaf 9;
sleep 1
# Update system again
tput setaf 1; echo "$CHECK_FOR_UPDATES_AGAIN"; tput setaf 9;
if command -v apt-get >/dev/null; then
sudo apt update && sudo apt install -y libpulse-dev libatomic1 libc6
elif command -v yum >/dev/null; then
if [[ "$ID" == "fedora" ]] || [[ "$ID" =~ ^(centos|ol|rhel)$ && "${VERSION:0:1}" == "8" ]]; then
sudo dnf update -y
elif [[ "$ID" =~ ^(centos|ol|rhel)$ && "${VERSION:0:1}" == "7" ]]; then
sudo yum update -y
else
echo "Unsupported version for yum/dnf."
fi
fi
tput setaf 2; echo "$ECHO_DONE"; tput setaf 9;
sleep 1
}
########################################################################
################# LD: Install the steamcmd #############
########################################################################
function Install_steamcmd_client() {
# Install steamcmd and related dependencies based on the Linux flavor
tput setaf 1; echo "$INSTALL_STEAMCMD_LIBSD12"; tput setaf 9;
if command -v apt-get >/dev/null; then
echo steam steam/license note '' | sudo debconf-set-selections
echo steam steam/question select 'I AGREE' | sudo debconf-set-selections
sudo apt install -y steamcmd libsdl2-2.0-0 libsdl2-2.0-0:i386
tput setaf 2; echo "$ECHO_DONE"; tput setaf 9;
elif command -v yum >/dev/null; then
if [[ "$ID" == "fedora" ]] || [[ "$ID" =~ ^(centos|ol|rhel)$ && "${VERSION:0:1}" == "8" ]]; then
sudo dnf -y install steam kernel-modules-extra
elif [[ "$ID" =~ ^(centos|ol|rhel)$ && "${VERSION:0:1}" == "7" ]]; then
sudo yum -y install steam
else
echo "Unsupported version for yum/dnf."
fi
# Download and install steamcmd manually for yum systems
steamzipfile="/home/steam/steamcmd/steamcmd_linux.tar.gz"
mkdir -p /home/steam/steamcmd
cd /home/steam/steamcmd
[ -e $steamzipfile ] && rm $steamzipfile
[ "$freshinstall" == "y" ] && rm -rfv /home/steam/steamcmd/*
wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz
tar xf steamcmd_linux.tar.gz
tput setaf 2; echo "$ECHO_DONE"; tput setaf 9;
else
echo "Unsupported package manager."
fi
# Configure firewall settings for steamcmd
if [ "${usefw}" == "y" ]; then
case "${fwbeingused}" in
ufw)
if command -v ufw >/dev/null; then
sudo ufw allow 1200/udp
sudo ufw allow 27020/udp
sudo ufw allow 27000-27015/udp
sudo ufw allow 27015-27016/both
sudo ufw allow 27030-27039/both
echo "UFW rules added."
fi
;;
iptables)
echo "IPTables configuration not implemented."
;;
firewalld)
if command -v firewalld >/dev/null; then
if [ "$is_firewall_enabled" == "y" ] && [ "$get_firewall_status" == "y" ]; then
sftc="ste"
add_Valheim_server_public_ports
fi
fi
;;
*)
echo "Unsupported firewall configuration."
;;
esac
else
[ "${is_firewall_enabled}" == "y" ] && disable_all_firewalls
fi
tput setaf 2; echo "$ECHO_DONE"; tput setaf 9;
sleep 1
# Build symbolic link for steamcmd
tput setaf 1; echo "$INSTALL_BUILD_SYM_LINK_STEAMCMD"; tput setaf 9;
if command -v apt-get >/dev/null; then
ln -s /usr/games/steamcmd /home/steam/steamcmd
elif command -v yum >/dev/null; then
ln -s /usr/games/steamcmd /home/steam/steamcmd/linux32/steamcmd
else
echo "Unsupported package manager."
fi
tput setaf 2; echo "$ECHO_DONE"; tput setaf 9;
sleep 1
}
########################################################################
##########Backup and Restore World DB and FWL Files START###############
########################################################################
#Backup World DB and FWL Files
function backup_world_data() {
echo ""
echo ""
# Read user input confirmation
tput setaf 1; echo "$BACKUP_WORLD_DATA_HEADER"; tput setaf 9;
tput setaf 1; echo "$BACKUP_WORLD_INFO_CONFIRM"; tput setaf 9;
read -p "$BACKUP_WORLD_INPUT_CONFIRM_Y_N" confirmBackup
# If 'y', then continue, else cancel
if [ "$confirmBackup" == "y" ]; then
# Get the current date as variable
TODAY=$(date +%Y-%m-%d-%T)
tput setaf 5; echo "$BACKUP_WORLD_CHECK_DIRECTORY"; tput setaf 9;
tput setaf 5; echo "$BACKUP_WORLD_CHECK_DIRECTORY_1"; tput setaf 9;
dldir="$backupPath/$worldname"
[ ! -d "$dldir" ] && mkdir -p "$dldir"
sleep 1
# Clean up files older than 2 weeks and create a new backup
tput setaf 1; echo "$BACKUP_WORLD_CONDUCT_CLEANING"; tput setaf 9;
find "$backupPath/$worldname/"* -mtime +14 -type f -delete
tput setaf 2; echo "$BACKUP_WORLD_CONDUCT_CLEANING_LOKI"; tput setaf 9;
sleep 1
# Stop Valheim server
tput setaf 1; echo "$BACKUP_WORLD_STOPPING_SERVICES"; tput setaf 9;
systemctl stop valheimserver_${worldname}.service
tput setaf 1; echo "$BACKUP_WORLD_STOP_INFO"; tput setaf 9;
tput setaf 2; echo "$BACKUP_WORLD_STOP_INFO_1"; tput setaf 9;
tput setaf 2; echo "$BACKUP_WORLD_STOP_WAIT_10_SEC"; tput setaf 9;
sleep 10
# Create a backup tarball
tput setaf 1; echo "$BACKUP_WORLD_MAKING_TAR"; tput setaf 9;
tar czf "$backupPath/$worldname/valheim-backup-$TODAY.tgz" "$worldpath/$worldname/"*
tput setaf 2; echo "$BACKUP_WORLD_MAKING_TAR_COMPLETE"; tput setaf 9;
sleep 1
# Restart Valheim server
tput setaf 2; echo "$BACKUP_WORLD_RESTARTING_SERVICES"; tput setaf 9;
systemctl start valheimserver_${worldname}.service
tput setaf 2; echo "$BACKUP_WORLD_RESTARTING_SERVICES_1"; tput setaf 9;
echo ""
# Set permissions for backup files
tput setaf 2; echo "$BACKUP_WORLD_SET_PERMS_FILES"; tput setaf 9;
chown -Rf steam:steam "$backupPath/$worldname"
tput setaf 2; echo "$BACKUP_WORLD_PROCESS_COMPLETE"; tput setaf 9;
echo ""
else
tput setaf 3; echo "$BACKUP_WORLD_PROCESS_CANCELED"; tput setaf 9;
fi
}
# Restore World Files DB and FWL
# Thanks to GITHUB @LachlanMac and @Kurt
function restore_world_data() {
# Initialize empty array
declare -a backups
# Loop through backups and put in array
for file in "${backupPath}/${worldname}"/*.tgz; do
backups+=("$file")
done
# Counter index
bIndex=1
for item in "${backups[@]}"; do
# Print option [index]> [file name]
basefile=$(basename "$item")
echo "$bIndex> $basefile"
# Increment
bIndex=$((bIndex + 1))
done
# Prompt user for index
tput setaf 2; echo "$RESTORE_WORLD_DATA_HEADER"; tput setaf 9;
tput setaf 2; echo "$RESTORE_WORLD_DATA_CONFIRM"; tput setaf 9;
read -p "$RESTORE_WORLD_DATA_SELECTION" selectedIndex
# Show confirmation message
restorefile=$(basename "${backups[selectedIndex - 1]}")
echo -ne "
$(ColorRed '------------------------------------------------------------')
$(ColorGreen ' '"$RESTORE_WORLD_DATA_SHOW_FILE"' $restorefile ?')
$(ColorGreen ' '"$RESTORE_WORLD_DATA_ARE_YOU_SURE"' ')
$(ColorOrange ' '"$RESTORE_WORLD_DATA_VALIDATE_DATA_WITH_CONFIG"' ${valheimInstallPath}/${worldname}/start_valheim_${worldname}.sh')
$(ColorOrange ' '"$RESTORE_WORLD_DATA_INFO"' ')
$(ColorGreen ' '"$RESTORE_WORLD_DATA_CONFIRM_1"' ') "
# Read user input confirmation
read -p "" confirmBackupRestore
# If 'y', then continue, else cancel
if [ "$confirmBackupRestore" == "y" ]; then
# Stop Valheim server
tput setaf 1; echo "$RESTORE_WORLD_DATA_STOP_VALHEIM_SERVICE"; tput setaf 9;
systemctl stop valheimserver_${worldname}.service
tput setaf 2; echo "$RESTORE_WORLD_DATA_STOP_VALHEIM_SERVICE_1"; tput setaf 9;
sleep 5
# Copy backup to worlds folder
tput setaf 2; echo "$RESTORE_WORLD_DATA_COPYING ${backups[selectedIndex - 1]} to ${worldpath}/${worldname}/"; tput setaf 9;
cp "${backups[selectedIndex - 1]}" "${worldpath}/${worldname}/"
# Unpack backup
tput setaf 2; echo "$RESTORE_WORLD_DATA_UNPACKING ${worldpath}/${restorefile}"; tput setaf 9;
tar xzf "${worldpath}/${worldname}/${restorefile}" --strip-components=7 --directory "${worldpath}/${worldname}/"
chown -Rf steam:steam "${worldpath}/${worldname}/"
rm "${worldpath}/${worldname}"/*.tgz
# Start Valheim server
tput setaf 2; echo "$RESTORE_WORLD_DATA_STARTING_VALHEIM_SERVICES"; tput setaf 9;
tput setaf 2; echo "$RESTORE_WORLD_DATA_CUSS_LOKI"; tput setaf 9;
systemctl start valheimserver_${worldname}.service
else
tput setaf 2; echo "$RESTORE_WORLD_DATA_CANCEL_CUSS_LOKI"; tput setaf 9;
fi
}
########################################################################
##########Backup and Restore World DB and FWL Files END#################
########################################################################
########################################################################
###############LD: Download Valheim from steam #########################
########################################################################
function nocheck_valheim_update_install() {
# Set Steam executable and update/install Valheim
tput setaf 1; echo "$INSTALL_BUILD_DOWNLOAD_INSTALL_STEAM_VALHEIM"; tput setaf 9;
sleep 1
# Execute the steamcmd command to install/update Valheim
$steamexe +login anonymous +force_install_dir "${valheimInstallPath}/${worldname}" +app_update 896660 validate +exit
tput setaf 2; echo "$ECHO_DONE"; tput setaf 9;
}
########################################################################
#############Install Official Update of Valheim Updates#################
########################################################################
function continue_with_valheim_update_install() {
clear
echo ""
echo -ne "
$(ColorOrange "$FUNCTION_INSTALL_VALHEIM_UPDATES")
$(ColorRed "$DRAW60")"
echo ""
tput setaf 2; echo "$FUNCTION_INSTALL_VALHEIM_FOUND"; tput setaf 9;
tput setaf 2; echo "$FUNCTION_INSTALL_VALHEIM_UPDATE_INFO"; tput setaf 9;
tput setaf 2; echo "$FUNCTION_INSTALL_VALHEIM_UPDATE_CONFIRM"; tput setaf 9;
echo -ne "
$(ColorRed "$DRAW60")"
echo ""
read -p "$PLEASE_CONFIRM" confirmOfficialUpdates
# If 'y', then continue, else cancel
if [ "$confirmOfficialUpdates" == "y" ]; then
tput setaf 2; echo "$FUNCTION_INSTALL_VALHEIM_UPDATE_APPLY_INFO"; tput setaf 9;