-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathprovision.sh
330 lines (249 loc) · 6.89 KB
/
provision.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#! /bin/bash
# For some strange reason I don't understand yet Vagrant
# seems to write "exit" to the provisioning scripts
# stdin stream. As this may confuse tools that optionally
# read from stdin (genenrate-xml.py in this case) we're
# draining stdin here as the first thing before doing
# anything else
if ! test -t 0
then
cat > /dev/null
fi
#----------------------------------------------------
#
# the vagrant disksize plugin does not always manage
# to resize the root file system so we do it here
# once more just in case
#
#----------------------------------------------------
growpart /dev/sda 1
resize2fs $(mount | grep "on / " | egrep -o "^[^ ]+")
df -h /
#----------------------------------------------------
#
# add "maposmatic" system user
#
#----------------------------------------------------
useradd --create-home maposmatic
usermod -a -G www-data maposmatic
#----------------------------------------------------
#
# putting some often used constants into variables
#
#----------------------------------------------------
VAGRANT=/vagrant
FILEDIR=$VAGRANT/files
INCDIR=$VAGRANT/inc
INSTALLDIR=/home/maposmatic
LOGDIR=$INSTALLDIR/logs
mkdir -p $LOGDIR
chmod a+rwx $LOGDIR
DATADIR=$INSTALLDIR/data
mkdir -p $DATADIR/rendered_maps $DATADIR/upload
chmod -R a+rwx $DATADIR
if touch $VAGRANT/can_write_here
then
CACHEDIR=$VAGRANT/cache
rm $VAGRANT/can_write_here
else
mkdir -p /home/cache
chmod a+rwx /home/cache
CACHEDIR=/home/cache
fi
mkdir -p $CACHEDIR
SHAPEFILE_DIR=$INSTALLDIR/shapefiles
mkdir -p $SHAPEFILE_DIR
STYLEDIR=$INSTALLDIR/styles
mkdir -p $STYLEDIR
# store memory size in KB in $MemTotal
export $(grep MemTotal /proc/meminfo | sed -e's/kB//' -e's/ //g' -e's/:/=/')
#----------------------------------------------------
#
# include local config file
#
#----------------------------------------------------
if test -f $VAGRANT/local-config.sh
then
. $VAGRANT/local-config.sh
fi
#----------------------------------------------------
#
# check for an OSM PBF extract to import
#
# if there are more than one: take the first one found
# if there are none: exit
#
#----------------------------------------------------
export OSM_EXTRACT=$(ls $VAGRANT/*.pbf | head -1)
if test -f "$OSM_EXTRACT"
then
if test -r "$OSM_EXTRACT"
then
echo "Using $OSM_EXTRACT for OSM data import"
else
echo "$OSM_EXTRACT is not readable!"
exit 3
fi
else
echo "No OSM .pbf data file found for import!"
exit 3
fi
#----------------------------------------------------
#
# Make variables used by included provision scripts
# available to VM users to be able to easily re-run scripts
#
#----------------------------------------------------
. $INCDIR/shell-profile.sh
#----------------------------------------------------
#
# Vagrant/Virtualbox environment preparations
# (not really Ocitysmap specific yet)
#
#----------------------------------------------------
# override language settings
locale-gen en_US.UTF-8
localedef --force --inputfile=en_US --charmap=UTF-8 en_US.UTF-8
# but keep "C" locale for now as locale changes only seem
# to have an effect on future login shells
export LANG=C.UTF-8
export LANGUAGE=C.UTF-8
export LC_ADDRESS=C.UTF-8
export LC_ALL=C.UTF-8
export LC_CTYPE=C.UTF-8
export LC_IDENTIFICATION=C.UTF-8
export LC_MEASUREMENT=C.UTF-8
export LC_MESSAGE=C.UTF-8
export LC_MONETARY=C.UTF-8
export LC_NAME=C.UTF-8
export LC_NUMERIC=C.UTF-8
export LC_PAPER=C.UTF-8
export LC_TELEPHONE=C.UTF-8
export LC_TIME=C.UTF-8
# silence curl and wget progress reports
# as these just flood the vagrant output in an unreadable way
echo "--silent" > /root/.curlrc
echo "quiet = on" > /root/.wgetrc
# pre-seed compiler cache
if test -d $CACHEDIR/.ccache/
then
cp -rn $CACHEDIR/.ccache/ ~/
else
mkdir -p ~/.ccache
fi
# sudo environment setup
. $INCDIR/sudoers.sh
# install local tools
. $INCDIR/install-tools.sh
# installing apt, pip and npm packages
. $INCDIR/install-packages.sh
PYTHON_VERSION=python$(python3 -c 'import sys; print("%d.%d" % (sys.version_info.major, sys.version_info.minor))')
# install all locales in the background
. $INCDIR/locales.sh
banner "shapefiles"
# install shapefiles
. $INCDIR/get-shapefiles.sh
# set up shapefile update job
cp $FILEDIR/systemd/shapefile-update.* /etc/systemd/system
systemctl daemon-reload
# initial git configuration
. $INCDIR/git-setup.sh
# add host entry for gis-db
sed -ie 's/localhost/localhost gis-db/g' /etc/hosts
banner "db setup"
. $INCDIR/database-setup.sh
banner "places db"
. $INCDIR/places-database.sh
banner "db l10n"
. $INCDIR/from-source/mapnik-german-l10n.sh
banner "building osm2pgsql"
. $INCDIR/from-source/osm2pgsql-build.sh
banner "building phyghtmap" # needed by OpenTopoMap
. $INCDIR/from-source/phyghtmap.sh
banner "db import - classic"
. $INCDIR/osm2pgsql-import.sh
banner "db import - flex"
. $INCDIR/osm2pgsql-import-flex.sh
banner "get bounds"
python3 $INCDIR/data-bounds.py $INSTALLDIR/bounds $OSM_EXTRACT
banner "DEM setup"
. $INCDIR/elevation-data.sh
banner "renderer setup"
. $INCDIR/ocitysmap.sh
banner "shapefiles"
# install shapefiles
. $INCDIR/get-shapefiles.sh
# set up shapefile update job
cp $FILEDIR/systemd/shapefile-update.* /etc/systemd/system
systemctl daemon-reload
banner "styles"
. $INCDIR/styles.sh
#----------------------------------------------------
#
# Setting up Django fronted
#
#----------------------------------------------------
banner "django frontend"
. $INCDIR/apache-global-config.sh
. $INCDIR/maposmatic-frontend.sh
#----------------------------------------------------
#
# Setting up "Umgebungsplaene" alternative frontend
#
#----------------------------------------------------
banner "umgebungsplaene"
. $INCDIR/umgebungsplaene.sh
#----------------------------------------------------
#
# munin monitoring
#
#----------------------------------------------------
banner "munin"
. $INCDIR/munin.sh
#----------------------------------------------------
#
# some necessary security tweaks
#
#-----------------------------------------------------
banner "security"
. $INCDIR/security-quirks.sh
#----------------------------------------------------
#
# add simple tile server for offline operations
#
#----------------------------------------------------
banner "tileserver"
if test ${WITH_TILESERVER:=yes} = "yes"
then
. $INCDIR/tileserver.sh
else
echo "skipping"
fi
#----------------------------------------------------
#
# add weblate translation service
#
#----------------------------------------------------
banner "weblate"
if test ${WITH_WEBLATE:=yes} = "yes"
then
. $INCDIR/weblate.sh
else
echo "skipping"
fi
#----------------------------------------------------
#
# tests
#
#-----------------------------------------------------
banner "running tests"
. $INCDIR/testing.sh
#----------------------------------------------------
#
# cleanup
#
#-----------------------------------------------------
banner "cleanup"
. $INCDIR/start-timer-jobs.sh
# write back compiler cache
cp -rn /root/.ccache $CACHEDIR