source: bootstrapper/bootstrap.sh@ 331

Last change on this file since 331 was 264, checked in by alloc, 9 years ago

v99 + bootstrapper 9

File size: 7.2 KB
RevLine 
[1]1#!/bin/bash
[264]2VERSION=8
[1]3
[258]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
[30]19if [ `id -u` -ne 0 ]; then
20 echo "This script has to be run as root!"
21 exit 1
22fi
23
24
[1]25ADDCRONJOBS=0
26RUNINSTALL=0
[32]27INSTALLOPTIONALDEPS=0
[1]28
[44]29DEPENDENCIES="gcc wget rsync xmlstarlet"
[1]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
[30]43if [ $IS64BIT -eq 1 ]; then
[35]44 DEPENDENCIES="$DEPENDENCIES lib32gcc1"
[1]45fi
46
47showHelp() {
[48]48 echo "7dtd bootstrapper version $VERSION"
49 echo
[30]50 echo "Usage: ./bootstrap.sh [-h] [-c] -i"
[1]51 echo "Parameters:"
52 echo " -h Print this help screen and exit"
[30]53# echo " -o Install optional dependencies ($OPTDEPENDENCIES)"
[31]54 echo " -c Enable cron job for automatic backups"
[1]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:"
[30]64 echo " https://7dtd.illy.bz/"
[1]65 echo
66 read -p "Press enter to continue"
67 echo -e "\n=============================================================\n\n"
68}
69
70nonDebianWarning() {
[30]71 if [ $ISDEBIAN -eq 0 ]; then
[1]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"
[30]75 echo "fail because of missing dependencies. Make sure you check"
76 echo "the website regarding the prerequisites"
77 echo "(https://7dtd.illy.bz)."
[35]78 echo
[1]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"
[30]97 if [ $IS64BIT -eq 1 ]; then
[1]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
[32]111checkSetupDeps() {
[40]112 for DEP in gcc wget tr rsync xmlstarlet; do
[41]113 which $DEP > /dev/null 2>&1
[39]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
[35]119
[42]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."
[43]124 echo
125 echo "It will result in errors trying to run SteamCMD if this library is not available!."
[42]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
[35]139 ldconfig -p | grep gcc | grep -v 64 > /dev/null
140 if [ $? -ne 0 ]; then
[42]141 echo "WARNING: There probably is no 32 Bit version of libgcc installed."
[43]142 echo
143 echo "It will result in errors trying to run SteamCMD if this library is not available!"
[42]144 echo "Do you want to continue anyway?"
[35]145 select yn in "Yes" "No"; do
146 case $yn in
147 Yes)
148 break;;
149 No)
150 echo "Aborting."
[38]151 exit 1
[35]152 ;;
153 esac
154 done
155 fi
[32]156}
157
[1]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
[263]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
[30]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
[65]184 chown root.root /etc/cron.d/7dtd-backup
[30]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
[65]189 chmod 0755 /etc/cron.d/7dtd-backup
[30]190 chmod 0755 /usr/local/bin/7dtd.sh
191 chmod 0755 /usr/local/lib/7dtd -R
192
193 if [ $ISDEBIAN -eq 1 ]; then
[1]194 update-rc.d 7dtd.sh defaults
[32]195 fi
196
197 echo
198 echo "Compiling start-stop-daemon"
199 cd /usr/local/lib/7dtd/start-stop-daemon
[31]200
[32]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
[1]205 echo -e "\n=============================================================\n\n"
206}
207
208installSteamCmdAndSDTD() {
209 echo -e "Installing SteamCMD and 7DtD\n"
[30]210 7dtd.sh updateengine
[1]211 echo -e "\n=============================================================\n\n"
212}
213
214addCronJobs() {
[30]215 echo -e "Enabling backup cron job\n"
[1]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."
[30]219
220 cat /etc/cron.d/7dtd-backup | tr -d '#' > /tmp/7dtd-backup
221 cp /tmp/7dtd-backup /etc/cron.d
[1]222
223 echo -e "\n=============================================================\n\n"
224}
225
226finish() {
[30]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
[1]237 echo
[30]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
[31]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
[1]244 echo -e "For further configuration options check:"
245 echo -e " /etc/7dtd.conf"
246 echo
[30]247 echo -e "For feedback, suggestions, problems please visit the bugtracker:"
248 echo -e " https://7dtd.illy.bz/"
[1]249 echo
250}
251
252main() {
253 intro
254 nonDebianWarning
255
[30]256 if [ $ISDEBIAN -eq 1 ]; then
[1]257 installAptDeps
[30]258 if [ $INSTALLOPTIONALDEPS -eq 1 ]; then
259# installOptionalDeps
[1]260 echo
261 fi
[32]262 else
[38]263 checkSetupDeps
[1]264 fi
265 setupUser
266 installManagementScripts
267 installSteamCmdAndSDTD
[30]268 if [ $ADDCRONJOBS -eq 1 ]; then
[1]269 addCronJobs
270 fi
271 finish
272}
273
[30]274if [ -z $1 ]; then
[1]275 showHelp
276 exit 0
277fi
278while 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
294done
[30]295if [ $RUNINSTALL -eq 1 ]; then
[1]296 main
297fi
298
Note: See TracBrowser for help on using the repository browser.