forked from OSGeo/OSGeoLive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_sahana.sh
executable file
·412 lines (356 loc) · 13.1 KB
/
install_sahana.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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
#! /bin/sh
#################################################
#
# Purpose: Installation of Sahana Eden into Xubuntu
# Author: Fran Boon, Rik Goldman, Steven Robinson, Jerel Moses, Maurice Quarles
#
# Copyright (c) 2011-2016 Open Source Geospatial Foundation (OSGeo)
# Licensed under the GNU LGPL version >= 2.1.
#
# 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".
##################################################
#
# About:
# =====
# This script will install Sahana Eden into Xubuntu
#
# Requires: Apache2, Python, PostgreSQL
#
# see also
# http://eden.sahanafoundation.org/wiki/InstallationGuidelinesLinux
./diskspace_probe.sh "`basename $0`" begin
BUILD_DIR=`pwd`
####
# Check for Root User
gotroot=$(id -u)
if [ "$gotroot" != "0" ] ; then
echo "This script must run with root privileges."
exit 100
fi
# live disc's username is "user"
INSTALL_DIR="/usr/local/lib"
if [ -z "$USER_NAME" ] ; then
USER_NAME="user"
fi
USER_HOME="/home/$USER_NAME"
SAHANA_CONF="/etc/apache2/conf-available/sahana.conf"
TMP_DIR="/tmp/build_sahana"
WEBSERVER="apache2"
## versions syncd manually
# PostgreSQL
PG_VERSION="9.5"
# Geoserver
GS_VERSION="2.13.2"
GS_HOME="$INSTALL_DIR/geoserver-$GS_VERSION"
# FIXME: Script doesn't currently use this var
PORT="8007"
mkdir -p "$TMP_DIR"
# Update from repos
apt-get -q update
# Install dependencies and support tools
# Installed already by setup.sh
# wget make g++ bzip2
DEBIAN_FRONTEND=noninteractive apt-get -y \
-o DPkg::Options::=--force-confdef \
-o DPkg::Options::=--force-confold \
install \
git \
unzip \
zlib1g-dev \
libgeos-c1v5 \
python-dev \
python-lxml \
python-dateutil \
python-shapely \
python-imaging \
python-reportlab \
python-xlrd \
python-xlwt \
python-numpy \
libapache2-mod-wsgi \
python-psycopg2
## 09feb14 do not install python-matplotlib
## pip install version is newer.. more pip wars
## TODO even more defensive scripting
if [ ! -e /usr/share/pyshared/matplotlib ] ; then
apt-get install -y python-matplotlib
#pip install matplotlib
fi
# Install python-tweepy (optional)
##echo "deb http://ppa.launchpad.net/chris-lea/python-tweepy/ubuntu precise main
##deb-src http://ppa.launchpad.net/chris-lea/python-tweepy/ubuntu precise main" \
## > /etc/apt/sources.list.d/python-tweepy.list
##apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C7917B12
##apt-get -q update
##apt-get install --yes python-tweepy
# Install PostGIS 2.2 done elsewhere
#apt-get install --yes "postgresql-$PG_VERSION-postgis" postgis libgdal1
# Add DB User
su -c - postgres "createuser -s sahana" && true
# Create Fresh DB
# ensure no active connections to old one
#apache2ctl stop # WSGI
killall python
su -c - postgres "dropdb sahana" && true
su -c - postgres "createdb -E UTF8 -O sahana sahana"
# Not needed any more
#su -c - postgres "createlang plpgsql -d sahana"
# Add Role Password
cat << EOF > "$TMP_DIR/sahana.sql"
ALTER ROLE sahana WITH PASSWORD 'sahana';
EOF
su -c - postgres "psql -q -d sahana -f $TMP_DIR/sahana.sql"
# Create db with postgis extensions
su -c - postgres "psql -q -d sahana -c 'create extension postgis'"
# Add web2py account
# - with mod_proxy we now run web2py as 'user'
#adduser --system --disabled-password --no-create-home web2py && true
#addgroup web2py && true
#usermod -G web2py web2py && true
# Download web2py
rm -rf "$INSTALL_DIR"/web2py
#W2P_FILE="web2py_src-1.99.7.zip"
#wget -c --progress=dot:mega \
# "http://eden.sahanafoundation.org/downloads/$W2P_FILE" \
# -O "$TMP_DIR/$W2P_FILE"
#unzip -q "$TMP_DIR/$W2P_FILE" -d "$INSTALL_DIR"
cd "$INSTALL_DIR"
git clone git://github.com/web2py/web2py.git
cd web2py
git checkout 354e63d0fea30e35b7d55f4f26dd34b4d887232f
#git checkout 828a4d7a60021b20bd9dfacf8235e9113156271b
git reset --hard
cat << EOF > "$INSTALL_DIR/web2py/routes.py"
default_application = 'eden'
default_controller = 'default'
default_function = 'index'
routes_onerror = [
('eden/400', '!'),
('eden/401', '!'),
('eden/*', '/eden/errors/index'),
('*/*', '/eden/errors/index'),
]
EOF
# Install Sahana Eden
cd "$INSTALL_DIR/web2py/applications"
git clone git://github.com/flavour/eden.git
cd eden
git checkout deca684114b572b1965521cf7d28afd76cdd9fc6
git reset --hard
# Create Eden Directories
mkdir -p "$INSTALL_DIR/web2py/applications/eden/cache"
mkdir -p "$INSTALL_DIR/web2py/applications/eden/databases"
mkdir -p "$INSTALL_DIR/web2py/applications/eden/errors"
mkdir -p "$INSTALL_DIR/web2py/applications/eden/sessions"
mkdir -p "$INSTALL_DIR/web2py/applications/eden/uploads/gis_cache"
mkdir -p "$INSTALL_DIR/web2py/applications/eden/uploads/images"
mkdir -p "$INSTALL_DIR/web2py/applications/eden/uploads/tracks"
# Set permissions
mkdir -p "$INSTALL_DIR/web2py/applications/admin/cache"
mkdir -p "$INSTALL_DIR/web2py/applications/admin/databases"
mkdir -p "$INSTALL_DIR/web2py/applications/admin/errors"
mkdir -p "$INSTALL_DIR/web2py/applications/admin/sessions"
FILES="
$INSTALL_DIR/web2py/applications/admin/cache
$INSTALL_DIR/web2py
$INSTALL_DIR/web2py/applications/admin/cron
$INSTALL_DIR/web2py/applications/admin/databases
$INSTALL_DIR/web2py/applications/admin/errors
$INSTALL_DIR/web2py/applications/admin/sessions
$INSTALL_DIR/web2py/applications/eden
$INSTALL_DIR/web2py/applications/eden/cache
$INSTALL_DIR/web2py/applications/eden/cron
$INSTALL_DIR/web2py/applications/eden/databases
$INSTALL_DIR/web2py/applications/eden/errors
$INSTALL_DIR/web2py/applications/eden/models
$INSTALL_DIR/web2py/applications/eden/sessions
$INSTALL_DIR/web2py/applications/eden/static/img/markers
$INSTALL_DIR/web2py/applications/eden/uploads
$INSTALL_DIR/web2py/applications/eden/uploads/gis_cache
$INSTALL_DIR/web2py/applications/eden/uploads/images
$INSTALL_DIR/web2py/applications/eden/uploads/tracks
"
chgrp users $FILES
chmod g+w $FILES
adduser "$USER_NAME" users
# Copy Deployment Templates
if [ ! -f "$INSTALL_DIR/web2py/applications/eden/models" ] ; then
cp "$INSTALL_DIR/web2py/applications/eden/private/templates/000_config.py" \
"$INSTALL_DIR/web2py/applications/eden/models/000_config.py"
fi
# Stream Edit 000_config.py
sed -i 's|EDITING_CONFIG_FILE = False|EDITING_CONFIG_FILE = True|' \
"$INSTALL_DIR/web2py/applications/eden/models/000_config.py"
sed -i 's|#settings.base.public_url = "http://127.0.0.1:8000"|settings.base.public_url = "http://127.0.0.1"|' \
"$INSTALL_DIR/web2py/applications/eden/models/000_config.py"
# Not working with PostGIS 2 (prepop fails)
#sed -i 's|#settings.gis.spatialdb = True|settings.gis.spatialdb = True|' \
# "$INSTALL_DIR/web2py/applications/eden/models/000_config.py"
# Stream Edit 000_config.py for Postgres Database
sed -i 's|#settings.database.db_type = "postgres"|settings.database.db_type = "postgres"|' \
"$INSTALL_DIR/web2py/applications/eden/models/000_config.py"
sed -i 's|#settings.database.password = "password"|settings.database.password = "sahana"|' \
"$INSTALL_DIR/web2py/applications/eden/models/000_config.py"
# Configure Eden for Portland (FOSS4G 2014)
sed -i -e 's|22.593723263|45.5282|' \
-e 's|5.28516253|-122.6632|' \
-e 's|,2,|,12,|' \
"$INSTALL_DIR/web2py/applications/eden/private/templates/default/gis_config.csv"
#sed -i 's|#settings.L10n.utc_offset = "UTC +0000"|settings.L10n.utc_offset = "UTC +0100"|' \
# "$INSTALL_DIR/web2py/applications/eden/private/templates/default/config.py"
cat << EOF >> "$INSTALL_DIR/web2py/applications/eden/models/zzz_1st_run.py"
# Create Login
table = auth.settings.table_user_name
# 1st-run initialisation
if not len(db().select(db[table].id, limitby=(0, 1))):
import hmac
import hashlib
alg = hashlib.sha512
db[table].insert(
email = 'admin',
password = hmac.new(auth.settings.hmac_key, 'admin', alg).hexdigest(),
utc_offset = '+0800',
first_name = 'Admin',
last_name = 'User'
)
db.commit()
# Add user to admin role
auth.add_membership(1, 1)
# Add user to authenticated role
auth.add_membership(2, 1)
db.commit()
EOF
# Configure Eden to make use of local GeoData
sed -i 's|-180,180,"|-180,180,"http://localhost:8082/geoserver/wms?service=WMS\&request=GetCapabilities"|' \
"$INSTALL_DIR/web2py/applications/eden/private/templates/default/gis_config.csv"
# Perform the initial database Migration/Prepopulation
cd "$INSTALL_DIR/web2py"
touch NEWINSTALL
sudo -H -u "$USER_NAME" python web2py.py -S eden -M \
-R applications/eden/static/scripts/tools/noop.py
# Stream Edit 000_config.py to disable migration
sed -i 's|settings.base.migrate = True|settings.base.migrate = False|' \
"$INSTALL_DIR/web2py/applications/eden/models/000_config.py"
sed -i 's|#settings.base.prepopulate = 0|settings.base.prepopulate = 0|' \
"$INSTALL_DIR/web2py/applications/eden/models/000_config.py"
# Compile scripts to optimise performance
cd "$INSTALL_DIR/web2py"
chgrp users "$INSTALL_DIR/web2py"
chmod g+w "$INSTALL_DIR/web2py"
sudo -H -u "$USER_NAME" python web2py.py -S eden -M \
-R applications/eden/static/scripts/tools/compile.py
# final tidy up
su -c - postgres "psql -d sahana -c 'VACUUM ANALYZE'"
chown root.root "$INSTALL_DIR"/web2py/applications/eden/compiled/ -R
chown root.root "$INSTALL_DIR"/web2py/applications/eden/__init__.pyc
# not sure which of the rest need to be writable by the user, so make them all
chown root.users "$INSTALL_DIR"/web2py/applications/eden/databases/*
chmod g+w "$INSTALL_DIR"/web2py/applications/eden/databases/*
chown root.users "$INSTALL_DIR"/web2py/applications/eden/cache/*
chmod g+w "$INSTALL_DIR"/web2py/applications/eden/cache/*
chown root.users "$INSTALL_DIR"/web2py/deposit "$INSTALL_DIR"/web2py/logs
chmod g+w "$INSTALL_DIR"/web2py/deposit "$INSTALL_DIR"/web2py/logs
# does it really need to be writable?
chown root.users "$INSTALL_DIR"/web2py/welcome.w2p
chmod g+w "$INSTALL_DIR"/web2py/welcome.w2p
# does it really need to be writable?
chown root.users "$INSTALL_DIR"/web2py/applications/eden/models/0000_update*.py
chmod g+w "$INSTALL_DIR"/web2py/applications/eden/models/0000_update*.py
# Apache configuration
# Enable Modules
#a2enmod ssl
#a2enmod rewrite
#a2enmod wsgi
a2enmod proxy
a2enmod proxy_http
#Create Sahana Conf for Apache2
cat << EOF > "$SAHANA_CONF"
Alias /eden/static /usr/local/lib/web2py/applications/eden/static
ProxyRequests off
#WSGIScriptAlias /eden/ /usr/local/lib/web2py/wsgihandler.py
#WSGIDaemonProcess web2py user=web2py group=web2py home=/usr/local/lib/web2py maximum-requests=1000
# serve static files directly
<Directory /usr/local/lib/web2py/applications/eden/static/>
Order Allow,Deny
Allow from all
</Directory>
# proxy all the other requests
<Location "/eden">
Order deny,allow
Allow from all
ProxyPass http://localhost:8007/eden
ProxyPassReverse http://localhost:8007/
#ProxyHTMLURLMap http://127.0.0.1:8007/eden/ /eden
</Location>
# everything else goes over WSGI (but this doesn't work on a subfolder)
#<Directory /usr/local/lib/web2py>
# AllowOverride None
# Order Allow,Deny
# Deny from all
# <Files wsgihandler.py>
# Allow from all
# </Files>
#</Directory>
#<Location "/eden">
# Order deny,allow
# Allow from all
# WSGIProcessGroup web2py
#</Location>
EOF
a2enconf sahana.conf
# Restart Apache2
apache2ctl restart
# Create startup script
START_SCRIPT="/usr/local/bin/start_sahana.sh"
cat << EOF > "$START_SCRIPT"
#!/bin/sh
EOF
# Start Geoserver, since we can make use of it
echo "$GS_HOME/bin/startup.sh &" >> "$START_SCRIPT"
echo "cd $INSTALL_DIR/web2py" >> "$START_SCRIPT"
cat << EOF >> "$START_SCRIPT"
python web2py.py -a admin -p 8007 &
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 "Sahana starting"
zenity --info --text "Starting web browser ..."
firefox "http://localhost:8007/eden"
EOF
chmod +x "$START_SCRIPT"
# Add Launch icon to desktop
chmod 644 "$BUILD_DIR"/../app-conf/sahana/sahana.png
cp "$BUILD_DIR"/../app-conf/sahana/sahana.png /usr/share/icons/
cat << EOF > /usr/share/applications/sahana.desktop
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Sahana
Comment=Sahana Eden
Categories=Application;Internet;
Exec=/usr/local/bin/start_sahana.sh
Icon=/usr/share/icons/sahana.png
Terminal=false
StartupNotify=false
EOF
# Prepare Desktop
mkdir -p "$USER_HOME/Desktop"
cp -f /usr/share/applications/sahana.desktop \
"$USER_HOME/Desktop/sahana.desktop"
# cleanup, but do not remove python-dev here
# apt-get --assume-yes remove python-dev
rm -rf "$INSTALL_DIR/web2py/.git"*
rm -rf "$INSTALL_DIR/web2py/applications/eden/.git"*
####
"$BUILD_DIR"/diskspace_probe.sh "`basename $0`" end