Update sahana install script to use git

Programatically insert Sahana admin account to database
This commit is contained in:
Disassembler 2017-08-31 11:24:47 +02:00
parent 5db7d52b07
commit 5c30cc871a
3 changed files with 49 additions and 10 deletions

View File

@ -3,25 +3,21 @@
SOURCE_DIR=$(realpath $(dirname "${0}"))
# Install dependencies for Sahana
apt-get -y --no-install-recommends install python-dateutil python-imaging python-lxml python-matplotlib python-psycopg2 python-reportlab python-requests python-shapely python-xlrd python-xlwt
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
# Install web2py
git clone --recursive https://github.com/web2py/web2py.git /srv/sahana
git -C /srv/sahana checkout tags/latest
git -C /srv/sahana checkout cda35fd
git -C /srv/sahana submodule update
rm -rf /srv/sahana/.git* /srv/sahana/gluon/packages/dal/.git*
# Install Sahana
wget https://github.com/sahana/eden/archive/master.tar.gz -O /srv/sahana/applications/eden.tgz
tar xzf /srv/sahana/applications/eden.tgz -C /srv/sahana/applications/
mv /srv/sahana/applications/eden-master /srv/sahana/applications/eden
rm -f /srv/sahana/applications/eden.tgz
git clone https://github.com/sahana/eden.git /srv/sahana/applications/eden
# Create PostgreSQL user and database
export SAHANA_PWD=$(head -c 260 /dev/urandom | tr -cd '[:alnum:]' | head -c 26)
envsubst <${SOURCE_DIR}/sahana/tmp/createdb-sahana.sql >/tmp/createdb-sahana.sql
sudo -u postgres psql -f /tmp/createdb-sahana.sql
rm -f /tmp/createdb-sahana.sql
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
# Configure web2py
cp ${SOURCE_DIR}/sahana/srv/sahana/routes.py /srv/sahana/routes.py
@ -34,6 +30,14 @@ mkdir -p /srv/sahana/applications/eden/static/cache/chart
mkdir -p /srv/sahana/applications/eden/uploads/{gis_cache,images,tracks}
export SAHANA_HMAC=$(head -c 260 /dev/urandom | tr -cd '[:alnum:]' | head -c 26)
envsubst <${SOURCE_DIR}/sahana/srv/sahana/applications/eden/models/000_config.py >/srv/sahana/applications/eden/models/000_config.py
#cp ${SOURCE_DIR}/sahana/srv/sahana/applications/eden/modules/templates/default/config.py /srv/sahana/applications/eden/modules/templates/default/config.py
cp ${SOURCE_DIR}/sahana/srv/sahana/applications/eden/languages/cz.py /srv/sahana/applications/eden/languages/cz.py
# Patch bugs
#cp ${SOURCE_DIR}/sahana/srv/sahana/applications/eden/modules/s3/s3resource.py /srv/sahana/applications/eden/modules/s3/s3resource.py
#cp ${SOURCE_DIR}/sahana/srv/sahana/applications/eden/modules/s3db/delphi.py /srv/sahana/applications/eden/modules/s3db/delphi.py
#cp ${SOURCE_DIR}/sahana/srv/sahana/applications/eden/modules/s3db/org.py /srv/sahana/applications/eden/modules/s3db/org.py
#cp ${SOURCE_DIR}/sahana/srv/sahana/gluon/contrib/login_methods/openid_auth.py /srv/sahana/gluon/contrib/login_methods/openid_auth.py
# Create OS user
adduser --system --group --home /srv/sahana --shell /bin/false sahana
@ -48,6 +52,12 @@ sed -i 's/settings.base.migrate = True/settings.base.migrate = False/' /srv/saha
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
# Create admin account
export SAHANA_ADMIN_HASH=$(python ${SOURCE_DIR}/sahana/sahana-password-hash.py)
envsubst <${SOURCE_DIR}/sahana/tmp/sahana-adminaccount.sql >/tmp/sahana-adminaccount.sql
sudo -u postgres psql -f /tmp/sahana-adminaccount.sql sahana
rm /tmp/sahana-adminaccount.sql
# 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

