Create Sahana admin properly using imported CSV

This commit is contained in:
Disassembler 2017-09-01 14:25:17 +02:00
parent ee683176dc
commit df1cea0c8e
5 changed files with 15 additions and 41 deletions

View File

@ -11,10 +11,10 @@ git -C /srv/sahana checkout cda35fd
git -C /srv/sahana submodule update git -C /srv/sahana submodule update
# Install Sahana # Install Sahana
git clone https://github.com/sahana/eden.git /srv/sahana/applications/eden git clone --depth 1 https://github.com/sahana/eden.git /srv/sahana/applications/eden
# Create PostgreSQL user and database # Create PostgreSQL user and database
export SAHANA_PWD=$(head -c 260 /dev/urandom | tr -cd '[:alnum:]' | head -c 26) export SAHANA_PWD=$(head -c 18 /dev/urandom | base64)
envsubst <${SOURCE_DIR}/sahana/tmp/sahana-createdb.sql >/tmp/sahana-createdb.sql envsubst <${SOURCE_DIR}/sahana/tmp/sahana-createdb.sql >/tmp/sahana-createdb.sql
sudo -u postgres psql -f /tmp/sahana-createdb.sql sudo -u postgres psql -f /tmp/sahana-createdb.sql
rm -f /tmp/sahana-createdb.sql rm -f /tmp/sahana-createdb.sql
@ -28,9 +28,11 @@ ln -s /srv/sahana/handlers/wsgihandler.py /srv/sahana/wsgihandler.py
mkdir /srv/sahana/applications/eden/{databases,errors,sessions} mkdir /srv/sahana/applications/eden/{databases,errors,sessions}
mkdir -p /srv/sahana/applications/eden/static/cache/chart mkdir -p /srv/sahana/applications/eden/static/cache/chart
mkdir -p /srv/sahana/applications/eden/uploads/{gis_cache,images,tracks} 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) export SAHANA_HMAC=$(head -c 18 /dev/urandom | base64)
export SAHANA_ADMIN_PWD=$(head -c 18 /dev/urandom | base64)
envsubst <${SOURCE_DIR}/sahana/srv/sahana/applications/eden/models/000_config.py >/srv/sahana/applications/eden/models/000_config.py 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/modules/templates/default/config.py /srv/sahana/applications/eden/modules/templates/default/config.py
envsubst <${SOURCE_DIR}/sahana/srv/sahana/applications/eden/modules/templates/default/users/masterUsers.csv >/srv/sahana/applications/eden/modules/templates/default/users/masterUsers.csv
cp ${SOURCE_DIR}/sahana/srv/sahana/applications/eden/languages/cz.py /srv/sahana/applications/eden/languages/cz.py cp ${SOURCE_DIR}/sahana/srv/sahana/applications/eden/languages/cz.py /srv/sahana/applications/eden/languages/cz.py
# Patch bugs # Patch bugs
@ -52,12 +54,6 @@ 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 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 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 # Create uwsgi and nginx app definition
cp ${SOURCE_DIR}/sahana/etc/uwsgi/apps-available/sahana.ini /etc/uwsgi/apps-available/sahana.ini 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 ln -s /etc/uwsgi/apps-available/sahana.ini /etc/uwsgi/apps-enabled/sahana.ini
@ -68,8 +64,6 @@ ln -s /etc/nginx/apps-available/sahana /etc/nginx/apps-enabled/sahana
systemctl restart uwsgi systemctl restart uwsgi
systemctl restart nginx systemctl restart nginx
# TODO: Set cgroups
# TODO: Does matplotlib still require MPLCONFIGDIR directory? # TODO: Does matplotlib still require MPLCONFIGDIR directory?
# If so, /srv/sahana/wsgihandler.py needs to be modified # If so, /srv/sahana/wsgihandler.py needs to be modified
@ -85,3 +79,10 @@ systemctl restart nginx
# WARNING: Unresolved optional dependency: pyserial required # WARNING: Unresolved optional dependency: pyserial required
# WARNING: S3Msg unresolved dependency tweepy required for non-Tropo Twitter support # 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 # WARNING: Message Parsing unresolved dependency: TwitterSearch required for fetching results from twitter keyword queries
# TODO: remove default web2py apps
# TODO: Development notes - to be deleted
# 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

View File

@ -1,8 +0,0 @@
#!/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

@ -234,7 +234,7 @@ settings.import_template()
# e.g. # e.g.
#settings.base.system_name = T("Sahana TEST") #settings.base.system_name = T("Sahana TEST")
#settings.base.prepopulate = ("MY_TEMPLATE_ONLY") #settings.base.prepopulate = ("MY_TEMPLATE_ONLY")
#settings.base.prepopulate += ("default", "default/users") settings.base.prepopulate += ("default", "default/users")
#settings.base.theme = "default" #settings.base.theme = "default"
#settings.L10n.default_language = "en" #settings.L10n.default_language = "en"
#settings.security.policy = 7 # Organisation-ACLs #settings.security.policy = 7 # Organisation-ACLs

View File

@ -0,0 +1,2 @@
First Name,Last Name,Email,Password,Role,Organisation
Admin,User,admin@example.com,${SAHANA_ADMIN_PWD},ADMIN,
1 First Name Last Name Email Password Role Organisation
2 Admin User admin@example.com ${SAHANA_ADMIN_PWD} ADMIN

View File

@ -1,21 +0,0 @@
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);