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