1 | #!/bin/bash
|
---|
2 | # Version 1
|
---|
3 |
|
---|
4 | if [ `id -u` -ne 0 ]; then
|
---|
5 | echo "This script has to be run as root!"
|
---|
6 | exit 1
|
---|
7 | fi
|
---|
8 |
|
---|
9 |
|
---|
10 | ADDCRONJOBS=0
|
---|
11 | RUNINSTALL=0
|
---|
12 |
|
---|
13 | DEPENDENCIES="xvfb mono-runtime rsync xmlstarlet"
|
---|
14 |
|
---|
15 | if [ -n "$(command -v apt-get)" ]; then
|
---|
16 | ISDEBIAN=1
|
---|
17 | else
|
---|
18 | ISDEBIAN=0
|
---|
19 | fi
|
---|
20 |
|
---|
21 | if [ $(uname -m) == 'x86_64' ]; then
|
---|
22 | IS64BIT=1
|
---|
23 | else
|
---|
24 | IS64BIT=0
|
---|
25 | fi
|
---|
26 |
|
---|
27 | if [ $IS64BIT -eq 1 ]; then
|
---|
28 | DEPENDENCIES="$DEPENDENCIES lib32gcc1 wine:i386"
|
---|
29 | else
|
---|
30 | DEPENDENCIES="$DEPENDENCIES wine"
|
---|
31 | fi
|
---|
32 |
|
---|
33 | showHelp() {
|
---|
34 | echo "Usage: ./bootstrap.sh [-h] [-c] -i"
|
---|
35 | echo "Parameters:"
|
---|
36 | echo " -h Print this help screen and exit"
|
---|
37 | # echo " -o Install optional dependencies ($OPTDEPENDENCIES)"
|
---|
38 | echo " -c Enable cron job for automatic backups"
|
---|
39 | echo " -i Required to actually start the installation"
|
---|
40 | }
|
---|
41 |
|
---|
42 | intro() {
|
---|
43 | echo
|
---|
44 | echo "7DtD Linux dedicated server bootstrapper"
|
---|
45 | echo
|
---|
46 | echo "This will install a 7DtD server according to the information"
|
---|
47 | echo "given on:"
|
---|
48 | echo " https://7dtd.illy.bz/"
|
---|
49 | echo
|
---|
50 | read -p "Press enter to continue"
|
---|
51 | echo -e "\n=============================================================\n\n"
|
---|
52 | }
|
---|
53 |
|
---|
54 | nonDebianWarning() {
|
---|
55 | if [ $ISDEBIAN -eq 0 ]; then
|
---|
56 | echo "NOTE: It seems like this system is not based on Debian."
|
---|
57 | echo "Although installation of the scripts and SteamCMD/7dtd"
|
---|
58 | echo "will work the installed management scripts will probably"
|
---|
59 | echo "fail because of missing dependencies. Make sure you check"
|
---|
60 | echo "the website regarding the prerequisites"
|
---|
61 | echo "(https://7dtd.illy.bz)."
|
---|
62 | echo "Do you want to continue anyway?"
|
---|
63 | select yn in "Yes" "No"; do
|
---|
64 | case $yn in
|
---|
65 | Yes)
|
---|
66 | echo "Continuing..."
|
---|
67 | break;;
|
---|
68 | No)
|
---|
69 | echo "Aborting."
|
---|
70 | exit 0
|
---|
71 | ;;
|
---|
72 | esac
|
---|
73 | done
|
---|
74 | echo -e "\n=============================================================\n\n"
|
---|
75 | fi
|
---|
76 | }
|
---|
77 |
|
---|
78 | installAptDeps() {
|
---|
79 | echo -e "Installing dependencies\n"
|
---|
80 | if [ $IS64BIT -eq 1 ]; then
|
---|
81 | dpkg --add-architecture i386
|
---|
82 | fi
|
---|
83 | apt-get update
|
---|
84 | apt-get install $DEPENDENCIES
|
---|
85 | echo -e "\n=============================================================\n\n"
|
---|
86 | }
|
---|
87 |
|
---|
88 | installOptionalDeps() {
|
---|
89 | echo -e "Installing optional dependencies\n"
|
---|
90 | apt-get install $OPTDEPENDENCIES
|
---|
91 | echo -e "\n=============================================================\n\n"
|
---|
92 | }
|
---|
93 |
|
---|
94 | setupUser() {
|
---|
95 | echo -e "Setting up user and group \"sdtd\"\n"
|
---|
96 | useradd -d /home/sdtd -m -r -s /bin/bash -U sdtd
|
---|
97 | echo -e "\n=============================================================\n\n"
|
---|
98 | }
|
---|
99 |
|
---|
100 | installManagementScripts() {
|
---|
101 | echo -e "Downloading and installing management scripts\n"
|
---|
102 | wget -nv http://illy.bz/fi/7dtd/management_scripts.tar.gz -O /tmp/management_scripts.tar.gz
|
---|
103 | tar --touch -xzf /tmp/management_scripts.tar.gz -C /
|
---|
104 |
|
---|
105 | chown root.root /etc/7dtd.conf
|
---|
106 | chmod 0600 /etc/7dtd.conf
|
---|
107 |
|
---|
108 | chown sdtd.sdtd /home/sdtd -R
|
---|
109 |
|
---|
110 | chown root.root /etc/init.d/7dtd.sh
|
---|
111 | chown root.root /etc/bash_completion.d/7dtd
|
---|
112 | chown root.root /usr/local/bin/7dtd.sh
|
---|
113 | chown root.root /usr/local/lib/7dtd -R
|
---|
114 | chmod 0755 /etc/init.d/7dtd.sh
|
---|
115 | chmod 0755 /etc/bash_completion.d/7dtd
|
---|
116 | chmod 0755 /usr/local/bin/7dtd.sh
|
---|
117 | chmod 0755 /usr/local/lib/7dtd -R
|
---|
118 |
|
---|
119 | if [ $ISDEBIAN -eq 1 ]; then
|
---|
120 | update-rc.d 7dtd.sh defaults
|
---|
121 | else
|
---|
122 | echo
|
---|
123 | echo "Compiling start-stop-daemon"
|
---|
124 | cd /usr/local/lib/7dtd/start-stop-daemon
|
---|
125 | make
|
---|
126 | make install
|
---|
127 |
|
---|
128 | sed -ir "s/^export SSD=.*$/export SSD=\/usr\/local\/lib\/7dtd\/start-stop-daemon\/start-stop-daemon/" /etc/7dtd.conf
|
---|
129 | fi
|
---|
130 | echo -e "\n=============================================================\n\n"
|
---|
131 | }
|
---|
132 |
|
---|
133 | setSteamLoginData() {
|
---|
134 | echo -e "Steam account data\n"
|
---|
135 | echo "Please enter your Steam login data for SteamCMD to get the 7dtd-server files:"
|
---|
136 | read -p "Steam username: " username
|
---|
137 | read -s -p "Steam password: " password
|
---|
138 | sed -i "s/export STEAM_USER=/export STEAM_USER=$username/" /etc/7dtd.conf
|
---|
139 | sed -i "s/export STEAM_PASS=/export STEAM_PASS=$password/" /etc/7dtd.conf
|
---|
140 | echo -e "\n=============================================================\n\n"
|
---|
141 | }
|
---|
142 |
|
---|
143 | installSteamCmdAndSDTD() {
|
---|
144 | echo -e "Installing SteamCMD and 7DtD\n"
|
---|
145 | 7dtd.sh updateengine
|
---|
146 | echo -e "\n=============================================================\n\n"
|
---|
147 | }
|
---|
148 |
|
---|
149 | addCronJobs() {
|
---|
150 | echo -e "Enabling backup cron job\n"
|
---|
151 |
|
---|
152 | echo -e "By default a backup of the save folder will be created once"
|
---|
153 | echo -e " per hour. This can be changed in /etc/cron.d/7dtd-backup."
|
---|
154 |
|
---|
155 | cat /etc/cron.d/7dtd-backup | tr -d '#' > /tmp/7dtd-backup
|
---|
156 | cp /tmp/7dtd-backup /etc/cron.d
|
---|
157 |
|
---|
158 | echo -e "\n=============================================================\n\n"
|
---|
159 | }
|
---|
160 |
|
---|
161 | finish() {
|
---|
162 | if [ $ISDEBIAN -eq 0 ]; then
|
---|
163 | echo
|
---|
164 | echo "You are not running a Debian based distribution."
|
---|
165 | echo "The following things should manually be checked:"
|
---|
166 | echo " - Existence of prerequsities"
|
---|
167 | echo " - Running the init-script on boot"
|
---|
168 | else
|
---|
169 | echo -e "\n ALL DONE"
|
---|
170 | fi
|
---|
171 |
|
---|
172 | echo
|
---|
173 | echo -e "You can now continue setting up instances as explained on the website:"
|
---|
174 | echo -e " https://7dtd.illy.bz/wiki/Instance%20management"
|
---|
175 | echo
|
---|
176 | echo -e "You might also need to manually enable bash auto completion, refer to:"
|
---|
177 | echo -e " https://7dtd.illy.bz/wiki/Installation#Bashcompletion"
|
---|
178 | echo
|
---|
179 | echo -e "For further configuration options check:"
|
---|
180 | echo -e " /etc/7dtd.conf"
|
---|
181 | echo
|
---|
182 | echo -e "For feedback, suggestions, problems please visit the bugtracker:"
|
---|
183 | echo -e " https://7dtd.illy.bz/"
|
---|
184 | echo
|
---|
185 | }
|
---|
186 |
|
---|
187 | main() {
|
---|
188 | intro
|
---|
189 | nonDebianWarning
|
---|
190 |
|
---|
191 | if [ $ISDEBIAN -eq 1 ]; then
|
---|
192 | installAptDeps
|
---|
193 | if [ $INSTALLOPTIONALDEPS -eq 1 ]; then
|
---|
194 | # installOptionalDeps
|
---|
195 | echo
|
---|
196 | fi
|
---|
197 | fi
|
---|
198 | setupUser
|
---|
199 | installManagementScripts
|
---|
200 | setSteamLoginData
|
---|
201 | installSteamCmdAndSDTD
|
---|
202 | if [ $ADDCRONJOBS -eq 1 ]; then
|
---|
203 | addCronJobs
|
---|
204 | fi
|
---|
205 | finish
|
---|
206 | }
|
---|
207 |
|
---|
208 | if [ -z $1 ]; then
|
---|
209 | showHelp
|
---|
210 | exit 0
|
---|
211 | fi
|
---|
212 | while getopts "hcoi" opt; do
|
---|
213 | case "$opt" in
|
---|
214 | h)
|
---|
215 | showHelp
|
---|
216 | exit 0
|
---|
217 | ;;
|
---|
218 | c)
|
---|
219 | ADDCRONJOBS=1
|
---|
220 | ;;
|
---|
221 | o)
|
---|
222 | INSTALLOPTIONALDEPS=1
|
---|
223 | ;;
|
---|
224 | i)
|
---|
225 | RUNINSTALL=1
|
---|
226 | ;;
|
---|
227 | esac
|
---|
228 | done
|
---|
229 | if [ $RUNINSTALL -eq 1 ]; then
|
---|
230 | main
|
---|
231 | fi
|
---|
232 |
|
---|