forked from markiliffe/hxl-extraction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_database.sh
executable file
·34 lines (30 loc) · 1.32 KB
/
install_database.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
#!/bin/bash
DATABASE_NAME=hxlextract
DATABASE_USER=hxlextract
# Set the PostGIS version
if [ -z "$1" ]; then
PGIS_VERSION=1.5
else
PGIS_VERSION="$1"
fi
# Create the spatial database
POSTGIS_SQL_PATH=`pg_config --sharedir`/contrib/postgis-$PGIS_VERSION
exists=`psql --list | egrep '\btemplate_postgis\b'`
# Check if the template_postgis database exists. If not, create it.
if [ -z "$exists" ]; then
# Creating the template spatial database.
createdb -E UTF8 template_postgis
createlang -d template_postgis plpgsql # Adding PLPGSQL language support.
# Allows non-superusers the ability to create from this template
psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis';"
# Loading the PostGIS SQL routines
psql -d template_postgis -f $POSTGIS_SQL_PATH/postgis.sql
psql -d template_postgis -f $POSTGIS_SQL_PATH/spatial_ref_sys.sql
# Enabling users to alter spatial tables.
psql -d template_postgis -c "GRANT ALL ON geometry_columns TO PUBLIC;"
psql -d template_postgis -c "GRANT ALL ON geography_columns TO PUBLIC;"
psql -d template_postgis -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"
fi
# Create a new djangorifa user - will prompt for a password but nothing else
createuser -P -D -R -S $DATABASE_USER
createdb -T template_postgis -E 'utf8' -O $DATABASE_USER $DATABASE_NAME