tom@5284: #!/bin/bash
felix@5287: 
tom@8794: # $1: name, user and password for new DB (optional. Default: d4e)
tom@8794: # $2: host (optional. Default: localhost)
tom@8794: 
tom@8794: SCRIPT_DIR=`dirname $0`
tom@8794: DB_NAME=${1:-d4e}
tom@8794: PG_HOST=${2:-localhost}
tom@5284: 
tom@5284: # run as user postgres (postgresql super-user)
tom@5284: # it is assumed that the owner of the DB has the same name as the DB!
tom@5284: 
tom@5284: # create PostGIS-DB
tom@8794: createuser -S -D -R $DB_NAME
tom@8794: createdb $DB_NAME
tom@8794: 
tom@8794: psql -d $DB_NAME -c "ALTER USER $DB_NAME WITH PASSWORD '$DB_NAME';"
tom@8794: 
tom@8794: psql -d $DB_NAME -c "CREATE EXTENSION postgis;"
tom@8794: psql -d $DB_NAME -c "GRANT ALL ON geometry_columns TO $DB_NAME;
tom@8794:                      GRANT ALL ON geography_columns TO $DB_NAME;
tom@8794:                      GRANT ALL ON spatial_ref_sys TO $DB_NAME;"
tom@5284: 
tom@5284: # add credentials to .pgpass (or create .pgpass)
tom@8794: echo "*:*:$DB_NAME:$DB_NAME:$DB_NAME" >> ~/.pgpass
tom@5284: chmod 0600 ~/.pgpass
tom@5284: 
tom@5284: # apply schema-scripts
tom@8794: psql -d $DB_NAME -U $DB_NAME -h $PG_HOST -f $SCRIPT_DIR/postgresql.sql
tom@8794: psql -d $DB_NAME -U $DB_NAME -h $PG_HOST -f $SCRIPT_DIR/postgresql-spatial.sql
tom@8794: psql -d $DB_NAME -U $DB_NAME -h $PG_HOST -f $SCRIPT_DIR/postgresql-minfo.sql