source: bootstrapper/bootstrap.sh@ 33

Last change on this file since 33 was 32, checked in by alloc, 10 years ago

Bootstrapper update

File size: 6.3 KB
RevLine 
[1]1#!/bin/bash
[30]2# Version 1
[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
[32]14DEPENDENCIES="gcc wget tr xvfb mono-runtime rsync xmlstarlet gcc"
[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
[1]29 DEPENDENCIES="$DEPENDENCIES lib32gcc1 wine:i386"
30else
31 DEPENDENCIES="$DEPENDENCIES wine"
32fi
33
34showHelp() {
[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)."
[1]63 echo "Do you want to continue anyway?"
64 select yn in "Yes" "No"; do
65 case $yn in
66 Yes)
67 echo "Continuing..."
68 break;;
69 No)
70 echo "Aborting."
71 exit 0
72 ;;
73 esac
74 done
75 echo -e "\n=============================================================\n\n"
76 fi
77}
78
79installAptDeps() {
80 echo -e "Installing dependencies\n"
[30]81 if [ $IS64BIT -eq 1 ]; then
[1]82 dpkg --add-architecture i386
83 fi
84 apt-get update
85 apt-get install $DEPENDENCIES
86 echo -e "\n=============================================================\n\n"
87}
88
89installOptionalDeps() {
90 echo -e "Installing optional dependencies\n"
91 apt-get install $OPTDEPENDENCIES
92 echo -e "\n=============================================================\n\n"
93}
94
[32]95checkSetupDeps() {
96 which gcc > /dev/null
97 if [ $? -ne 0 ]; then
98 echo "'gcc' not installed. Please install it and run this script again."
99 echo 0
100 return
101 fi
102
103 which wget > /dev/null
104 if [ $? -ne 0 ]; then
105 echo "'wget' not installed. Please install it and run this script again."
106 echo 0
107 return
108 fi
109
110 which tr > /dev/null
111 if [ $? -ne 0 ]; then
112 echo "'tr' not installed. Please install it and run this script again."
113 echo 0
114 return
115 fi
116
117 echo 1
118}
119
[1]120setupUser() {
121 echo -e "Setting up user and group \"sdtd\"\n"
122 useradd -d /home/sdtd -m -r -s /bin/bash -U sdtd
123 echo -e "\n=============================================================\n\n"
124}
125
126installManagementScripts() {
127 echo -e "Downloading and installing management scripts\n"
128 wget -nv http://illy.bz/fi/7dtd/management_scripts.tar.gz -O /tmp/management_scripts.tar.gz
[30]129 tar --touch -xzf /tmp/management_scripts.tar.gz -C /
130
131 chown root.root /etc/7dtd.conf
132 chmod 0600 /etc/7dtd.conf
133
134 chown sdtd.sdtd /home/sdtd -R
135
136 chown root.root /etc/init.d/7dtd.sh
137 chown root.root /etc/bash_completion.d/7dtd
138 chown root.root /usr/local/bin/7dtd.sh
139 chown root.root /usr/local/lib/7dtd -R
140 chmod 0755 /etc/init.d/7dtd.sh
141 chmod 0755 /etc/bash_completion.d/7dtd
142 chmod 0755 /usr/local/bin/7dtd.sh
143 chmod 0755 /usr/local/lib/7dtd -R
144
145 if [ $ISDEBIAN -eq 1 ]; then
[1]146 update-rc.d 7dtd.sh defaults
[32]147 fi
148
149 echo
150 echo "Compiling start-stop-daemon"
151 cd /usr/local/lib/7dtd/start-stop-daemon
[31]152
[32]153 gcc -Wall -Wextra -Wno-return-type -o start-stop-daemon start-stop-daemon.c
154 chown root.root start-stop-daemon
155 chmod 0755 start-stop-daemon
156
157#TODO: remove
158 sed -ir "s/^export SSD=.*$/export SSD=\/usr\/local\/lib\/7dtd\/start-stop-daemon\/start-stop-daemon/" /etc/7dtd.conf
159
[1]160 echo -e "\n=============================================================\n\n"
161}
162
163setSteamLoginData() {
164 echo -e "Steam account data\n"
165 echo "Please enter your Steam login data for SteamCMD to get the 7dtd-server files:"
166 read -p "Steam username: " username
167 read -s -p "Steam password: " password
168 sed -i "s/export STEAM_USER=/export STEAM_USER=$username/" /etc/7dtd.conf
169 sed -i "s/export STEAM_PASS=/export STEAM_PASS=$password/" /etc/7dtd.conf
170 echo -e "\n=============================================================\n\n"
171}
172
173installSteamCmdAndSDTD() {
174 echo -e "Installing SteamCMD and 7DtD\n"
[30]175 7dtd.sh updateengine
[1]176 echo -e "\n=============================================================\n\n"
177}
178
179addCronJobs() {
[30]180 echo -e "Enabling backup cron job\n"
[1]181
182 echo -e "By default a backup of the save folder will be created once"
183 echo -e " per hour. This can be changed in /etc/cron.d/7dtd-backup."
[30]184
185 cat /etc/cron.d/7dtd-backup | tr -d '#' > /tmp/7dtd-backup
186 cp /tmp/7dtd-backup /etc/cron.d
[1]187
188 echo -e "\n=============================================================\n\n"
189}
190
191finish() {
[30]192 if [ $ISDEBIAN -eq 0 ]; then
193 echo
194 echo "You are not running a Debian based distribution."
195 echo "The following things should manually be checked:"
196 echo " - Existence of prerequsities"
197 echo " - Running the init-script on boot"
198 else
199 echo -e "\n ALL DONE"
200 fi
201
[1]202 echo
[30]203 echo -e "You can now continue setting up instances as explained on the website:"
204 echo -e " https://7dtd.illy.bz/wiki/Instance%20management"
205 echo
[31]206 echo -e "You might also need to manually enable bash auto completion, refer to:"
207 echo -e " https://7dtd.illy.bz/wiki/Installation#Bashcompletion"
208 echo
[1]209 echo -e "For further configuration options check:"
210 echo -e " /etc/7dtd.conf"
211 echo
[30]212 echo -e "For feedback, suggestions, problems please visit the bugtracker:"
213 echo -e " https://7dtd.illy.bz/"
[1]214 echo
215}
216
217main() {
218 intro
219 nonDebianWarning
220
[30]221 if [ $ISDEBIAN -eq 1 ]; then
[1]222 installAptDeps
[30]223 if [ $INSTALLOPTIONALDEPS -eq 1 ]; then
224# installOptionalDeps
[1]225 echo
226 fi
[32]227 else
228 if [ $(checkSetupDeps) -eq 0 ]; then
229 return
230 fi
[1]231 fi
232 setupUser
233 installManagementScripts
234 setSteamLoginData
235 installSteamCmdAndSDTD
[30]236 if [ $ADDCRONJOBS -eq 1 ]; then
[1]237 addCronJobs
238 fi
239 finish
240}
241
[30]242if [ -z $1 ]; then
[1]243 showHelp
244 exit 0
245fi
246while getopts "hcoi" opt; do
247 case "$opt" in
248 h)
249 showHelp
250 exit 0
251 ;;
252 c)
253 ADDCRONJOBS=1
254 ;;
255 o)
256 INSTALLOPTIONALDEPS=1
257 ;;
258 i)
259 RUNINSTALL=1
260 ;;
261 esac
262done
[30]263if [ $RUNINSTALL -eq 1 ]; then
[1]264 main
265fi
266
Note: See TracBrowser for help on using the repository browser.