forked from Nimdy/Dedicated_Valheim_Server_Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.sh
1188 lines (1067 loc) · 44.8 KB
/
menu.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
# Sanity Check
# #######################################################
echo "$(tput setaf 4)-------------------------------------------------------"
echo "$(tput setaf 0)$(tput setab 7)Since we need to run the menu with elevated privileges$(tput sgr 0)"
echo "$(tput setaf 0)$(tput setab 7)Please enter your password now.$(tput sgr 0)"
echo "$(tput setaf 4)-------------------------------------------------------"
# ######################################################
[[ "$EUID" -eq 0 ]] || exec sudo "$0" "$@"
# MAIN BRANCH MENU
# THIS IS STILL A WORK IN PROGRESS BUT ALL THE FUNCTIONS WORK
# I NEED TO JUST CLEAN IT UP AND FORMAT BETTER
# PLEASE LET ME KNOW ABOUT ISSUES
# UPDATE THE MENU BEFORE YOU USE IT
# If Frankenstein was a bash script
# Please help improve this script
# Easy Valheim Server Menu super duper easy
# Open to other commands that should be used...
clear
###############################################################
#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/worlds
#Backup Directory ( Default )
backupPath=/home/steam/backups
###############################################################
# Set Menu Version
mversion="Version 1.7.8-Loki"
##
# Update Menu script
##
##
# Admin Tools:
# -Backup World: Manual backups of .db and .fwl files
# -Restore World: Manual restore of .db and .fwl files
# -Stop Valheim Server: Stops the Valheim Service
# -Start Valheim Server: Starts the Valheim Service
# -Restart Valheim Server: Restarts the Valheim Service (stop/start)
# -Status Valheim Server: Displays the current status of the Valheim Server Service
# -Check and Apply Valheim Server Update: Reaches out to to Steam with steamcmd and looks for official updates. If found applies them and restarts Valheim services
# -Fresh Valheim Server: Installs Valheim server from official Steam repo.
##
##
# Tech Support Tools
#Display Valheim Config File
#Display Valheim Server Service
#Display World Data Folder
#Display System Info
#Display Network Info
#Display Connected Players History
##
##
# Adding Valheim Mod Support
##
########################################################################
#############################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 I know this is not pretty like Loki's face but it works!
git fetch
[ -n "$(git diff --name-only "$UPSTREAM" "$SCRIPTFILE")" ] && {
echo "BY THORS HAMMER take a peek inside Valhalla!!"
sleep 1
git pull --force
git stash
git checkout "$BRANCH"
git pull --force
echo " Updating"
sleep 1
cd /opt/Dedicated_Valheim_server_Script/
chmod +x menu.sh
exec "$SCRIPTNAME" "${ARGS[@]}"
# Now exit this old instance
exit 1
}
echo "Oh for Loki sakes! No updates to be had... back to choring! "
}
#####Fully remove after one week of testing new menu system with public
#function script_check_update() {
#BRANCH="https://github.com/Nimdy/Dedicated_Valheim_Server_Script/tree/main"
# git stash
# LAST_UPDATE=`git show --no-notes --format=format:"%H" $BRANCH | head -n 1`
# LAST_COMMIT=`git show --no-notes --format=format:"%H" origin/$BRANCH | head -n 1`
# if [ $LAST_COMMIT != $LAST_UPDATE ]; then
# tput setaf 2; echo "Updating your branch $BRANCH" ; tput setaf 9;
# git pull --no-edit
# else
# echo "No updates available"
#
# fi
# echo "Resetting permissions on menu.sh"
# chmod +x menu.sh
# tput setaf 2; echo "Restarting menu system" ; tput setaf 9;
# sleep 3
# ./menu.sh
#}
########################################################################
########################Install Valheim Server##########################
########################################################################
function valheim_server_install() {
clear
echo ""
echo -ne "
$(ColorOrange '-----------------Install Valheim Server------------------')
$(ColorRed '------------------------------------------------------------')"
echo ""
tput setaf 2; echo "You are about to INSTALL the Valheim Server" ; tput setaf 9;
tput setaf 2; echo "You are you sure y(YES) or n(NO)?" ; tput setaf 9;
echo -ne "
$(ColorRed '------------------------------------------------------------')"
echo ""
read -p "Please confirm:" confirmStartInstall
#if y, then continue, else cancel
if [ "$confirmStartInstall" == "y" ]; then
echo ""
#check for updates and upgrade the system auto yes
tput setaf 2; echo "Checking for upgrades" ; tput setaf 9;
apt update && apt upgrade -y
tput setaf 2; echo "Done" ; tput setaf 9;
sleep 1
#check for updates and upgrade the system auto yes
tput setaf 2; echo "Install Git, Locate and Net-Tools" ; tput setaf 9;
apt install git mlocate net-tools -y
tput setaf 2; echo "Done" ; tput setaf 9;
sleep 1
#install software-properties-common for add-apt-repository command below
tput setaf 2; echo "Installing software-properties-common package"
apt install software-properties-common
tput setaf 2; echo "Done"
tput setaf 9;
sleep 1
#add multiverse repo
tput setaf 2; echo "Adding multiverse REPO" ; tput setaf 9;
add-apt-repository -y multiverse
tput setaf 2; echo "Done" ; tput setaf 9;
sleep 1
#add i386 architecture
tput setaf 1; echo "Adding i386 architecture" ; tput setaf 9;
dpkg --add-architecture i386
tput setaf 2; echo "Done" ; tput setaf 9;
sleep 1
#update system again
tput setaf 1; echo "Checking and updating system again" ; tput setaf 9;
apt update
tput setaf 2; echo "Done" ; tput setaf 9;
sleep 1
# Linux Steam Local Account Password input
echo ""
clear
echo "Thanks for downloading the script, let's get started"
echo "The following information is required for configuration files"
echo "Read each step carefully"
echo "A printout of data entered will be displayed to you"
echo ""
echo "A non-root account will be created to run Valheim Server"
echo "This account is named steam"
while true; do
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
tput setaf 2; echo "----------------NONROOT STEAM ACCOUNT PASSWORD--------------" ; tput setaf 9;
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
tput setaf 1; echo "Password must be 6 Characters or more" ; tput setaf 9;
tput setaf 1 ;echo "At least one number, one uppercase letter and one lowercase letter" ; tput setaf 9;
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
tput setaf 2; echo "Good Example: Viking12" ; tput setaf 9;
tput setaf 1; echo "Bad Example: Vik!" ; tput setaf 9;
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
echo ""
read -p "Please give steam a password: " userpassword
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
[[ ${#userpassword} -ge 6 && "$userpassword" == *[[:lower:]]* && "$userpassword" == *[[:upper:]]* && "$userpassword" =~ ^[[:alnum:]]+$ ]] && break
tput setaf 2; echo "Password not accepted - Too Short or has Special Characters" ; tput setaf 9;
tput setaf 2; echo "I swear to LOKI, you better NOT use Special Characters" ; tput setaf 9;
done
clear
echo ""
# Take user input for Valheim Server Public Display
echo ""
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
tput setaf 2; echo "------------------Public Server Display Name----------------" ; tput setaf 9;
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
tput setaf 1; echo "Enter a name for your Valheim Server" ; tput setaf 9;
tput setaf 1; echo "This is for the Public Steam Browser Listing" ; tput setaf 9;
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
tput setaf 2; echo "Good Example: Zero's Viking Server" ; tput setaf 9;
tput setaf 1; echo "Bad Example: Zero's #1 Server Cash Signs hashtags or other special chars, it will break the script!" ; tput setaf 9;
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
echo ""
read -p "Enter public server display name: " displayname
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
echo ""
clear
# Take user input for Valheim Server World Database Generation
echo ""
while true; do
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
tput setaf 2; echo "----------------------Set your World Name-------------------" ; tput setaf 9;
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
tput setaf 1; echo "Name must be 4 Characters or more" ; tput setaf 9;
tput setaf 1; echo "No Special Characters not even a space" ; tput setaf 9;
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
tput setaf 2; echo "Good Example: ThorsHammer" ; tput setaf 9;
tput setaf 1; echo "Bad Example: Loki is a Trickster" ; tput setaf 9;
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
echo ""
read -p "Please make a world name: " worldname
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
[[ ${#worldname} -ge 4 && "$worldname" =~ ^[[:alnum:]]+$ ]] && break
tput setaf 2; echo "World Name not set: Too Short or has Special Characters" ; tput setaf 9;
tput setaf 2; echo "I swear to LOKI, you better NOT use Special Characters" ; tput setaf 9;
done
clear
echo ""
# Take user input for Valheim Server password
# Added security for harder passwords
echo ""
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
tput setaf 2; echo "--------------------Set Server Access Password--------------" ; tput setaf 9;
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
tput setaf 1; echo "Now for Loki, please follow instructions" ; tput setaf 9;
tput setaf 1; echo "Server is required to have a password" ; tput setaf 9;
tput setaf 1; echo "Password cannot match public display name or world name" ; tput setaf 9;
tput setaf 1; echo "Make your password unique" ; tput setaf 9;
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
tput setaf 2; echo "Your public display name: $displayname " ; tput setaf 9;
tput setaf 2; echo "Your world name: $worldname " ; tput setaf 9;
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
while true; do
tput setaf 1; echo "This password must be 5 Characters or more" ; tput setaf 9;
tput setaf 1; echo "At least one number, one uppercase letter and one lowercase letter" ; tput setaf 9;
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
tput setaf 2; echo "Good Example: Viking12" ; tput setaf 9;
tput setaf 1; echo "Bad Example: Vik!" ; tput setaf 9;
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
read -p "Enter Password to Enter your Valheim Server: " password
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
[[ ${#password} -ge 5 && "$password" == *[[:lower:]]* && "$password" == *[[:upper:]]* && "$password" =~ ^[[:alnum:]]+$ ]] && break
tput setaf 2; echo "Password not accepted - Too Short, Special Characters" ; tput setaf 9;
tput setaf 2; echo "I swear to LOKI, you better NOT use Special Characters" ; tput setaf 9;
done
echo ""
cat >> /home/steam/serverSetup.txt <<EOF
Here is the information you entered
This information is for you to ref later, in case you forgot
---------------------------------------------------------------
nonroot steam password: $userpassword
Public Server Name: $displayname
Local World Name: $worldname
Valheim Server Password: $password
---------------------------------------------------------------
Each time this is ran, the past info will be added to each line
---------------------------------------------------------------
EOF
chown steam:steam /home/steam/serverSetup.txt
clear
echo "Here is the information you entered"
echo "This information is saved in the valheim_server.sh file"
echo "This information is saved in /home/steam/serverSetup.txt for referance later, if you forget"
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
tput setaf 2; echo "nonroot steam password: $userpassword " ; tput setaf 9;
tput setaf 2; echo "Public Server Name: $displayname " ; tput setaf 9;
tput setaf 2; echo "Local World Name: $worldname " ; tput setaf 9;
tput setaf 2; echo "Valheim Server Password: $password " ; tput setaf 9;
tput setaf 2; echo "------------------------------------------------------------" ; tput setaf 9;
echo ""
sleep 5
#install steamcmd and libsd12-2
tput setaf 1; echo "Installing steamcmd and libsdl2" ; tput setaf 9;
echo steam steam/question select "I AGREE" | sudo debconf-set-selections
echo steam steam/license note '' | sudo debconf-set-selections
apt install steamcmd libsdl2-2.0-0 libsdl2-2.0-0:i386 -y
tput setaf 2; echo "Done" ; tput setaf 9;
sleep 1
#EDIT HERE #1
#build account to run Valheim
tput setaf 1; echo "Building steam account NONROOT" ; tput setaf 9;
sleep 1
useradd --create-home --shell /bin/bash --password $userpassword steam
cp /etc/skel/.bashrc /home/steam/.bashrc
cp /etc/skel/.profile /home/steam/.profile
tput setaf 2; echo "Done" ; tput setaf 9;
sleep 1
#build symbolic link for steamcmd
tput setaf 1; echo "Building symbolic link for steamcmd" ; tput setaf 9;
ln -s /usr/games/steamcmd /home/steam/steamcmd
tput setaf 2; echo "Done" ; tput setaf 9;
sleep 1
#chown steam user to steam
tput setaf 1; echo "Setting steam permissions" ; tput setaf 9;
chown steam:steam -Rf /home/steam/*
tput setaf 2; echo "Done" ; tput setaf 9;
sleep 1
#Download Valheim from steam
tput setaf 1; echo "Downloading and installing Valheim from Steam" ; tput setaf 9;
sleep 1
/home/steam/steamcmd +login anonymous +force_install_dir ${valheimInstallPath} +app_update 896660 validate +exit
tput setaf 2; echo "Done" ; tput setaf 9;
sleep 1
#build config for start_valheim.sh
tput setaf 1; echo "Deleting old configuration if file exist" ; tput setaf 9;
tput setaf 1; echo "Building Valheim start_valheim server configuration" ; tput setaf 9;
[ -e ${valheimInstallPath}/start_valheim.sh ] && rm ${valheimInstallPath}/start_valheim.sh
sleep 1
cat >> ${valheimInstallPath}/start_valheim.sh <<EOF
#!/bin/bash
export templdpath=\$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=./linux64:\$LD_LIBRARY_PATH
export SteamAppId=892970
# Tip: Make a local copy of this script to avoid it being overwritten by steam.
# NOTE: You need to make sure the ports 2456-2458 is being forwarded to your server through your local router & firewall.
./valheim_server.x86_64 -name "${displayname}" -port 2456 -nographics -batchmode -world "${worldname}" -password "${password}"
#export LD_LIBRARY_PATH=$templdpath
export LD_LIBRARY_PATH=\$templdpath
EOF
tput setaf 2; echo "Done" ; tput setaf 9;
sleep 1
#build check log script
tput setaf 1; echo "Deleting old check log script if exist" ; tput setaf 9;
tput setaf 1; echo "Building check log script" ; tput setaf 9;
[ -e /home/steam/check_log.sh ] && rm /home/steam/check_log.sh
sleep 1
cat >> /home/steam/check_log.sh <<EOF
journalctl --unit=valheimserver --reverse
EOF
chmod +x /home/steam/check_log.sh
tput setaf 2; echo "Done" ; tput setaf 9;
sleep 1
#set execute permissions
tput setaf 1; echo "Setting execute permissions on start_valheim.sh" ; tput setaf 9;
chmod +x ${valheimInstallPath}/start_valheim.sh
tput setaf 2; echo "Done" ; tput setaf 9;
tput setaf 1; echo "Setting execute permissions on check_log.sh" ; tput setaf 9;
chmod +x /home/steam/check_log.sh
tput setaf 2; echo "Done" ; tput setaf 9;
sleep 1
#build systemctl configurations for execution of processes for Valheim Server
tput setaf 1; echo "Deleting old configuration if file exist" ; tput setaf 9;
tput setaf 1; echo "Building systemctl instructions for Valheim" ; tput setaf 9;
# remove old Valheim Server Service
[ -e /etc/systemd/system/valheimserver.service ] && rm /etc/systemd/system/valheimserver.service
# remove past Valheim Server Service
[ -e /lib/systemd/system/valheimserver.service ] && rm /lib/systemd/system/valheimserver.service
sleep 1
# Add new Valheim Server Service
# Thanks @QuadeHale
cat >> /lib/systemd/system/valheimserver.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=/home/steam/steamcmd +login anonymous +force_install_dir ${valheimInstallPath} +app_update 896660 validate +exit
ExecStart=${valheimInstallPath}/start_valheim.sh
ExecReload=/bin/kill -s HUP \$MAINPID
KillSignal=SIGINT
WorkingDirectory=${valheimInstallPath}
LimitNOFILE=100000
[Install]
WantedBy=multi-user.target
EOF
tput setaf 2; echo "Done" ; tput setaf 9;
sleep 1
#chown steam user permissions to all of user steam dir location
tput setaf 1; echo "Setting steam account permissions to /home/steam/*" ; tput setaf 9;
chown steam:steam -Rf /home/steam/*
tput setaf 2; echo "Done" ; tput setaf 9;
sleep 1
# Reload daemons
tput setaf 1; echo "Reloading daemons and spawning Necks" ; tput setaf 9;
systemctl daemon-reload
tput setaf 2; echo "Done" ; tput setaf 9;
sleep 1
# Start server
tput setaf 1; echo "By Thors Hammer we are Starting the Valheim Server" ; tput setaf 9;
systemctl start valheimserver
tput setaf 2; echo "Done" ; tput setaf 9;
sleep 1
# Enable server on restarts
tput setaf 1; echo "Enabling Valheim Server on start or after reboots" ; tput setaf 9;
systemctl enable valheimserver
tput setaf 2; echo "Done" ; tput setaf 9;
sleep 2
clear
tput setaf 2; echo "Check server status by typing systemctl status valheimserver.service"
tput setaf 2; echo "Thank you for using the script."
tput setaf 2; echo "AND A HUGE THANKS TO github: @RedKrieg, @bherbruck, @xaviablaza, @joaoanes"
tput setaf 2; echo "@amasover, @madmozg, @nicolas-martin, @devdavi, @Lachlanmac and others!"
tput setaf 2; echo "If your name is missing! Let me know!"
tput setaf 2; echo "Twitch: ZeroBandwidth"
tput setaf 2; echo "GLHF"
tput setaf 9;
echo ""
echo ""
else
echo "Canceling the INSTALL of Valheim Server Service - because Loki sucks"
fi
}
########################################################################
###################Backup World DB and FWL Files########################
########################################################################
function backup_world_data() {
echo ""
echo ""
## Get the current date as variable.
TODAY="$(date +%Y-%m-%d-%T)"
echo "Checking to see if backup directory is created"
echo "If not, one will be created"
dldir=$backupPath
[ ! -d "$dldir" ] && mkdir -p "$dldir"
sleep 1
## Clean up files older than 2 weeks. Create a new backup.
echo "Cleaning up old backup files. Older than 2 weeks"
find $backupPath/* -mtime +14 -type f -delete
echo "Cleaned up better than Loki"
sleep 1
## Tar Section. Create a backup file, with the current date in its name.
## Add -h to convert the symbolic links into a regular files.
## Backup some system files, also the entire `/home` directory, etc.
##--exclude some directories, for example the the browser's cache, `.bash_history`, etc.
#stop valheim server
echo "Stopping Valheim Server for clean backups"
systemctl stop valheimserver.service
echo "Stopped"
echo "Making tar file of world data"
tar czf $backupPath/valheim-backup-$TODAY.tgz $worldpath/*
echo "Process complete!"
sleep 1
echo "Restarting the best Valheim Server in the world"
systemctl start valheimserver.service
echo "Valheim Server Service Started"
echo ""
echo "Setting permissions for steam on backup file"
chown -Rf steam:steam ${backupPath}
echo "Process complete!"
echo ""
}
########################################################################
##################Restore World Files DB and FWL########################
########################################################################
# Thanks to GITHUB @LachlanMac and @Kurt
function restore_world_data() {
#init empty array
declare -a backups
#loop through backups and put in array
for file in ${backupPath}/*.tgz
do
backups=(${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
#promt user for index
tput setaf 2; echo "Select Backup File you wish to restore" ; tput setaf 9;
read -p "" selectedIndex
#show confirmation message
restorefile=$(basename "${backups[$selectedIndex-1]}")
echo -ne "
$(ColorRed '------------------------------------------------------------')
$(ColorGreen 'Restore '${restorefile}' ?')
$(ColorGreen 'Are you sure you want to do this? ')
$(ColorOrange 'Remember to match world name with '${valheimInstallPath}'/start_valheim.sh')
$(ColorOrange 'The param for -world "worldname" much match restore file worldname.db and worldname.fwl')
$(ColorGreen 'Press y (for yes) or n (for no)') "
#read user input confirmation
read -p "" confirmBackup
#if y, then continue, else cancel
if [ "$confirmBackup" == "y" ]; then
#stop valheim server
echo "Stopping Valheim Server"
systemctl stop valheimserver.service
echo "Stopped"
#give it a few
sleep 5
#copy backup to worlds folder
echo "Copying ${backups[$selectedIndex-1]} to ${worldpath}/"
cp ${backups[$selectedIndex-1]} ${worldpath}/
#untar
echo "Unpacking ${worldpath}/${restorefile}"
tar xzf ${worldpath}/${restorefile} --strip-components=7 --directory ${worldpath}/
chown -Rf steam:steam ${worldpath}
#uncomment when test are 100%
#last time steam was applied to /usr and other locations
#really jacked stuff up - DAMN IT LOKI!!!
#chown -Rf steam:steam $worldpath
#start valheim server
echo "Starting Valheim Services"
echo "This better work Loki!"
systemctl start valheimserver.service
else
echo "Canceling restore process because Loki sucks"
fi
}
########################################################################
#############Install Official Update of Valheim Updates#################
########################################################################
function continue_with_valheim_update_install() {
clear
echo ""
echo -ne "
$(ColorOrange '-----------------Installing Valheim Updates-----------------')
$(ColorRed '------------------------------------------------------------')"
echo ""
tput setaf 2; echo "A NEW update was found!" ; tput setaf 9;
tput setaf 2; echo "You are about to apply Official Valheim Updates" ; tput setaf 9;
tput setaf 2; echo "You are you sure y(YES) or n(NO)?" ; tput setaf 9;
echo -ne "
$(ColorRed '------------------------------------------------------------')"
echo ""
read -p "Please confirm:" confirmOfficialUpdates
#if y, then continue, else cancel
if [ "$confirmOfficialUpdates" == "y" ]; then
tput setaf 2; echo "Using Thor's Hammer to apply Official Updates!" ; tput setaf 9;
/home/steam/steamcmd +login anonymous +force_install_dir ${valheimInstallPath} +app_update 896660 validate +exit
chown -R steam:steam ${valheimInstallPath}
echo ""
else
echo "Canceling all Official Updates for Valheim Server - because Loki sucks"
sleep 3
clear
fi
}
########################################################################
######################beta updater for Valheim##########################
########################################################################
########################################################################
######################beta updater for Valheim##########################
########################################################################
#function check_apply_server_updates_beta() {
# echo ""
# echo "Downloading Official Valheim Repo Log Data for comparison only"
# repoValheim=$(/home/steam/steamcmd +login anonymous +app_info_update 1 +app_info_print 896660 +quit | grep -A10 branches | grep -A2 public | grep buildid | cut -d'"' -f4)
# echo "Official Valheim-: $repoValheim"
# localValheim=$(grep buildid ${valheimInstallPath}/steamapps/appmanifest_896660.acf | cut -d'"' -f4)
# echo "Local Valheim Ver: $localValheim"
# if [ "$repoValheim" == "$localValheim" ]; then
# echo "No new Updates found"
# sleep 2
# else
# echo "Update Found kicking process to Odin for updating!"
# sleep 2
# continue_with_valheim_update_install
# echo ""
# fi
# echo ""
#}
function check_apply_server_updates_beta() {
echo ""
echo "Downloading Official Valheim Repo Log Data for comparison only"
[ ! -d /opt/valheimtemp ] && mkdir -p /opt/valheimtemp
/home/steam/steamcmd +login anonymous +force_install_dir /opt/valheimtemp +app_update 896660 validate +exit
sed -e 's/[\t ]//g;/^$/d' /opt/valheimtemp/steamapps/appmanifest_896660.acf > appmanirepo.log
repoValheim=$(sed -n '11p' appmanirepo.log)
echo "Official Valheim-: $repoValheim"
sed -e 's/[\t ]//g;/^$/d' ${valheimInstallPath}/steamapps/appmanifest_896660.acf > appmanilocal.log
localValheim=$(sed -n '11p' appmanilocal.log)
echo "Local Valheim Ver: $localValheim"
if [ "$repoValheim" == "$localValheim" ]; then
echo "No new Updates found"
echo "Cleaning up TEMP FILES"
rm -Rf /opt/valheimtemp
rm appmanirepo.log
rm appmanilocal.log
sleep 2
else
echo "Update Found kicking process to Odin for updating!"
sleep 2
continue_with_valheim_update_install
echo ""
fi
echo ""
}
########################################################################
##############Verify Checking Updates for Valheim Server################
########################################################################
function confirm_check_apply_server_updates() {
while true; do
echo -ne "
$(ColorRed '------------------------------------------------------------')"
echo ""
tput setaf 2; echo "The Script will download the Log Data from the official" ; tput setaf 9;
tput setaf 2; echo "Steam Valheim Repo and compare the data." ; tput setaf 9;
tput setaf 2; echo "No changes will be made, until you agree later." ; tput setaf 9;
tput setaf 2; echo "Press y(YES) and n(NO)" ; tput setaf 9;
echo -ne "
$(ColorRed '------------------------------------------------------------')"
echo ""
tput setaf 2; read -p "Do you wish to continue?" yn ; tput setaf 9;
echo -ne "
$(ColorRed '------------------------------------------------------------')"
case $yn in
[Yy]* ) check_apply_server_updates_beta; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
}
########################################################################
###############Display Valheim Start Configuration######################
########################################################################
function display_start_valheim() {
clear
echo ""
sudo cat ${valheimInstallPath}/start_valheim.sh
echo ""
}
########################################################################
###############Display Valheim World Data Folder########################
########################################################################
function display_world_data_folder() {
clear
echo ""
sudo ls -lisa $worldpath
echo ""
}
########################################################################
######################Stop Valheim Server Service#######################
########################################################################
function stop_valheim_server() {
clear
echo ""
echo -ne "
$(ColorOrange '--------------------Stop Valheim Server---------------------')
$(ColorRed '------------------------------------------------------------')"
echo ""
tput setaf 2; echo "You are about to STOP the Valheim Server" ; tput setaf 9;
tput setaf 2; echo "You are you sure y(YES) or n(NO)?" ; tput setaf 9;
echo -ne "
$(ColorRed '------------------------------------------------------------')"
echo ""
read -p "Please confirm:" confirmStop
#if y, then continue, else cancel
if [ "$confirmStop" == "y" ]; then
echo ""
echo "Stopping Valheim Server Services"
sudo systemctl stop valheimserver.service
echo ""
else
echo "Canceling Stopping of Valheim Server Service - because Loki sucks"
sleep 3
clear
fi
}
########################################################################
###################Start Valheim Server Service#########################
########################################################################
function start_valheim_server() {
clear
echo ""
echo -ne "
$(ColorOrange '-------------------Start Valheim Server---------------------')
$(ColorRed '------------------------------------------------------------')"
echo ""
tput setaf 2; echo "You are about to START the Valheim Server" ; tput setaf 9;
tput setaf 2; echo "You are you sure y(YES) or n(NO)?" ; tput setaf 9;
echo -ne "
$(ColorRed '------------------------------------------------------------')"
echo ""
read -p "Please confirm:" confirmStart
#if y, then continue, else cancel
if [ "$confirmStart" == "y" ]; then
echo ""
tput setaf 2; echo "Starting Valheim Server with Thor's Hammer!!!!" ; tput setaf 9;
sudo systemctl start valheimserver.service
echo ""
else
echo "Canceling Starting of Valheim Server Service - because Loki sucks"
sleep 3
clear
fi
}
########################################################################
####################Restart Valheim Server Service######################
########################################################################
function restart_valheim_server() {
clear
echo ""
echo -ne "
$(ColorOrange '------------------Restart Valheim Server--------------------')
$(ColorRed '------------------------------------------------------------')"
echo ""
tput setaf 2; echo "You are about to RESTART the Valheim Server" ; tput setaf 9;
tput setaf 2; echo "You are you sure y(YES) or n(NO)?" ; tput setaf 9;
echo -ne "
$(ColorRed '------------------------------------------------------------')"
echo ""
read -p "Please confirm:" confirmRestart
#if y, then continue, else cancel
if [ "$confirmRestart" == "y" ]; then
tput setaf 2; echo "Restarting Valheim Server with Thor's Hammer!!!!" ; tput setaf 9;
sudo systemctl restart valheimserver.service
echo ""
else
echo "Canceling Restarting of Valheim Server Service - because Loki sucks"
sleep 3
clear
fi
}
########################################################################
#####################Display Valheim Server Status######################
########################################################################
function display_valheim_server_status() {
clear
echo ""
sudo systemctl status --no-pager -l valheimserver.service
echo ""
}
########################################################################
##############Display Valheim Vanilla Configuration File################
########################################################################
function display_start_valheim() {
clear
echo ""
sudo cat ${valheimInstallPath}/start_valheim.sh
echo ""
}
########################################################################
#######################Sub Server Menu System###########################
########################################################################
server_install_menu() {
echo ""
echo -ne "
$(ColorOrange '----------------Server System Information-------------------')
$(ColorOrange '-')$(ColorGreen '1)') Fresh or Reinstall Valheim Server
$(ColorOrange '-')$(ColorGreen '0)') Go to Main Menu
$(ColorOrange '------------------------------------------------------------')
$(ColorBlue 'Choose an option:') "
read a
case $a in
1) valheim_server_install ; server_install_menu ;;
0) menu ; menu ;;
*) echo -ne " $(ColorRed 'Wrong option.')" ; server_install_menu ;;
esac
}
########################################################################
#########################Print System INFOS#############################
########################################################################
function display_system_info() {
clear
echo ""
echo -e "-------------------------------System Information----------------------------"
echo -e "Hostname:\t\t"`hostname`
echo -e "uptime:\t\t\t"`uptime | awk '{print $3,$4}' | sed 's/,//'`
echo -e "Manufacturer:\t\t"`cat /sys/class/dmi/id/chassis_vendor`
echo -e "Product Name:\t\t"`cat /sys/class/dmi/id/product_name`
echo -e "Version:\t\t"`cat /sys/class/dmi/id/product_version`
echo -e "Serial Number:\t\t"`cat /sys/class/dmi/id/product_serial`
echo -e "Machine Type:\t\t"`vserver=$(lscpu | grep Hypervisor | wc -l); if [ $vserver -gt 0 ]; then echo "VM"; else echo "Physical"; fi`
echo -e "Operating System:\t"`hostnamectl | grep "Operating System" | cut -d ' ' -f5-`
echo -e "Kernel:\t\t\t"`uname -r`
echo -e "Architecture:\t\t"`arch`
echo -e "Processor Name:\t\t"`awk -F':' '/^model name/ {print $2}' /proc/cpuinfo | uniq | sed -e 's/^[ \t]*//'`
echo -e "Active User:\t\t"`w | cut -d ' ' -f1 | grep -v USER | xargs -n1`
echo -e "System Main IP:\t\t"`hostname -I`
echo ""
echo -e "-------------------------------CPU/Memory Usage------------------------------"
echo -e "Memory Usage:\t"`free | awk '/Mem/{printf("%.2f%"), $3/$2*100}'`
echo -e "CPU Usage:\t"`cat /proc/stat | awk '/cpu/{printf("%.2f%\n"), ($2+$4)*100/($2+$4+$5)}' | awk '{print $0}' | head -1`
echo ""
echo -e "-------------------------------Disk Usage >80%-------------------------------"
df -Ph | sed s/%//g | awk '{ if($5 > 80) print $0;}'
echo ""
}
########################################################################
#############################PRINT NETWORK INFO#########################
########################################################################
function display_network_info() {
clear
echo ""
sudo netstat -atunp | grep valheim
echo ""
}
########################################################################
################Display History of Connected Players####################
########################################################################
function display_player_history() {
clear
echo ""
sudo cat /var/log/syslog | grep ZDOID
echo ""
}
########################################################################
#####################Sub Tech Support Menu System#######################
########################################################################
tech_support(){
echo ""
echo -ne "
$(ColorOrange '--------------------Valheim Tech Support--------------------')
$(ColorOrange '-')$(ColorGreen ' 1)') Display Valheim Config File
$(ColorOrange '-')$(ColorGreen ' 2)') Display Valheim Server Service
$(ColorOrange '-')$(ColorGreen ' 3)') Display World Data Folder
$(ColorOrange '-')$(ColorGreen ' 4)') Display System Info
$(ColorOrange '-')$(ColorGreen ' 5)') Display Network Info
$(ColorOrange '-')$(ColorGreen ' 6)') Display Connected Players History
$(ColorOrange '------------------------------------------------------------')
$(ColorOrange '-')$(ColorGreen ' 0)') Go to Main Menu
$(ColorOrange '------------------------------------------------------------')
$(ColorBlue 'Choose an option:') "
read a
case $a in
1) display_start_valheim ; tech_support ;;
2) display_valheim_server_status ; tech_support ;;
3) display_world_data_folder ; tech_support ;;
4) display_system_info ; tech_support ;;
5) display_network_info ; tech_support ;;
6) display_player_history ; tech_support ;;
0) menu ; menu ;;
*) echo -ne " $(ColorRed 'Wrong option.')" ; tech_support ;;
esac
}
########################################################################
########################Sub Admin Menu System###########################
########################################################################
admin_tools_menu(){
echo ""
echo -ne "
$(ColorOrange '-------------Valheim Backup and Restore Tools---------------')
$(ColorOrange '-')$(ColorGreen ' 1)') Backup World
$(ColorOrange '-')$(ColorGreen ' 2)') Restore World
$(ColorOrange '--------------------Valheim Service Tools-------------------')
$(ColorOrange '-')$(ColorGreen ' 3)') Stop Valheim Server
$(ColorOrange '-')$(ColorGreen ' 4)') Start Valheim Server
$(ColorOrange '-')$(ColorGreen ' 5)') Restart Valheim Server
$(ColorOrange '-')$(ColorGreen ' 6)') Status Valheim Server
$(ColorOrange '----------------Official Valheim Server Update--------------')
$(ColorOrange '-')$(ColorGreen ' 7)') Check and Apply Valheim Server Update
$(ColorOrange '------------------First Time or Reinstall-------------------')
$(ColorOrange '-')$(ColorGreen ' 8)') Fresh Valheim Server
$(ColorOrange '------------------------------------------------------------')
$(ColorOrange '-')$(ColorGreen ' 0)') Go to Main Menu
$(ColorBlue 'Choose an option:') "
read a
case $a in
1) backup_world_data ; admin_tools_menu ;;
2) restore_world_data ; admin_tools_menu ;;
3) stop_valheim_server ; admin_tools_menu ;;
4) start_valheim_server ; admin_tools_menu ;;
5) restart_valheim_server ; admin_tools_menu ;;
6) display_valheim_server_status ; admin_tools_menu ;;
7) confirm_check_apply_server_updates ; admin_tools_menu ;;
8) valheim_server_install ; admin_tools_menu ;;
0) menu ; menu ;;
*) echo -ne " $(ColorRed 'Wrong option.')" ; admin_tools_menu ;;