source: bootstrapper/bootstrap.sh@ 196

Last change on this file since 196 was 65, checked in by alloc, 10 years ago

Bootstrapper v4

File size: 7.4 KB
RevLine 
[1]1#!/bin/bash
[65]2VERSION=4
[1]3
[30]4if [ `id -u` -ne 0 ]; then
5 echo "This script has to be run as root!"
6 exit 1
7fi
8
9
[1]10ADDCRONJOBS=0
11RUNINSTALL=0
[32]12INSTALLOPTIONALDEPS=0
[1]13
[44]14DEPENDENCIES="gcc wget rsync xmlstarlet"
[1]15
16if [ -n "$(command -v apt-get)" ]; then
17 ISDEBIAN=1
18else
19 ISDEBIAN=0
20fi
21
22if [ $(uname -m) == 'x86_64' ]; then
23 IS64BIT=1
24else
25 IS64BIT=0
26fi
27
[30]28if [ $IS64BIT -eq 1 ]; then
[35]29 DEPENDENCIES="$DEPENDENCIES lib32gcc1"
[1]30fi
31
32showHelp() {
[48]33 echo "7dtd bootstrapper version $VERSION"
34 echo
[30]35 echo "Usage: ./bootstrap.sh [-h] [-c] -i"
[1]36 echo "Parameters:"
37 echo " -h Print this help screen and exit"
[30]38# echo " -o Install optional dependencies ($OPTDEPENDENCIES)"
[31]39 echo " -c Enable cron job for automatic backups"
[1]40 echo " -i Required to actually start the installation"
41}
42
43intro() {
44 echo
45 echo "7DtD Linux dedicated server bootstrapper"
46 echo
47 echo "This will install a 7DtD server according to the information"
48 echo "given on:"
[30]49 echo " https://7dtd.illy.bz/"
[1]50 echo
51 read -p "Press enter to continue"
52 echo -e "\n=============================================================\n\n"
53}
54
55nonDebianWarning() {
[30]56 if [ $ISDEBIAN -eq 0 ]; then
[1]57 echo "NOTE: It seems like this system is not based on Debian."
58 echo "Although installation of the scripts and SteamCMD/7dtd"
59 echo "will work the installed management scripts will probably"
[30]60 echo "fail because of missing dependencies. Make sure you check"
61 echo "the website regarding the prerequisites"
62 echo "(https://7dtd.illy.bz)."
[35]63 echo
[1]64 echo "Do you want to continue anyway?"
65 select yn in "Yes" "No"; do
66 case $yn in
67 Yes)
68 echo "Continuing..."
69 break;;
70 No)
71 echo "Aborting."
72 exit 0
73 ;;
74 esac
75 done
76 echo -e "\n=============================================================\n\n"
77 fi
78}
79
80installAptDeps() {
81 echo -e "Installing dependencies\n"
[30]82 if [ $IS64BIT -eq 1 ]; then
[1]83 dpkg --add-architecture i386
84 fi
85 apt-get update
86 apt-get install $DEPENDENCIES
87 echo -e "\n=============================================================\n\n"
88}
89
90installOptionalDeps() {
91 echo -e "Installing optional dependencies\n"
92 apt-get install $OPTDEPENDENCIES
93 echo -e "\n=============================================================\n\n"
94}
95
[32]96checkSetupDeps() {
[40]97 for DEP in gcc wget tr rsync xmlstarlet; do
[41]98 which $DEP > /dev/null 2>&1
[39]99 if [ $? -ne 0 ]; then
100 echo "\"$DEP\" not installed. Please install it and run this script again."
101 exit 1
102 fi
103 done
[35]104
[42]105 ldconfig -p | grep ld-linux | grep "(ELF)" > /dev/null
106 if [ $? -ne 0 ]; then
107 echo "WARNING: There probably is no 32 Bit version of ld-linux installed."
108 echo "This is most probably part of a 32 Bit version of a glibc-package."
[43]109 echo
110 echo "It will result in errors trying to run SteamCMD if this library is not available!."
[42]111 echo "Do you want to continue anyway?"
112 select yn in "Yes" "No"; do
113 case $yn in
114 Yes)
115 break;;
116 No)
117 echo "Aborting."
118 exit 1
119 ;;
120 esac
121 done
122 fi
123
[35]124 ldconfig -p | grep gcc | grep -v 64 > /dev/null
125 if [ $? -ne 0 ]; then
[42]126 echo "WARNING: There probably is no 32 Bit version of libgcc installed."
[43]127 echo
128 echo "It will result in errors trying to run SteamCMD if this library is not available!"
[42]129 echo "Do you want to continue anyway?"
[35]130 select yn in "Yes" "No"; do
131 case $yn in
132 Yes)
133 break;;
134 No)
135 echo "Aborting."
[38]136 exit 1
[35]137 ;;
138 esac
139 done
140 fi
[32]141}
142
[1]143setupUser() {
144 echo -e "Setting up user and group \"sdtd\"\n"
145 useradd -d /home/sdtd -m -r -s /bin/bash -U sdtd
146 echo -e "\n=============================================================\n\n"
147}
148
149installManagementScripts() {
150 echo -e "Downloading and installing management scripts\n"
151 wget -nv http://illy.bz/fi/7dtd/management_scripts.tar.gz -O /tmp/management_scripts.tar.gz
[51]152 tar --touch --no-overwrite-dir -xzf /tmp/management_scripts.tar.gz -C /
[30]153
154 chown root.root /etc/7dtd.conf
155 chmod 0600 /etc/7dtd.conf
156
157 chown sdtd.sdtd /home/sdtd -R
158
159 chown root.root /etc/init.d/7dtd.sh
160 chown root.root /etc/bash_completion.d/7dtd
[65]161 chown root.root /etc/cron.d/7dtd-backup
[30]162 chown root.root /usr/local/bin/7dtd.sh
163 chown root.root /usr/local/lib/7dtd -R
164 chmod 0755 /etc/init.d/7dtd.sh
165 chmod 0755 /etc/bash_completion.d/7dtd
[65]166 chmod 0755 /etc/cron.d/7dtd-backup
[30]167 chmod 0755 /usr/local/bin/7dtd.sh
168 chmod 0755 /usr/local/lib/7dtd -R
169
170 if [ $ISDEBIAN -eq 1 ]; then
[1]171 update-rc.d 7dtd.sh defaults
[32]172 fi
173
174 echo
175 echo "Compiling start-stop-daemon"
176 cd /usr/local/lib/7dtd/start-stop-daemon
[31]177
[32]178 gcc -Wall -Wextra -Wno-return-type -o start-stop-daemon start-stop-daemon.c
179 chown root.root start-stop-daemon
180 chmod 0755 start-stop-daemon
181
[1]182 echo -e "\n=============================================================\n\n"
183}
184
[35]185installLinuxEngine() {
186 echo -e "Downloading and installing Linux engine\n"
187 wget -nv http://illy.bz/fi/7dtd/linux_files.tar.gz -O /tmp/linux_files.tar.gz
[36]188 tar --touch -xzf /tmp/linux_files.tar.gz -C /home/sdtd/
[35]189
[37]190 chown sdtd.sdtd -R /home/sdtd/linux_files
[36]191 chmod 0644 -R /home/sdtd/linux_files
[37]192 find /home/sdtd/linux_files -type d -exec chmod 0755 {} \;
[35]193 chmod 0755 /home/sdtd/linux_files/engine/7DaysToDie.x86
194
195 echo -e "\n=============================================================\n\n"
196}
197
[1]198setSteamLoginData() {
199 echo -e "Steam account data\n"
200 echo "Please enter your Steam login data for SteamCMD to get the 7dtd-server files:"
201 read -p "Steam username: " username
202 read -s -p "Steam password: " password
203 sed -i "s/export STEAM_USER=/export STEAM_USER=$username/" /etc/7dtd.conf
204 sed -i "s/export STEAM_PASS=/export STEAM_PASS=$password/" /etc/7dtd.conf
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
[35]267 installLinuxEngine
[1]268 setSteamLoginData
269 installSteamCmdAndSDTD
[30]270 if [ $ADDCRONJOBS -eq 1 ]; then
[1]271 addCronJobs
272 fi
273 finish
274}
275
[30]276if [ -z $1 ]; then
[1]277 showHelp
278 exit 0
279fi
280while getopts "hcoi" opt; do
281 case "$opt" in
282 h)
283 showHelp
284 exit 0
285 ;;
286 c)
287 ADDCRONJOBS=1
288 ;;
289 o)
290 INSTALLOPTIONALDEPS=1
291 ;;
292 i)
293 RUNINSTALL=1
294 ;;
295 esac
296done
[30]297if [ $RUNINSTALL -eq 1 ]; then
[1]298 main
299fi
300
Note: See TracBrowser for help on using the repository browser.