1 | #!/bin/bash
|
---|
2 | # Version 1
|
---|
3 |
|
---|
4 | if [ `id -u` -ne 0 ]; then
|
---|
5 | echo "This script has to be run as root!"
|
---|
6 | exit 1
|
---|
7 | fi
|
---|
8 |
|
---|
9 |
|
---|
10 | ADDCRONJOBS=0
|
---|
11 | RUNINSTALL=0
|
---|
12 | INSTALLOPTIONALDEPS=0
|
---|
13 |
|
---|
14 | DEPENDENCIES="gcc wget rsync xmlstarlet"
|
---|
15 |
|
---|
16 | if [ -n "$(command -v apt-get)" ]; then
|
---|
17 | ISDEBIAN=1
|
---|
18 | else
|
---|
19 | ISDEBIAN=0
|
---|
20 | fi
|
---|
21 |
|
---|
22 | if [ $(uname -m) == 'x86_64' ]; then
|
---|
23 | IS64BIT=1
|
---|
24 | else
|
---|
25 | IS64BIT=0
|
---|
26 | fi
|
---|
27 |
|
---|
28 | if [ $IS64BIT -eq 1 ]; then
|
---|
29 | DEPENDENCIES="$DEPENDENCIES lib32gcc1"
|
---|
30 | fi
|
---|
31 |
|
---|
32 | showHelp() {
|
---|
33 | echo "Usage: ./bootstrap.sh [-h] [-c] -i"
|
---|
34 | echo "Parameters:"
|
---|
35 | echo " -h Print this help screen and exit"
|
---|
36 | # echo " -o Install optional dependencies ($OPTDEPENDENCIES)"
|
---|
37 | echo " -c Enable cron job for automatic backups"
|
---|
38 | echo " -i Required to actually start the installation"
|
---|
39 | }
|
---|
40 |
|
---|
41 | intro() {
|
---|
42 | echo
|
---|
43 | echo "7DtD Linux dedicated server bootstrapper"
|
---|
44 | echo
|
---|
45 | echo "This will install a 7DtD server according to the information"
|
---|
46 | echo "given on:"
|
---|
47 | echo " https://7dtd.illy.bz/"
|
---|
48 | echo
|
---|
49 | read -p "Press enter to continue"
|
---|
50 | echo -e "\n=============================================================\n\n"
|
---|
51 | }
|
---|
52 |
|
---|
53 | nonDebianWarning() {
|
---|
54 | if [ $ISDEBIAN -eq 0 ]; then
|
---|
55 | echo "NOTE: It seems like this system is not based on Debian."
|
---|
56 | echo "Although installation of the scripts and SteamCMD/7dtd"
|
---|
57 | echo "will work the installed management scripts will probably"
|
---|
58 | echo "fail because of missing dependencies. Make sure you check"
|
---|
59 | echo "the website regarding the prerequisites"
|
---|
60 | echo "(https://7dtd.illy.bz)."
|
---|
61 | echo
|
---|
62 | echo "Do you want to continue anyway?"
|
---|
63 | select yn in "Yes" "No"; do
|
---|
64 | case $yn in
|
---|
65 | Yes)
|
---|
66 | echo "Continuing..."
|
---|
67 | break;;
|
---|
68 | No)
|
---|
69 | echo "Aborting."
|
---|
70 | exit 0
|
---|
71 | ;;
|
---|
72 | esac
|
---|
73 | done
|
---|
74 | echo -e "\n=============================================================\n\n"
|
---|
75 | fi
|
---|
76 | }
|
---|
77 |
|
---|
78 | installAptDeps() {
|
---|
79 | echo -e "Installing dependencies\n"
|
---|
80 | if [ $IS64BIT -eq 1 ]; then
|
---|
81 | dpkg --add-architecture i386
|
---|
82 | fi
|
---|
83 | apt-get update
|
---|
84 | apt-get install $DEPENDENCIES
|
---|
85 | echo -e "\n=============================================================\n\n"
|
---|
86 | }
|
---|
87 |
|
---|
88 | installOptionalDeps() {
|
---|
89 | echo -e "Installing optional dependencies\n"
|
---|
90 | apt-get install $OPTDEPENDENCIES
|
---|
91 | echo -e "\n=============================================================\n\n"
|
---|
92 | }
|
---|
93 |
|
---|
94 | checkSetupDeps() {
|
---|
95 | for DEP in gcc wget tr rsync xmlstarlet; do
|
---|
96 | which $DEP > /dev/null 2>&1
|
---|
97 | if [ $? -ne 0 ]; then
|
---|
98 | echo "\"$DEP\" not installed. Please install it and run this script again."
|
---|
99 | exit 1
|
---|
100 | fi
|
---|
101 | done
|
---|
102 |
|
---|
103 | ldconfig -p | grep ld-linux | grep "(ELF)" > /dev/null
|
---|
104 | if [ $? -ne 0 ]; then
|
---|
105 | echo "WARNING: There probably is no 32 Bit version of ld-linux installed."
|
---|
106 | echo "This is most probably part of a 32 Bit version of a glibc-package."
|
---|
107 | echo
|
---|
108 | echo "It will result in errors trying to run SteamCMD if this library is not available!."
|
---|
109 | echo "Do you want to continue anyway?"
|
---|
110 | select yn in "Yes" "No"; do
|
---|
111 | case $yn in
|
---|
112 | Yes)
|
---|
113 | break;;
|
---|
114 | No)
|
---|
115 | echo "Aborting."
|
---|
116 | exit 1
|
---|
117 | ;;
|
---|
118 | esac
|
---|
119 | done
|
---|
120 | fi
|
---|
121 |
|
---|
122 | ldconfig -p | grep gcc | grep -v 64 > /dev/null
|
---|
123 | if [ $? -ne 0 ]; then
|
---|
124 | echo "WARNING: There probably is no 32 Bit version of libgcc installed."
|
---|
125 | echo
|
---|
126 | echo "It will result in errors trying to run SteamCMD if this library is not available!"
|
---|
127 | echo "Do you want to continue anyway?"
|
---|
128 | select yn in "Yes" "No"; do
|
---|
129 | case $yn in
|
---|
130 | Yes)
|
---|
131 | break;;
|
---|
132 | No)
|
---|
133 | echo "Aborting."
|
---|
134 | exit 1
|
---|
135 | ;;
|
---|
136 | esac
|
---|
137 | done
|
---|
138 | fi
|
---|
139 | }
|
---|
140 |
|
---|
141 | setupUser() {
|
---|
142 | echo -e "Setting up user and group \"sdtd\"\n"
|
---|
143 | useradd -d /home/sdtd -m -r -s /bin/bash -U sdtd
|
---|
144 | echo -e "\n=============================================================\n\n"
|
---|
145 | }
|
---|
146 |
|
---|
147 | installManagementScripts() {
|
---|
148 | echo -e "Downloading and installing management scripts\n"
|
---|
149 | wget -nv http://illy.bz/fi/7dtd/management_scripts.tar.gz -O /tmp/management_scripts.tar.gz
|
---|
150 | tar --touch -xzf /tmp/management_scripts.tar.gz -C /
|
---|
151 |
|
---|
152 | chown root.root /etc/7dtd.conf
|
---|
153 | chmod 0600 /etc/7dtd.conf
|
---|
154 |
|
---|
155 | chown sdtd.sdtd /home/sdtd -R
|
---|
156 |
|
---|
157 | chown root.root /etc/init.d/7dtd.sh
|
---|
158 | chown root.root /etc/bash_completion.d/7dtd
|
---|
159 | chown root.root /usr/local/bin/7dtd.sh
|
---|
160 | chown root.root /usr/local/lib/7dtd -R
|
---|
161 | chmod 0755 /etc/init.d/7dtd.sh
|
---|
162 | chmod 0755 /etc/bash_completion.d/7dtd
|
---|
163 | chmod 0755 /usr/local/bin/7dtd.sh
|
---|
164 | chmod 0755 /usr/local/lib/7dtd -R
|
---|
165 |
|
---|
166 | if [ $ISDEBIAN -eq 1 ]; then
|
---|
167 | update-rc.d 7dtd.sh defaults
|
---|
168 | fi
|
---|
169 |
|
---|
170 | echo
|
---|
171 | echo "Compiling start-stop-daemon"
|
---|
172 | cd /usr/local/lib/7dtd/start-stop-daemon
|
---|
173 |
|
---|
174 | gcc -Wall -Wextra -Wno-return-type -o start-stop-daemon start-stop-daemon.c
|
---|
175 | chown root.root start-stop-daemon
|
---|
176 | chmod 0755 start-stop-daemon
|
---|
177 |
|
---|
178 | echo -e "\n=============================================================\n\n"
|
---|
179 | }
|
---|
180 |
|
---|
181 | installLinuxEngine() {
|
---|
182 | echo -e "Downloading and installing Linux engine\n"
|
---|
183 | wget -nv http://illy.bz/fi/7dtd/linux_files.tar.gz -O /tmp/linux_files.tar.gz
|
---|
184 | tar --touch -xzf /tmp/linux_files.tar.gz -C /home/sdtd/
|
---|
185 |
|
---|
186 | chown sdtd.sdtd -R /home/sdtd/linux_files
|
---|
187 | chmod 0644 -R /home/sdtd/linux_files
|
---|
188 | find /home/sdtd/linux_files -type d -exec chmod 0755 {} \;
|
---|
189 | chmod 0755 /home/sdtd/linux_files/engine/7DaysToDie.x86
|
---|
190 |
|
---|
191 | echo -e "\n=============================================================\n\n"
|
---|
192 | }
|
---|
193 |
|
---|
194 | setSteamLoginData() {
|
---|
195 | echo -e "Steam account data\n"
|
---|
196 | echo "Please enter your Steam login data for SteamCMD to get the 7dtd-server files:"
|
---|
197 | read -p "Steam username: " username
|
---|
198 | read -s -p "Steam password: " password
|
---|
199 | sed -i "s/export STEAM_USER=/export STEAM_USER=$username/" /etc/7dtd.conf
|
---|
200 | sed -i "s/export STEAM_PASS=/export STEAM_PASS=$password/" /etc/7dtd.conf
|
---|
201 | echo -e "\n=============================================================\n\n"
|
---|
202 | }
|
---|
203 |
|
---|
204 | installSteamCmdAndSDTD() {
|
---|
205 | echo -e "Installing SteamCMD and 7DtD\n"
|
---|
206 | 7dtd.sh updateengine
|
---|
207 | echo -e "\n=============================================================\n\n"
|
---|
208 | }
|
---|
209 |
|
---|
210 | addCronJobs() {
|
---|
211 | echo -e "Enabling backup cron job\n"
|
---|
212 |
|
---|
213 | echo -e "By default a backup of the save folder will be created once"
|
---|
214 | echo -e " per hour. This can be changed in /etc/cron.d/7dtd-backup."
|
---|
215 |
|
---|
216 | cat /etc/cron.d/7dtd-backup | tr -d '#' > /tmp/7dtd-backup
|
---|
217 | cp /tmp/7dtd-backup /etc/cron.d
|
---|
218 |
|
---|
219 | echo -e "\n=============================================================\n\n"
|
---|
220 | }
|
---|
221 |
|
---|
222 | finish() {
|
---|
223 | if [ $ISDEBIAN -eq 0 ]; then
|
---|
224 | echo
|
---|
225 | echo "You are not running a Debian based distribution."
|
---|
226 | echo "The following things should manually be checked:"
|
---|
227 | echo " - Existence of prerequsities"
|
---|
228 | echo " - Running the init-script on boot"
|
---|
229 | else
|
---|
230 | echo -e "\n ALL DONE"
|
---|
231 | fi
|
---|
232 |
|
---|
233 | echo
|
---|
234 | echo -e "You can now continue setting up instances as explained on the website:"
|
---|
235 | echo -e " https://7dtd.illy.bz/wiki/Instance%20management"
|
---|
236 | echo
|
---|
237 | echo -e "You might also need to manually enable bash auto completion, refer to:"
|
---|
238 | echo -e " https://7dtd.illy.bz/wiki/Installation#Bashcompletion"
|
---|
239 | echo
|
---|
240 | echo -e "For further configuration options check:"
|
---|
241 | echo -e " /etc/7dtd.conf"
|
---|
242 | echo
|
---|
243 | echo -e "For feedback, suggestions, problems please visit the bugtracker:"
|
---|
244 | echo -e " https://7dtd.illy.bz/"
|
---|
245 | echo
|
---|
246 | }
|
---|
247 |
|
---|
248 | main() {
|
---|
249 | intro
|
---|
250 | nonDebianWarning
|
---|
251 |
|
---|
252 | if [ $ISDEBIAN -eq 1 ]; then
|
---|
253 | installAptDeps
|
---|
254 | if [ $INSTALLOPTIONALDEPS -eq 1 ]; then
|
---|
255 | # installOptionalDeps
|
---|
256 | echo
|
---|
257 | fi
|
---|
258 | else
|
---|
259 | checkSetupDeps
|
---|
260 | fi
|
---|
261 | setupUser
|
---|
262 | installManagementScripts
|
---|
263 | installLinuxEngine
|
---|
264 | setSteamLoginData
|
---|
265 | installSteamCmdAndSDTD
|
---|
266 | if [ $ADDCRONJOBS -eq 1 ]; then
|
---|
267 | addCronJobs
|
---|
268 | fi
|
---|
269 | finish
|
---|
270 | }
|
---|
271 |
|
---|
272 | if [ -z $1 ]; then
|
---|
273 | showHelp
|
---|
274 | exit 0
|
---|
275 | fi
|
---|
276 | while getopts "hcoi" opt; do
|
---|
277 | case "$opt" in
|
---|
278 | h)
|
---|
279 | showHelp
|
---|
280 | exit 0
|
---|
281 | ;;
|
---|
282 | c)
|
---|
283 | ADDCRONJOBS=1
|
---|
284 | ;;
|
---|
285 | o)
|
---|
286 | INSTALLOPTIONALDEPS=1
|
---|
287 | ;;
|
---|
288 | i)
|
---|
289 | RUNINSTALL=1
|
---|
290 | ;;
|
---|
291 | esac
|
---|
292 | done
|
---|
293 | if [ $RUNINSTALL -eq 1 ]; then
|
---|
294 | main
|
---|
295 | fi
|
---|
296 |
|
---|