forked from Nimdy/Dedicated_Valheim_Server_Script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_dedicated_valheim_server.sh
More file actions
189 lines (165 loc) · 5.22 KB
/
build_dedicated_valheim_server.sh
File metadata and controls
189 lines (165 loc) · 5.22 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
#!/bin/bash
# All in one Script to install Valheim Dedicated Server
# Thanks to nicolas-martin for the variable assignment changes
# Thanks to YT: GeekHead for modivating me to do this
# There are 4 things you need to change!
# NOTE: Minimum password length is 5 characters & Password cant be in the server name.
userpassword="user_password"
password="passw0rd"
displayname="server display name"
worldname="111111111"
#check for updates and upgrade the system auto yes
tput setaf 2; echo "Checking for upgrades"
apt update && apt upgrade -y
tput setaf 2; echo "Done"
tput setaf 9;
sleep 1
#add multiverse repo
tput setaf 2; echo "Adding multiverse REPO"
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"
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"
apt update
tput setaf 2; echo "Done"
tput setaf 9;
sleep 1
#install steamcmd
tput setaf 1; echo "Installing steamcmd"
apt install steamcmd -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"
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"
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"
chown steam:steam /home/steam/steamcmd
tput setaf 2; echo "Done"
tput setaf 9;
sleep 1
#Download Valheim from steam
tput setaf 1; echo "Downloading and installing Valheim from Steam"
sleep 1
tput setaf 9;
/home/steam/steamcmd +login anonymous +force_install_dir /home/steam/valheimserver +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 1; echo "Building Valheim start_valheim server configuration"
rm /home/steam/valheimserver/start_valheim.sh
sleep 1
cat >> /home/steam/valheimserver/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
EOF
tput setaf 2; echo "Done"
tput setaf 9;
sleep 1
#build check log script
tput setaf 1; echo "Deleting old configuration if file exist"
tput setaf 1; echo "Building check log script"
rm /home/steam/check_log.sh
sleep 1
cat >> /home/steam/check_log.sh <<EOF
journalctl --unit=valheimserver --reverse
EOF
tput setaf 2; echo "Done"
tput setaf 9;
sleep 1
#set execute permissions
tput setaf 1; echo "Setting execute permissions on start_valheim.sh"
chmod +x /home/steam/valheimserver/start_valheim.sh
tput setaf 2; echo "Done"
tput setaf 1; echo "Setting execute permissions on check_log.sh"
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 1; echo "Building systemctl instructions for Valheim"
rm /etc/systemd/system/valheimserver.service
sleep 1
cat >> /etc/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 /home/steam/valheimserver +app_update 896660 validate +exit
ExecStart=/home/steam/valheimserver/start_valheim.sh
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGINT
WorkingDirectory=/home/steam/valheimserver
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/*"
chown steam:steam -Rf /home/steam/*
tput setaf 2; echo "Done"
tput setaf 9;
sleep 1
# Reload daemons
tput setaf 1; echo "Reloading daemons"
systemctl daemon-reload
tput setaf 2; echo "Done"
sleep 1
# Start server
tput setaf 1; echo "Starting Valheim Server"
systemctl start valheimserver
tput setaf 2; echo "Done"
sleep 1
# Enable server on restarts
tput setaf 1; echo "Enabling Valheim Server on start or after reboots"
systemctl enable valheimserver
tput setaf 2; echo "Done"
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 "Twitch: ZeroBandwidth"
tput setaf 2; echo "GLHF"
tput setaf 9;