forked from GeoNode/postgis-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
initdb-geonode.sh
executable file
·48 lines (43 loc) · 1.49 KB
/
initdb-geonode.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
#!/bin/bash
set -e
function create_geonode_user_and_database() {
local db=$1
echo " Creating user and database '$db'"
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
CREATE USER $db;
ALTER USER $db with encrypted password '$GEONODE_DATABASE_PASSWORD';
CREATE DATABASE $db;
GRANT ALL PRIVILEGES ON DATABASE $db TO $db;
EOSQL
}
function create_geonode_user_and_geodatabase() {
local geodb=$1
echo " Creating user and database '$geodb'"
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
CREATE USER $geodb;
ALTER USER $geodb with encrypted password '$GEONODE_GEODATABASE_PASSWORD';
CREATE DATABASE $geodb;
GRANT ALL PRIVILEGES ON DATABASE $geodb TO $geodb;
EOSQL
}
function update_database_with_postgis() {
local db=$1
echo " Updating databse '$db' with extension"
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$db" <<-EOSQL
CREATE EXTENSION IF NOT EXISTS postgis;
GRANT ALL ON geometry_columns TO PUBLIC;
GRANT ALL ON spatial_ref_sys TO PUBLIC;
EOSQL
}
if [ -n "$GEONODE_DATABASE" ]; then
echo "Geonode database creation requested: $GEONODE_DATABASE"
create_geonode_user_and_database $GEONODE_DATABASE
update_database_with_postgis $GEONODE_DATABASE
echo "Geonode database created"
fi
if [ -n "$GEONODE_GEODATABASE" ]; then
echo "Geonode geodatabase creation requested: $GEONODE_GEODATABASE"
create_geonode_user_and_geodatabase $GEONODE_GEODATABASE
update_database_with_postgis $GEONODE_GEODATABASE
echo "Geonode geodatabase created"
fi