source: bootstrapper/bootstrap.sh@ 35

Last change on this file since 35 was 35, checked in by alloc, 11 years ago

Version 10: Native linux

File size: 6.9 KB
Line 
1#!/bin/bash
2# Version 1
3
4if [ `id -u` -ne 0 ]; then
5 echo "This script has to be run as root!"
6 exit 1
7fi
8
9
10ADDCRONJOBS=0
11RUNINSTALL=0
12INSTALLOPTIONALDEPS=0
13
14DEPENDENCIES="gcc wget tr rsync xmlstarlet"
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
28if [ $IS64BIT -eq 1 ]; then
29 DEPENDENCIES="$DEPENDENCIES lib32gcc1"
30fi
31
32showHelp() {
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
41intro() {
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
53nonDebianWarning() {
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 "Also make sure you have the 32 Bit version of libgcc installed!"
63 echo
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"
82 if [ $IS64BIT -eq 1 ]; then
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
96checkSetupDeps() {
97 which gcc > /dev/null
98 if [ $? -ne 0 ]; then
99 echo "'gcc' not installed. Please install it and run this script again."
100 echo 0
101 return
102 fi
103
104 which wget > /dev/null
105 if [ $? -ne 0 ]; then
106 echo "'wget' not installed. Please install it and run this script again."
107 echo 0
108 return
109 fi
110
111 which tr > /dev/null
112 if [ $? -ne 0 ]; then
113 echo "'tr' not installed. Please install it and run this script again."
114 echo 0
115 return
116 fi
117
118 ldconfig -p | grep gcc | grep -v 64 > /dev/null
119 if [ $? -ne 0 ]; then
120 echo "There probably is no 32 Bit version of libgcc installed."
121 echo "Do you want to continue?"
122 select yn in "Yes" "No"; do
123 case $yn in
124 Yes)
125 break;;
126 No)
127 echo "Aborting."
128 exit 0
129 ;;
130 esac
131 done
132 fi
133
134 echo 1
135}
136
137setupUser() {
138 echo -e "Setting up user and group \"sdtd\"\n"
139 useradd -d /home/sdtd -m -r -s /bin/bash -U sdtd
140 echo -e "\n=============================================================\n\n"
141}
142
143installManagementScripts() {
144 echo -e "Downloading and installing management scripts\n"
145 wget -nv http://illy.bz/fi/7dtd/management_scripts.tar.gz -O /tmp/management_scripts.tar.gz
146 tar --touch -xzf /tmp/management_scripts.tar.gz -C /
147
148 chown root.root /etc/7dtd.conf
149 chmod 0600 /etc/7dtd.conf
150
151 chown sdtd.sdtd /home/sdtd -R
152
153 chown root.root /etc/init.d/7dtd.sh
154 chown root.root /etc/bash_completion.d/7dtd
155 chown root.root /usr/local/bin/7dtd.sh
156 chown root.root /usr/local/lib/7dtd -R
157 chmod 0755 /etc/init.d/7dtd.sh
158 chmod 0755 /etc/bash_completion.d/7dtd
159 chmod 0755 /usr/local/bin/7dtd.sh
160 chmod 0755 /usr/local/lib/7dtd -R
161
162 if [ $ISDEBIAN -eq 1 ]; then
163 update-rc.d 7dtd.sh defaults
164 fi
165
166 echo
167 echo "Compiling start-stop-daemon"
168 cd /usr/local/lib/7dtd/start-stop-daemon
169
170 gcc -Wall -Wextra -Wno-return-type -o start-stop-daemon start-stop-daemon.c
171 chown root.root start-stop-daemon
172 chmod 0755 start-stop-daemon
173
174 echo -e "\n=============================================================\n\n"
175}
176
177installLinuxEngine() {
178 echo -e "Downloading and installing Linux engine\n"
179 wget -nv http://illy.bz/fi/7dtd/linux_files.tar.gz -O /tmp/linux_files.tar.gz
180 tar --touch -xzf /tmp/linux_files.gz -C /home/sdtd/
181
182 chown sdtd.sdtd /home/sdtd/linux_files
183 chmod 0644 /home/sdtd/linux_files
184 chmod 0755 /home/sdtd/linux_files/engine/7DaysToDie.x86
185
186 echo -e "\n=============================================================\n\n"
187}
188
189setSteamLoginData() {
190 echo -e "Steam account data\n"
191 echo "Please enter your Steam login data for SteamCMD to get the 7dtd-server files:"
192 read -p "Steam username: " username
193 read -s -p "Steam password: " password
194 sed -i "s/export STEAM_USER=/export STEAM_USER=$username/" /etc/7dtd.conf
195 sed -i "s/export STEAM_PASS=/export STEAM_PASS=$password/" /etc/7dtd.conf
196 echo -e "\n=============================================================\n\n"
197}
198
199installSteamCmdAndSDTD() {
200 echo -e "Installing SteamCMD and 7DtD\n"
201 7dtd.sh updateengine
202 echo -e "\n=============================================================\n\n"
203}
204
205addCronJobs() {
206 echo -e "Enabling backup cron job\n"
207
208 echo -e "By default a backup of the save folder will be created once"
209 echo -e " per hour. This can be changed in /etc/cron.d/7dtd-backup."
210
211 cat /etc/cron.d/7dtd-backup | tr -d '#' > /tmp/7dtd-backup
212 cp /tmp/7dtd-backup /etc/cron.d
213
214 echo -e "\n=============================================================\n\n"
215}
216
217finish() {
218 if [ $ISDEBIAN -eq 0 ]; then
219 echo
220 echo "You are not running a Debian based distribution."
221 echo "The following things should manually be checked:"
222 echo " - Existence of prerequsities"
223 echo " - Running the init-script on boot"
224 else
225 echo -e "\n ALL DONE"
226 fi
227
228 echo
229 echo -e "You can now continue setting up instances as explained on the website:"
230 echo -e " https://7dtd.illy.bz/wiki/Instance%20management"
231 echo
232 echo -e "You might also need to manually enable bash auto completion, refer to:"
233 echo -e " https://7dtd.illy.bz/wiki/Installation#Bashcompletion"
234 echo
235 echo -e "For further configuration options check:"
236 echo -e " /etc/7dtd.conf"
237 echo
238 echo -e "For feedback, suggestions, problems please visit the bugtracker:"
239 echo -e " https://7dtd.illy.bz/"
240 echo
241}
242
243main() {
244 intro
245 nonDebianWarning
246
247 if [ $ISDEBIAN -eq 1 ]; then
248 installAptDeps
249 if [ $INSTALLOPTIONALDEPS -eq 1 ]; then
250# installOptionalDeps
251 echo
252 fi
253 else
254 if [ $(checkSetupDeps) -eq 0 ]; then
255 return
256 fi
257 fi
258 setupUser
259 installManagementScripts
260 installLinuxEngine
261 setSteamLoginData
262 installSteamCmdAndSDTD
263 if [ $ADDCRONJOBS -eq 1 ]; then
264 addCronJobs
265 fi
266 finish
267}
268
269if [ -z $1 ]; then
270 showHelp
271 exit 0
272fi
273while getopts "hcoi" opt; do
274 case "$opt" in
275 h)
276 showHelp
277 exit 0
278 ;;
279 c)
280 ADDCRONJOBS=1
281 ;;
282 o)
283 INSTALLOPTIONALDEPS=1
284 ;;
285 i)
286 RUNINSTALL=1
287 ;;
288 esac
289done
290if [ $RUNINSTALL -eq 1 ]; then
291 main
292fi
293
Note: See TracBrowser for help on using the repository browser.