1 | #!/bin/sh
|
---|
2 | # Script to configure an Eden server
|
---|
3 | # - assumes that install-eden-apache-postgis-debian8.sh has been run
|
---|
4 |
|
---|
5 | # Defines for sahana eden installation
|
---|
6 | hostanddomain="127.0.0.1"
|
---|
7 | template="default"
|
---|
8 | key="testkey"
|
---|
9 | database_type="postgres"
|
---|
10 |
|
---|
11 | # Defines for database connection
|
---|
12 | database_name="sahana"
|
---|
13 | database_port="5432"
|
---|
14 | database_user="sahana"
|
---|
15 | database_password="sahana"
|
---|
16 |
|
---|
17 | #########
|
---|
18 | # Eden pre-installation of database
|
---|
19 | #########
|
---|
20 | #copy config template
|
---|
21 | cp ~web2py/applications/eden/modules/templates/000_config.py ~web2py/applications/eden/models
|
---|
22 | # adopt template according to defined values
|
---|
23 | sed -i "s|settings.base.template = \"default\"|settings.base.template = \"$template\"|" ~web2py/applications/eden/models/000_config.py
|
---|
24 | sed -i 's|EDITING_CONFIG_FILE = False|EDITING_CONFIG_FILE = True|' ~web2py/applications/eden/models/000_config.py
|
---|
25 | sed -i "s|akeytochange|$key|" ~web2py/applications/eden/models/000_config.py
|
---|
26 | sed -i "s|#settings.base.public_url = \"http://127.0.0.1:8000\"|settings.base.public_url = \"http://$hostanddomain\"|" ~web2py/applications/eden/models/000_config.py
|
---|
27 | #? wherefor
|
---|
28 | sed -i 's|#settings.base.cdn = True|settings.base.cdn = True|' ~web2py/applications/eden/models/000_config.py
|
---|
29 |
|
---|
30 | #########
|
---|
31 | # PostgreSQL
|
---|
32 | #########
|
---|
33 | cd ~web2py
|
---|
34 | #-------
|
---|
35 | #drop db if one already exists - before we have to stop the wsgi process!!
|
---|
36 | /etc/init.d/apache2 stop
|
---|
37 | echo "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$database_name';" > /tmp/delete_current_connections.sql
|
---|
38 | su - postgres -c "psql -q -p $database_port -f /tmp/delete_current_connections.sql"
|
---|
39 | su - postgres -c "dropdb -p $database_port $database_name"
|
---|
40 | echo "database dropped"
|
---|
41 | echo "CREATE USER $database_user WITH PASSWORD '$database_password';" > /tmp/pgpass.sql
|
---|
42 | su - postgres -c "psql -q -p $database_port -d template1 -f /tmp/pgpass.sql"
|
---|
43 | #template 1? - for roles
|
---|
44 | rm -f /tmp/pgpass.sql
|
---|
45 | su - postgres -c "createdb -p $database_port -O $database_user -E UTF8 $database_name -T template0"
|
---|
46 | # PostGIS
|
---|
47 | su - postgres -c "psql -q -p $database_port -d $database_name -f /usr/share/postgresql/9.4/contrib/postgis-2.1/postgis.sql"
|
---|
48 | su - postgres -c "psql -q -p $database_port -d $database_name -f /usr/share/postgresql/9.4/contrib/postgis-2.1/spatial_ref_sys.sql"
|
---|
49 | su - postgres -c "psql -q -p $database_port -d $database_name -c 'grant all on geometry_columns to $database_user;'"
|
---|
50 | # maybe new to postgis 2.x
|
---|
51 | su - postgres -c "psql -q -p $database_port -d $database_name -c 'grant all on geography_columns to $database_user;'"
|
---|
52 | su - postgres -c "psql -q -p $database_port -d $database_name -c 'grant all on spatial_ref_sys to $database_user;'"
|
---|
53 | # maybe the following is not needed
|
---|
54 | su - postgres -c "psql -q -p $database_port -d $database_name -c 'ALTER DATABASE $database_name OWNER TO $database_user;'"
|
---|
55 |
|
---|
56 | #########
|
---|
57 | # Eden post-installation of database
|
---|
58 | #########
|
---|
59 | # Disable comment on postgres configuration line
|
---|
60 | sed -i 's|#settings.database.db_type = "postgres"|settings.database.db_type = "postgres"|' ~web2py/applications/eden/models/000_config.py
|
---|
61 | # Defining password for database connection
|
---|
62 | sed -i "s|#settings.database.password = \"password\"|settings.database.password = \"$database_password\"|" ~web2py/applications/eden/models/000_config.py
|
---|
63 | # Enable spatial settings
|
---|
64 | sed -i 's|#settings.gis.spatialdb = True|settings.gis.spatialdb = True|' ~web2py/applications/eden/models/000_config.py
|
---|
65 | # Create the Tables & Populate with base data
|
---|
66 | # next line from mysql installation instruction - needed?
|
---|
67 | sed -i 's|settings.base.prepopulate = 0|#settings.base.prepopulate = 0|' ~web2py/applications/eden/models/000_config.py
|
---|
68 | #sed -i 's|settings.base.prepopulate = 0|settings.base.prepopulate = 1|' ~web2py/applications/eden/models/000_config.py
|
---|
69 | # If invoked a second time maybe it stucks on commented line!
|
---|
70 | #sed -i 's|#settings.base.prepopulate = 0|settings.base.prepopulate = 1|' ~web2py/applications/eden/models/000_config.py
|
---|
71 | sed -i 's|settings.base.migrate = False|settings.base.migrate = True|' ~web2py/applications/eden/models/000_config.py
|
---|
72 | cd ~web2py
|
---|
73 | # Delete .table entries for database which exists before, cause otherwise the new database will not be prepopulated
|
---|
74 | rm -rf ~web2py/applications/eden/databases/*
|
---|
75 | rm -rf ~web2py/applications/eden/compiled
|
---|
76 | sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
|
---|
77 | # Next line needed?
|
---|
78 | sed -i 's|#settings.base.prepopulate = 0|settings.base.prepopulate = 0|' ~web2py/applications/eden/models/000_config.py
|
---|
79 | #sed -i 's|settings.base.prepopulate = 1|settings.base.prepopulate = 0|' ~web2py/applications/eden/models/000_config.py
|
---|
80 | sed -i 's|settings.base.migrate = True|settings.base.migrate = False|' ~web2py/applications/eden/models/000_config.py
|
---|
81 | cd ~web2py
|
---|
82 | # notice - after compile the apache2 process is restarted!!!
|
---|
83 | sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/compile.py
|
---|
84 | # Schedule backups for 02:01 daily
|
---|
85 | echo "1 2 * * * root /usr/local/bin/backup" >> "/etc/crontab"
|
---|
86 | #read -p "Press any key to Reboot..."
|
---|
87 | #########
|
---|
88 | # Reboot? - why
|
---|
89 | #########
|
---|
90 | echo "Now rebooting.."
|
---|
91 | #reboot
|
---|