source: bootstrapper/bootstrap.sh @ 34

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

Version 9: Always use own start-stop-daemon

File size: 6.2 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 xvfb mono-runtime rsync xmlstarlet gcc"
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 wine:i386"
30else
31        DEPENDENCIES="$DEPENDENCIES wine"
32fi
33
34showHelp() {
35        echo "Usage: ./bootstrap.sh [-h] [-c] -i"
36        echo "Parameters:"
37        echo "  -h   Print this help screen and exit"
38#       echo "  -o   Install optional dependencies ($OPTDEPENDENCIES)"
39        echo "  -c   Enable cron job for automatic backups"
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:"
49        echo "   https://7dtd.illy.bz/"
50        echo
51        read -p "Press enter to continue"
52        echo -e "\n=============================================================\n\n"
53}
54
55nonDebianWarning() {
56        if [ $ISDEBIAN -eq 0 ]; then
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"
60                echo "fail because of missing dependencies. Make sure you check"
61                echo "the website regarding the prerequisites"
62                echo "(https://7dtd.illy.bz)."
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"
81        if [ $IS64BIT -eq 1 ]; then
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
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
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
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
146                update-rc.d 7dtd.sh defaults
147        fi
148       
149        echo
150        echo "Compiling start-stop-daemon"
151        cd /usr/local/lib/7dtd/start-stop-daemon
152
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        echo -e "\n=============================================================\n\n"
158}
159
160setSteamLoginData() {
161        echo -e "Steam account data\n"
162        echo "Please enter your Steam login data for SteamCMD to get the 7dtd-server files:"
163        read -p "Steam username: " username
164        read -s -p "Steam password: " password
165        sed -i "s/export STEAM_USER=/export STEAM_USER=$username/" /etc/7dtd.conf
166        sed -i "s/export STEAM_PASS=/export STEAM_PASS=$password/" /etc/7dtd.conf
167        echo -e "\n=============================================================\n\n"
168}
169
170installSteamCmdAndSDTD() {
171        echo -e "Installing SteamCMD and 7DtD\n"
172        7dtd.sh updateengine
173        echo -e "\n=============================================================\n\n"
174}
175
176addCronJobs() {
177        echo -e "Enabling backup cron job\n"
178
179        echo -e "By default a backup of the save folder will be created once"
180        echo -e "  per hour. This can be changed in /etc/cron.d/7dtd-backup."
181       
182        cat /etc/cron.d/7dtd-backup | tr -d '#' > /tmp/7dtd-backup
183        cp /tmp/7dtd-backup /etc/cron.d
184
185        echo -e "\n=============================================================\n\n"
186}
187
188finish() {
189        if [ $ISDEBIAN -eq 0 ]; then
190                echo
191                echo "You are not running a Debian based distribution."
192                echo "The following things should manually be checked:"
193                echo " - Existence of prerequsities"
194                echo " - Running the init-script on boot"
195        else
196                echo -e "\n ALL DONE"
197        fi
198
199        echo
200        echo -e "You can now continue setting up instances as explained on the website:"
201        echo -e "  https://7dtd.illy.bz/wiki/Instance%20management"
202        echo
203        echo -e "You might also need to manually enable bash auto completion, refer to:"
204        echo -e "  https://7dtd.illy.bz/wiki/Installation#Bashcompletion"
205        echo
206        echo -e "For further configuration options check:"
207        echo -e "  /etc/7dtd.conf"
208        echo
209        echo -e "For feedback, suggestions, problems please visit the bugtracker:"
210        echo -e "  https://7dtd.illy.bz/"
211        echo
212}
213
214main() {
215        intro
216        nonDebianWarning
217
218        if [ $ISDEBIAN -eq 1 ]; then
219                installAptDeps
220                if [ $INSTALLOPTIONALDEPS -eq 1 ]; then
221#                       installOptionalDeps
222                        echo
223                fi
224        else
225                if [ $(checkSetupDeps) -eq 0 ]; then
226                        return
227                fi
228        fi
229        setupUser
230        installManagementScripts
231        setSteamLoginData
232        installSteamCmdAndSDTD
233        if [ $ADDCRONJOBS -eq 1 ]; then
234                addCronJobs
235        fi
236        finish
237}
238
239if [ -z $1 ]; then
240        showHelp
241        exit 0
242fi
243while getopts "hcoi" opt; do
244        case "$opt" in
245                h)
246                        showHelp
247                        exit 0
248                        ;;
249                c)
250                        ADDCRONJOBS=1
251                        ;;
252                o)
253                        INSTALLOPTIONALDEPS=1
254                        ;;
255                i)
256                        RUNINSTALL=1
257                        ;;
258        esac
259done
260if [ $RUNINSTALL -eq 1 ]; then
261        main
262fi
263
Note: See TracBrowser for help on using the repository browser.