2017-06-25 20:49:41 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
SOURCE_DIR=$(realpath $(dirname "${0}"))
|
|
|
|
|
|
|
|
# Install dependencies for Sahana
|
2017-08-31 11:24:47 +02:00
|
|
|
apt-get -y --no-install-recommends install python-dateutil python-imaging python-lxml python-matplotlib python-openid python-psycopg2 python-reportlab python-requests python-shapely python-xlrd python-xlwt
|
2017-06-25 20:49:41 +02:00
|
|
|
|
|
|
|
# Install web2py
|
2017-07-18 15:44:06 +02:00
|
|
|
git clone --recursive https://github.com/web2py/web2py.git /srv/sahana
|
2017-08-31 11:24:47 +02:00
|
|
|
git -C /srv/sahana checkout cda35fd
|
2017-07-18 15:44:06 +02:00
|
|
|
git -C /srv/sahana submodule update
|
2017-06-25 20:49:41 +02:00
|
|
|
|
|
|
|
# Install Sahana
|
2017-09-01 14:25:17 +02:00
|
|
|
git clone --depth 1 https://github.com/sahana/eden.git /srv/sahana/applications/eden
|
2017-06-25 20:49:41 +02:00
|
|
|
|
|
|
|
# Create PostgreSQL user and database
|
2017-09-01 14:25:17 +02:00
|
|
|
export SAHANA_PWD=$(head -c 18 /dev/urandom | base64)
|
2017-08-31 11:24:47 +02:00
|
|
|
envsubst <${SOURCE_DIR}/sahana/tmp/sahana-createdb.sql >/tmp/sahana-createdb.sql
|
|
|
|
sudo -u postgres psql -f /tmp/sahana-createdb.sql
|
|
|
|
rm -f /tmp/sahana-createdb.sql
|
2017-06-25 20:49:41 +02:00
|
|
|
|
|
|
|
# Configure web2py
|
2017-09-10 21:38:31 +02:00
|
|
|
rm -rf /srv/sahana/applications/{admin,examples,welcome}
|
2017-06-25 20:49:41 +02:00
|
|
|
cp ${SOURCE_DIR}/sahana/srv/sahana/routes.py /srv/sahana/routes.py
|
|
|
|
cp ${SOURCE_DIR}/sahana/srv/sahana/run_scheduler.py /srv/sahana/run_scheduler.py
|
|
|
|
ln -s /srv/sahana/handlers/wsgihandler.py /srv/sahana/wsgihandler.py
|
|
|
|
|
|
|
|
# Configure Sahana
|
|
|
|
mkdir /srv/sahana/applications/eden/{databases,errors,sessions}
|
|
|
|
mkdir -p /srv/sahana/applications/eden/static/cache/chart
|
|
|
|
mkdir -p /srv/sahana/applications/eden/uploads/{gis_cache,images,tracks}
|
2017-09-01 14:25:17 +02:00
|
|
|
export SAHANA_HMAC=$(head -c 18 /dev/urandom | base64)
|
2017-06-25 20:49:41 +02:00
|
|
|
envsubst <${SOURCE_DIR}/sahana/srv/sahana/applications/eden/models/000_config.py >/srv/sahana/applications/eden/models/000_config.py
|
2017-09-10 21:38:31 +02:00
|
|
|
cp ${SOURCE_DIR}/sahana/srv/sahana/applications/eden/modules/templates/default/config.py /srv/sahana/applications/eden/modules/templates/default/config.py
|
2017-09-14 21:56:09 +02:00
|
|
|
export SAHANA_ADMIN_USER=admin@example.com
|
|
|
|
export SAHANA_ADMIN_PWD=$(head -c 18 /dev/urandom | base64)
|
2017-09-01 14:25:17 +02:00
|
|
|
envsubst <${SOURCE_DIR}/sahana/srv/sahana/applications/eden/modules/templates/default/users/masterUsers.csv >/srv/sahana/applications/eden/modules/templates/default/users/masterUsers.csv
|
2017-08-31 11:24:47 +02:00
|
|
|
cp ${SOURCE_DIR}/sahana/srv/sahana/applications/eden/languages/cz.py /srv/sahana/applications/eden/languages/cz.py
|
|
|
|
|
2017-06-25 20:49:41 +02:00
|
|
|
# Create OS user
|
|
|
|
adduser --system --group --home /srv/sahana --shell /bin/false sahana
|
|
|
|
chown -R sahana:sahana /srv/sahana
|
|
|
|
|
|
|
|
# Populate database
|
|
|
|
cd /srv/sahana
|
|
|
|
sudo -u sahana python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
|
|
|
|
|
2017-09-13 13:17:38 +02:00
|
|
|
# Set "production values" (increases performance). Only if the DEBUG environment variable doesn't exist
|
|
|
|
if [ -z "${DEBUG}" ]; then
|
|
|
|
sed -i 's/settings.base.migrate = True/settings.base.migrate = False/' /srv/sahana/applications/eden/models/000_config.py
|
|
|
|
sed -i 's/settings.base.debug = True/settings.base.debug = False/' /srv/sahana/applications/eden/models/000_config.py
|
|
|
|
sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' /srv/sahana/applications/eden/models/000_config.py
|
|
|
|
sudo -u sahana python web2py.py -S eden -M -R applications/eden/static/scripts/tools/compile.py
|
|
|
|
fi
|
2017-06-25 20:49:41 +02:00
|
|
|
|
|
|
|
# Create uwsgi and nginx app definition
|
|
|
|
cp ${SOURCE_DIR}/sahana/etc/uwsgi/apps-available/sahana.ini /etc/uwsgi/apps-available/sahana.ini
|
|
|
|
ln -s /etc/uwsgi/apps-available/sahana.ini /etc/uwsgi/apps-enabled/sahana.ini
|
|
|
|
cp ${SOURCE_DIR}/sahana/etc/nginx/apps-available/sahana /etc/nginx/apps-available/sahana
|
|
|
|
ln -s /etc/nginx/apps-available/sahana /etc/nginx/apps-enabled/sahana
|
|
|
|
|
|
|
|
# Restart services
|
|
|
|
systemctl restart uwsgi
|
|
|
|
systemctl restart nginx
|
|
|
|
|
2017-09-14 21:56:09 +02:00
|
|
|
# Add portal application definition
|
|
|
|
${SOURCE_DIR}/basic/portal-app-manager.py sahana-eden "https://{host}/eden/" "${SAHANA_ADMIN_USER}" "${SAHANA_ADMIN_PWD}"
|
|
|
|
|
2017-06-25 20:49:41 +02:00
|
|
|
# TODO: Does matplotlib still require MPLCONFIGDIR directory?
|
|
|
|
# If so, /srv/sahana/wsgihandler.py needs to be modified
|
|
|
|
|
|
|
|
# TODO: Potentially needed dependencies
|
|
|
|
# WARNING: Setup unresolved dependency: boto required for Setup Module
|
|
|
|
# WARNING: S3Doc unresolved dependency: pyth required for RTF document support in Full-Text Search
|
|
|
|
# WARNING: S3Doc unresolved dependency: sunburnt required for Full-Text Search support
|
|
|
|
# WARNING: S3GIS unresolved dependency: selenium required for Map printing support
|
|
|
|
# WARNING: Setup unresolved dependency: PyYAML required for Setup Module
|
|
|
|
# WARNING: S3GIS unresolved dependency: GDAL required for Shapefile support
|
|
|
|
# WARNING: Setup unresolved dependency: ansible required for Setup Module
|
|
|
|
# WARNING: Survey unresolved dependency: PyRTF required if you want to export assessment/survey templates as a Word document
|
|
|
|
# WARNING: Unresolved optional dependency: pyserial required
|
|
|
|
# WARNING: S3Msg unresolved dependency tweepy required for non-Tropo Twitter support
|
|
|
|
# WARNING: Message Parsing unresolved dependency: TwitterSearch required for fetching results from twitter keyword queries
|
2017-09-01 14:25:17 +02:00
|
|
|
|
2017-09-10 21:38:31 +02:00
|
|
|
# TODO: Development notes
|
2017-09-01 14:25:17 +02:00
|
|
|
# vi /srv/sahana/applications/eden/modules/templates/default/config.py
|
|
|
|
# vi /srv/sahana/applications/eden/modules/s3cfg.py
|
|
|
|
# sudo -u sahana /srv/sahana/web2py.py -i 192.168.2.202 -a sahana --nogui
|
2017-09-10 21:38:31 +02:00
|
|
|
# sudo -u sahana openssl req -new -x509 -nodes -out /srv/sahana/cert.pem -keyout /srv/sahana/cert.key -subj "/C=CZ/CN=$(hostname -f)"
|
|
|
|
# sudo -u sahana /srv/sahana/web2py.py -i 192.168.2.202 -a sahana -c /srv/sahana/cert.pem -k /srv/sahana/cert.key --nogui
|