forked from OSGeo/OSGeoLive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_cartaro.sh
executable file
·389 lines (289 loc) · 10.2 KB
/
install_cartaro.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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
#!/bin/bash
#############################################################################
#
# Purpose: This script will install Cartaro
#
#############################################################################
# Copyright (c) 2012 geOps (www.geops.de)
# Copyright (c) 2012-2018 The Open Source Geospatial Foundation.
# Licensed under the GNU LGPL.
#
# This library is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 2.1 of the License,
# or any later version. This library is distributed in the hope that
# it will be useful, but WITHOUT ANY WARRANTY, without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details, either
# in the "LICENSE.LGPL.txt" file distributed with this software or at
# web page "http://www.fsf.org/licenses/lgpl.html".
#############################################################################
# Running:
# =======
# sudo ./install_cartaro.sh
#
# Depedencies:
# ===========
# Needs already installed Geoserver with at least version 2.2
#
./diskspace_probe.sh "`basename $0`" begin
####
CARTARO_PASSWORD="geoserver"
CARTARO_USER="cartaro-admin"
CARTARO_VERSION="1.9"
DB_NAME="cartaro"
DB_USER="cartaro"
DB_PASSWORD="cartaro"
GEO_ADMIN="admin"
GEO_PASS="geoserver"
GEO_VERSION="2.13.2"
GEO_PATH="/usr/local/lib/geoserver-$GEO_VERSION"
TMP_DIR="/tmp/build_cartaro"
TARGET_DIR="/usr/local/lib/cartaro"
DOC_DIR="/usr/local/share/cartaro"
GEOSERVER_URL="http://localhost:8082/geoserver"
USER_NAME="user"
USER_HOME="/home/$USER_NAME"
##############################
# Prepare folders
##############################
if [ ! -d "$TMP_DIR" ] ; then
mkdir -p "$TMP_DIR"
fi
##############################
# Add extra APT-Repository
##############################
# echo "[install_cartaro.sh] Configure APT-Repo and install extra module"
# if [ ! -f /etc/apt/sources.list.d/cartaro.list ] ; then
# cat << EOF > /etc/apt/sources.list.d/cartaro.list
# # Repo for Cartaro
# deb http://apt.geops.de xenial main
# EOF
# fi
# apt-key adv --keyserver hkp://keys.gnupg.net --recv-keys B6AA9BC9E7BDBF3D
# apt-get update
# apt-get --no-remove -y install php5-gdal
# php5enmod -s ALL gdal
###############################
# Prepare Database
###############################
echo "[install_cartaro.sh] Prepare Database ..."
#ensure all database conntections to db for cartaro are closed
/etc/init.d/apache2 stop
/etc/init.d/postgresql restart
/bin/su postgres -c " /usr/bin/psql -c \" drop database $DB_NAME; \""
/bin/su postgres -c " /usr/bin/psql -c \" drop role $DB_NAME; \""
/bin/su postgres -c " /usr/bin/psql -c \" create role $DB_USER with login password '$DB_PASSWORD'; \""
/bin/su postgres -c "/usr/bin/createdb -O $DB_USER -T template0 -E UTF-8 $DB_NAME"
/etc/init.d/apache2 start
###############################
# Prepare PostGIS
###############################
echo "[install_cartaro.sh] Prepare PostGIS ..."
/bin/su postgres -c "/usr/bin/psql -d $DB_NAME -c 'create extension postgis'"
/bin/su postgres -c "/usr/bin/psql -d $DB_NAME \
-c \" grant all on geometry_columns to $DB_USER; grant all on spatial_ref_sys to $DB_USER; \""
#####################
# Install Drush
#####################
echo "[install_cartaro.sh] Install Drush ..."
# install a working version of drush and patch it to not drop
# all tables, as this will also drop to postgis table
# install only, if folder does not already exists
DRUSH_DIR=$TARGET_DIR/drush
DRUSH_FILE="drush-7.x-5.4.tar.gz"
if [ ! -f "$DRUSH_DIR/drush" ] ; then
mkdir -p "$DRUSH_DIR"
if [ ! -f "$TMP_DIR/$DRUSH_FILE" ] ; then
pushd "$TMP_DIR"
wget -c --progress=dot:mega \
"http://ftp.drupal.org/files/projects/drush-7.x-5.4.tar.gz"
popd
fi
pushd "$TARGET_DIR"
# remove table dropping
tar xzf "$TMP_DIR/$DRUSH_FILE"
sed -ri "s/'DROP TABLE '/\'-- DROP TABLE \'/g" "$DRUSH_DIR/commands/sql/sql.drush.inc"
popd
fi
#####################
# Download Cartaro
#####################
echo "[install_cartaro.sh] Download Cartaro ..."
CARTARO_FILE="cartaro-7.x-${CARTARO_VERSION}-core.tar.gz"
if [ ! -d "$TARGET_DIR/cartaro-7.x-$CARTARO_VERSION" ] ; then
if [ ! -f "$TMP_DIR/$CARTARO_FILE" ] ; then
pushd "$TMP_DIR"
/usr/bin/wget -c --progress=dot:mega \
"http://ftp.drupal.org/files/projects/cartaro-7.x-${CARTARO_VERSION}-core.tar.gz"
popd
fi
pushd "$TARGET_DIR"
/bin/tar xzf "$TMP_DIR/$CARTARO_FILE"
/bin/mv "cartaro-7.x-$CARTARO_VERSION"/* .
# save filespace
rm -Rf profiles/cartaro/libraries/openlayers/doc
popd
fi
###################
# Configure apache
##################
echo "[install_cartaro.sh] Configure Apache2 ..."
if [ ! -f /etc/apache2/conf-available/cartaro.conf ] ; then
cat << EOF > /etc/apache2/conf-available/cartaro.conf
<Directory /var/www/html/cartaro>
RewriteEngine On
RewriteRule "(^|/)\." - [F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ /cartaro/index.php [L]
</Directory>
EOF
a2enconf cartaro
a2enmod rewrite
service apache2 restart
fi
####################
# Install Cartaro
###################
#ensure geoserver is running
echo "[install_cartaro.sh] Install Cartaro ..."
chown -R root.root "$TARGET_DIR"
echo "Stopping GeoServer"
"$GEO_PATH"/bin/shutdown.sh &> /dev/null &
sleep 30;
echo "Done"
echo "Starting GeoServer to import layers"
"$GEO_PATH"/bin/startup.sh &> /dev/null &
sleep 90;
echo "Done"
# attempt to run a site-install and reenter the password a few times
pushd "$TARGET_DIR"
# pgpassword needs to be exported - otherwise drush will prompt for the password (4 times!)
# with PGPASSWORD libpq will read the password itself
#
# the accout login is used for geoserver - so it should match
# a geoserver account
# install_configure_form.cartaro_demo=1
SITE_INSTALL_OPTS="cartaro
install_configure_form.cartaro_demo=1
install_configure_form.geoserver_workspace=cartaro
install_configure_form.geoserver_namespace=cartaro
install_configure_form.geoserver_url=$GEOSERVER_URL
--account-pass=$GEO_PASS
--account-name=$GEO_ADMIN
--site-name=Cartaro Demo
--db-url=pgsql://$DB_USER:$DB_PASSWORD@localhost:5432/$DB_NAME
--clean-url=1
--yes"
PGPASSWORD=$DB_PASSWORD $DRUSH_DIR/drush site-install $SITE_INSTALL_OPTS
# silence errors
"$DRUSH_DIR"/drush variable-set error_level 0
# and apply ownership to anything new that came along since we started
chown -R root.root "$TARGET_DIR"
# make file folder writeable for web-user
chown -R www-data.www-data "$TARGET_DIR"/sites/default/files
popd
#### final tidy up
/bin/su postgres -c "/usr/bin/psql -d $DB_NAME -c 'VACUUM ANALYZE'"
#######################
# Symlink for Apache2
#######################
echo "[install_cartaro.sh] Create Apache2 Symlinks ..."
if [ ! -L /var/www/html/cartaro ] ; then
ln -s "$TARGET_DIR" /var/www/html/cartaro
fi
###########################
# Create scripts start and shutdown
###########################
echo "[install_cartaro.sh] Create start and shutdown scripts ..."
if [ ! -d "$TARGET_DIR/bin" ] ; then
mkdir -p "$TARGET_DIR/bin"
fi
if [ ! -f "$TARGET_DIR/bin/start_cartaro.sh" ] ; then
cat << EOF > "$TARGET_DIR/bin/start_cartaro.sh"
#!/bin/sh
PASSWORD=user
# Enable JSONP for GeoServer
JAVA_OPTS="-DENABLE_JSONP=true -XX:MaxPermSize=128m"
echo "\$PASSWORD" | sudo -S JAVA_OPTS="\$JAVA_OPTS" $GEO_PATH/bin/startup.sh &
echo "\$PASSWORD" | sudo -S /etc/init.d/postgresql start
echo "\$PASSWORD" | sudo -S /etc/init.d/apache2 start
DELAY=40
(
for TIME in \`seq \$DELAY\` ; do
sleep 1
echo "\$TIME \$DELAY" | awk '{print int(0.5+100*\$1/\$2)}'
done
) | zenity --progress --auto-close --text "Cartaro is starting...."
zenity --info --text "Starting web browser ... have fun with Cartaro! Log in with user admin and password geoserver."
firefox "http://localhost/cartaro"
EOF
fi
if [ ! -f "$TARGET_DIR/bin/stop_cartaro.sh" ] ; then
cat << EOF > "$TARGET_DIR/bin/stop_cartaro.sh"
#!/bin/sh
PASSWORD=user
echo "\$PASSWORD" | sudo -S $GEO_PATH/bin/shutdown.sh &
zenity --info --text "Cartaro is stopped"
EOF
fi
chmod -R 0755 "$TARGET_DIR/bin"
##################################
# Copy Icons and create Desktop Icon
#################################
echo "[install_cartaro.sh] Create desktop icons ..."
if [ ! -f /usr/local/share/icons/logo-cartaro-48.png ] ; then
mkdir -p /usr/local/share/icons
pushd "/usr/local/share/icons"
wget -nv "http://cartaro.org/sites/cartaro.org/themes/cartaro_org/img/logos/logo-cartaro-48.png"
popd
fi
## start icon
if [ ! -f "/usr/local/share/applications/cartaro-start.desktop" ] ; then
mkdir -p /usr/local/share/applications
cat << EOF > /usr/local/share/applications/cartaro-start.desktop
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Start Cartaro
Comment=Cartaro $CARTARO_VERSION
Categories=Application;
Exec=$TARGET_DIR/bin/start_cartaro.sh
Icon=/usr/local/share/icons/logo-cartaro-48.png
Terminal=false
EOF
cp -a /usr/local/share/applications/cartaro-start.desktop "$USER_HOME/Desktop/"
chown -R "$USER_NAME":"$USER_NAME" "$USER_HOME/Desktop/cartaro-start.desktop"
fi
## stop icon
if [ ! -f "/usr/local/share/applications/cartaro-stop.desktop" ] ; then
mkdir -p /usr/local/share/applications
cat << EOF > /usr/local/share/applications/cartaro-stop.desktop
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Stop Cartaro
Comment=Cartaro $CARTARO_VERSION
Categories=Application;
Exec=$TARGET_DIR/bin/stop_cartaro.sh
Icon=/usr/local/share/icons/logo-cartaro-48.png
Terminal=false
EOF
cp -a /usr/local/share/applications/cartaro-stop.desktop "$USER_HOME/Desktop/"
chown -R "$USER_NAME":"$USER_NAME" "$USER_HOME/Desktop/cartaro-stop.desktop"
fi
############################################
# Bring down GeoServer and reset permissions
############################################
"$GEO_PATH"/bin/shutdown.sh &> /dev/null &
sleep 30
## Allow the user to write in the GeoServer data dir
adduser "$USER_NAME" users
chmod -R g+w "$GEO_PATH/data_dir"
chmod -R g+w "$GEO_PATH/logs"
chgrp -R users "$GEO_PATH/data_dir"
chgrp -R users "$GEO_PATH/logs"
####
./diskspace_probe.sh "`basename $0`" end