annotate postgres/setupDatabase.sh @ 54:334d65dac778

add hash bangs to specify bash shell
author smith@nwoca.org
date Wed, 24 Feb 2016 18:23:42 +0000
parents 0cdc167e6319
children 53671513b240
rev   line source
3
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
1 #!/bin/bash
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
2
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
3 export PGUSER=postgres
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
4 TEST=`psql <<- EOSQL
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
5 SELECT 1 FROM pg_database WHERE datname='$DB_NAME';
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
6 EOSQL`
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
7
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
8 if [[ $TEST == "1" ]]; then
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
9 echo "$DB_NAME exists. continuing startup."
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
10 # database exists
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
11 # $? is 0
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
12 exit 0
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
13 else
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
14 echo "Creating $DB_NAME for $DB_USER"
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
15 psql <<- EOSQL
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
16 CREATE ROLE $DB_USER WITH LOGIN ENCRYPTED PASSWORD '${DB_PASS}' CREATEDB;
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
17 CREATE DATABASE $DB_NAME WITH OWNER $DB_USER TEMPLATE template0 ENCODING 'UTF8';
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
18 GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER;
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
19 EOSQL
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
20 fi
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
21
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
22 echo ""
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
23 echo "$DB_NAME database created"