source: bootstrapper/bootstrap.sh@ 259

Last change on this file since 259 was 258, checked in by alloc, 9 years ago

Scripts: License

File size: 7.0 KB
Line 
1#!/bin/bash
2VERSION=7
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
19if [ `id -u` -ne 0 ]; then
20 echo "This script has to be run as root!"
21 exit 1
22fi
23
24
25ADDCRONJOBS=0
26RUNINSTALL=0
27INSTALLOPTIONALDEPS=0
28
29DEPENDENCIES="gcc wget rsync xmlstarlet"
30
31if [ -n "$(command -v apt-get)" ]; then
32 ISDEBIAN=1
33else
34 ISDEBIAN=0
35fi
36
37if [ $(uname -m) == 'x86_64' ]; then
38 IS64BIT=1
39else
40 IS64BIT=0
41fi
42
43if [ $IS64BIT -eq 1 ]; then
44 DEPENDENCIES="$DEPENDENCIES lib32gcc1"
45fi
46
47showHelp() {
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
58intro() {
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
70nonDebianWarning() {
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
95installAptDeps() {
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
105installOptionalDeps() {
106 echo -e "Installing optional dependencies\n"
107 apt-get install $OPTDEPENDENCIES
108 echo -e "\n=============================================================\n\n"
109}
110
111checkSetupDeps() {
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
158setupUser() {
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
164installManagementScripts() {
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 tar --touch --no-overwrite-dir -xzf /tmp/management_scripts.tar.gz -C /
168
169 chown root.root /etc/7dtd.conf
170 chmod 0600 /etc/7dtd.conf
171
172 chown sdtd.sdtd /home/sdtd -R
173
174 chown root.root /etc/init.d/7dtd.sh
175 chown root.root /etc/bash_completion.d/7dtd
176 chown root.root /etc/cron.d/7dtd-backup
177 chown root.root /usr/local/bin/7dtd.sh
178 chown root.root /usr/local/lib/7dtd -R
179 chmod 0755 /etc/init.d/7dtd.sh
180 chmod 0755 /etc/bash_completion.d/7dtd
181 chmod 0755 /etc/cron.d/7dtd-backup
182 chmod 0755 /usr/local/bin/7dtd.sh
183 chmod 0755 /usr/local/lib/7dtd -R
184
185 if [ $ISDEBIAN -eq 1 ]; then
186 update-rc.d 7dtd.sh defaults
187 fi
188
189 echo
190 echo "Compiling start-stop-daemon"
191 cd /usr/local/lib/7dtd/start-stop-daemon
192
193 gcc -Wall -Wextra -Wno-return-type -o start-stop-daemon start-stop-daemon.c
194 chown root.root start-stop-daemon
195 chmod 0755 start-stop-daemon
196
197 echo -e "\n=============================================================\n\n"
198}
199
200installSteamCmdAndSDTD() {
201 echo -e "Installing SteamCMD and 7DtD\n"
202 7dtd.sh updateengine
203 echo -e "\n=============================================================\n\n"
204}
205
206addCronJobs() {
207 echo -e "Enabling backup cron job\n"
208
209 echo -e "By default a backup of the save folder will be created once"
210 echo -e " per hour. This can be changed in /etc/cron.d/7dtd-backup."
211
212 cat /etc/cron.d/7dtd-backup | tr -d '#' > /tmp/7dtd-backup
213 cp /tmp/7dtd-backup /etc/cron.d
214
215 echo -e "\n=============================================================\n\n"
216}
217
218finish() {
219 if [ $ISDEBIAN -eq 0 ]; then
220 echo
221 echo "You are not running a Debian based distribution."
222 echo "The following things should manually be checked:"
223 echo " - Existence of prerequsities"
224 echo " - Running the init-script on boot"
225 else
226 echo -e "\n ALL DONE"
227 fi
228
229 echo
230 echo -e "You can now continue setting up instances as explained on the website:"
231 echo -e " https://7dtd.illy.bz/wiki/Instance%20management"
232 echo
233 echo -e "You might also need to manually enable bash auto completion, refer to:"
234 echo -e " https://7dtd.illy.bz/wiki/Installation#Bashcompletion"
235 echo
236 echo -e "For further configuration options check:"
237 echo -e " /etc/7dtd.conf"
238 echo
239 echo -e "For feedback, suggestions, problems please visit the bugtracker:"
240 echo -e " https://7dtd.illy.bz/"
241 echo
242}
243
244main() {
245 intro
246 nonDebianWarning
247
248 if [ $ISDEBIAN -eq 1 ]; then
249 installAptDeps
250 if [ $INSTALLOPTIONALDEPS -eq 1 ]; then
251# installOptionalDeps
252 echo
253 fi
254 else
255 checkSetupDeps
256 fi
257 setupUser
258 installManagementScripts
259 installSteamCmdAndSDTD
260 if [ $ADDCRONJOBS -eq 1 ]; then
261 addCronJobs
262 fi
263 finish
264}
265
266if [ -z $1 ]; then
267 showHelp
268 exit 0
269fi
270while getopts "hcoi" opt; do
271 case "$opt" in
272 h)
273 showHelp
274 exit 0
275 ;;
276 c)
277 ADDCRONJOBS=1
278 ;;
279 o)
280 INSTALLOPTIONALDEPS=1
281 ;;
282 i)
283 RUNINSTALL=1
284 ;;
285 esac
286done
287if [ $RUNINSTALL -eq 1 ]; then
288 main
289fi
290
Note: See TracBrowser for help on using the repository browser.