-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathinstaller.sh
executable file
·214 lines (176 loc) · 6.66 KB
/
installer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/sh
if [ $(id -u) -ne 0 ]
then
echo "Please run as root (with sudo) since we need to install some tools with apt, create a new user and adjust the files in the Apache html folder..."
exit 1
fi
echo "In order to use the Q3A Demo to run your server you must agree to id Software's EULA\n\n"
cat ./idSoftwareEULA
echo ""
while :
do
read -p "Do you agree to the EULA? (y/n): " agree
case $agree in
y*|Y*) break ;;
n*|N*) exit 1 ;;
esac
done
DIR="$(pwd)"
chmod +x ./scripts/*.sh
#Read config here
. ./installerconfig.cfg
###dpkg-lock-check loop from https://askubuntu.com/questions/132059/how-to-make-a-package-manager-wait-if-another-instance-of-apt-is-running
i=0
while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do
case $(($i % 4)) in
0 ) j="-" ;;
1 ) j="\\" ;;
2 ) j="|" ;;
3 ) j="/" ;;
esac
clear
echo "[$j] Waiting for other software managers to finish..."
sleep 0.2
i=$((i+1))
done
###
apt-get install sudo curl git nodejs npm jq apache2 wget apt-utils screen libarchive-zip-perl zipmerge bash -y
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
useradd -ms /bin/bash "$createUser"
cd /home/$createUser/ && git clone --recurse-submodules https://github.com/begleysm/quakejs.git
cd $DIR
cp ./scripts/ioq3ded.fixed.js /home/$createUser/quakejs/build/ioq3ded.js
cd /home/$createUser/quakejs && npm install
########################
# Content Server Setup #
########################
cp /home/$createUser/quakejs/html/* /var/www/html/
#copy html content for play page
cd $DIR
cp -f ./scripts/templates/index.html /var/www/html/
#Customize Playpage
sed -i "s/SERVERTITLE/${serverTitle}/g" /var/www/html/index.html
sed -i "s/CONTENTSERVER/${contentServer}/g" /var/www/html/index.html
sed -i "s/SERVERIP/${serverAddress}/g" /var/www/html/index.html
sed -i "s/SERVERPORT/${serverPort}/g" /var/www/html/index.html
if [ $funnyNames = 0 ]
then
sed -i "s/, '+name', playername//g" /var/www/html/index.html
fi
if [ $randomModels = 0 ]
then
sed -i "s/, '+model', playermodel//g" /var/www/html/index.html
fi
#CORS htaccess + rewrite on here
a2enmod rewrite
a2enmod headers
cp -f ./scripts/templates/htaccess /var/www/html/.htaccess
#funny names, random models, and server info for index.hml here
#Get assets from quakejs-content server
./scripts/get_assets.sh /var/www/html $sourceServer
# Not sure if we need this line since we now set fs_cdn as a parameter when starting the server...
# echo "127.0.0.1 content.quakejs.com" >> /etc/hosts
#Delete the downloaded Q3A maps?
if [ $customMapsOnly = 1 ]
then
find /var/www/html/assets/baseq3 -type f -not -name '*pak10*' -print0 | xargs -0 -I {} rm {}
fi
#################
# Customization #
#################
mkdir ./temp
#Run user defined scripts...
if [ $userscripts = 1 ]
then
chmod +x ./userscripts/*
for userscript in ./userscripts/*.sh
do
echo "Starting $userscript"
$userscript $createUser $serverAddress $serverPort $contentServer
done
fi
#Has the user defined custom downloads?
if [ $downloadLists = 1 ]
then
./scripts/downloader.sh
fi
#Copy maps to html-folder
cp ./customQ3maps/*.pk3 /var/www/html/assets/baseq3/
#Create autoexec.cfg and add it to pak101input
cd ./temp
mkdir ./scripts
for userCFG in ../autoexec/*.cfg
do
cat $userCFG >> ./scripts/default.txt
done
if [ $rconPasswordForAll = 1 ]
then
echo "seta rconpassword \"$rconPassword\"" >> ./scripts/default.txt
fi
zip ../pak101input/autoexec.pk3 ./scripts/default.txt
rm -f ./scripts/*
rmdir ./scripts
cd ..
#Merge baseq3 paks 100 & 101 (Directly in html-folder) (create backup for future updates)
mkdir ./paks
cp /var/www/html/assets/baseq3/*pak10* ./paks
./scripts/mergeScript2.sh ./paks/*pak100.pk3
./scripts/mergeScript2.sh ./paks/*pak101.pk3
echo "Deleting original paks in assets folder"
rm -f /var/www/html/assets/baseq3/*pak100.pk3
rm -f /var/www/html/assets/baseq3/*pak101.pk3
echo "Moving new paks to assets folder"
mv -f ./temp/*pk3 /var/www/html/assets/baseq3/
rm -f ./temp/*
# Calculate checksums and rename all files in the assets folders!
for folder in $(ls -d /var/www/html/assets/*/)
do
for file in $(ls $folder*.pk3)
do
./scripts/crcRename.sh "$file"
done
done
# create manifest.json
cp ./scripts/templates/manifest.json ./temp/manifest.tmp
for folder in $(ls -d /var/www/html/assets/*/)
do
for file in $(ls $folder*.pk3)
do
./scripts/manifestor.sh "$file" >> ./temp/manifest.tmp
done
done
echo "]" >> ./temp/manifest.tmp
mv -f ./temp/manifest.tmp /var/www/html/assets/manifest.json
# restart apache service
service apache2 restart
#Add parameters, create mapcycles and copy serverconfigs in mod folders
cp ./serverconfigs/*.cfg ./temp
for serverconfig in ./temp/*.cfg
do
echo "seta bot_enable 1" >> $serverconfig
echo "seta bot_minPlayers $bots" >> $serverconfig
echo "seta cg_gibs $gore" >> $serverconfig
echo "seta com_blood $gore" >> $serverconfig
echo "seta rconpassword \"$rconPassword\"" >> $serverconfig
echo "seta g_motd \"$motd\"" >> $serverconfig
echo "seta g_gametype $gametype" >> $serverconfig
echo "seta timelimit $timelimit" >> $serverconfig
echo "seta fraglimit $fraglimit" >> $serverconfig
echo "seta sv_hostname \"$hostname\"" >> $serverconfig
echo "seta sv_maxclients $maxclients" >> $serverconfig
# create mapcycles TODO: if custoMapsOnly =0 include the maps in pak0 in mapcycle
./scripts/mapCycler.sh $(ls /var/www/html/assets/$(basename --suffix=".cfg" $serverconfig)/*.pk3) >> $serverconfig
ls /home/$createUser/quakejs/base/$(basename --suffix=".cfg" $serverconfig) || mkdir /home/$createUser/quakejs/base/$(basename --suffix=".cfg" $serverconfig)
mv -f $serverconfig /home/$createUser/quakejs/base/$(basename --suffix=".cfg" $serverconfig)/server.cfg
done
chown -R $createUser:$createUser /home/$createUser/*
#create start-scripts
echo "#!/bin/bash" > /home/$createUser/quakejs/startscript.sh
echo "su - quake -c \"cd ~/quakejs && node build/ioq3ded.js +set net_port $serverPort +set net_ip $serverAddress +set fs_game baseq3 +set fs_cdn '${contentServer}' +set dedicated 1 +exec server.cfg & disown\"" >> /home/$createUser/quakejs/startscript.sh
echo "#!/bin/bash" > /home/$createUser/quakejs/startcpma.sh
echo "su - quake -c \"cd ~/quakejs && node build/ioq3ded.js +set net_port $serverPort +set net_ip $serverAddress +set fs_game cpma +set fs_cdn '${contentServer}' +set dedicated 1 +exec server.cfg & disown\"" >> /home/$createUser/quakejs/startcpma.sh
#create stopscript
echo "#!/bin/bash" > /home/$createUser/quakejs/stopscript.sh
echo "pkill -U $createUser" >> /home/$createUser/quakejs/stopscript.sh
chmod +x /home/$createUser/quakejs/*.sh
echo "Now cd to /home/$createUser/quakejs and run sudo ./startscript.sh or one of the mod startsrcipts :)"