View File

@ -0,0 +1,8 @@
#!/usr/bin/env python
import os
import sys
sys.path.append('/srv/sahana')
from gluon import CRYPT
print str(CRYPT(key=os.environ['SAHANA_HMAC'], digest_alg='sha512')('ZsG:nzP4Tv@AdX1L')[0])

View File

@ -0,0 +1,21 @@
INSERT INTO auth_user (first_name, last_name, email, password, username, language, utc_offset, organisation_id, org_group_id, site_id, link_user_to, registration_key, reset_password_key, deleted, timestmp, comments, uuid, mci, created_on, modified_on) VALUES
('Admin', 'Admin', 'noreply@example.com', '${SAHANA_ADMIN_HASH}', 'noreply_example.com', 'cz', '+0200', NULL, NULL, NULL, NULL, '', '', 'F', '2017-01-01 00:00:00', NULL, 'urn:uuid:b96b72d2-0753-42bd-b849-6e0a86149b84', 0, '2017-01-01 00:00:00', '2017-01-01 00:00:00');
INSERT INTO auth_membership (user_id, group_id, pe_id, uuid, mci, created_on, modified_on, deleted, deleted_fk, deleted_rb) VALUES
(1, 2, NULL, 'urn:uuid:863c8867-bdc3-4fa1-afb6-91e6863d44a5', 0, '2017-01-01 00:00:00', '2017-01-01 00:00:00', 'F', NULL, NULL),
(1, 1, NULL, 'urn:uuid:1cbf342d-51f8-4cf4-96d5-fb2e7d36d45b', 0, '2017-01-01 00:00:00', '2017-01-01 00:00:00', 'F', NULL, NULL);
INSERT INTO pr_pentity (deleted, instance_type, uuid, type, pe_label) VALUES
('F', 'pr_person', 'urn:uuid:1b8cf009-d28f-459c-abdd-c9ab58566f8e', NULL, NULL);
INSERT INTO sit_trackable (deleted, instance_type, uuid, track_timestmp) VALUES
('F', 'pr_person', 'urn:uuid:1b8cf009-d28f-459c-abdd-c9ab58566f8e', NULL);
INSERT INTO pr_contact (pe_id, contact_method, contact_description, value, priority, access, poll, comments, uuid, mci, deleted, deleted_fk, deleted_rb, created_on, modified_on, approved_by, created_by, modified_by, owned_by_user, owned_by_group, realm_entity) VALUES
(1, 'EMAIL', NULL, 'noreply@example.com', 1, 1, 'F', NULL, 'urn:uuid:f6192e0f-bdd0-4a69-989e-dd1a9b81b909', 0, 'F', NULL, NULL, '2017-01-01 00:00:00', '2017-01-01 00:00:00', NULL, NULL, NULL, 1, NULL, NULL);
INSERT INTO pr_person (pe_id, track_id, location_id, pe_label, missing, first_name, middle_name, last_name, initials, preferred_name, local_name, gender, date_of_birth, opt_in, comments, uuid, mci, deleted, deleted_fk, deleted_rb, created_on, modified_on, approved_by, created_by, modified_by, owned_by_user, owned_by_group, realm_entity) VALUES
(1, 1, NULL, NULL, 'F', 'Admin', NULL, 'Admin', NULL, NULL, NULL, 1, NULL, '||', NULL, 'urn:uuid:1b8cf009-d28f-459c-abdd-c9ab58566f8e', 0, 'F', NULL, NULL, '2017-01-01 00:00:00', '2017-01-01 00:00:00', NULL, NULL, 1, 1, NULL, NULL);
INSERT INTO pr_person_user (pe_id, user_id, uuid, mci, deleted, deleted_fk, deleted_rb, created_on, modified_on, approved_by, created_by, modified_by, owned_by_user, owned_by_group, realm_entity) VALUES
(1, 1, 'urn:uuid:8f48de7a-d3d8-4d1d-a6bd-7ee906a26264', 0, 'F', NULL, NULL, '2017-01-01 00:00:00', '2017-01-01 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL);