annotate postgres/setupDatabase.sh @ 286:477609392d1b

fix missing ant version
author smith@nwoca.org
date Thu, 06 Dec 2018 17:23:30 +0000
parents 53671513b240
children
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
81
53671513b240 DEP-10: add timezone and locale settings. add java base image. add native APR for tomcat
smith@nwoca.org
parents: 3
diff changeset
4 result=`psql -t -A <<- EOSQL
3
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
81
53671513b240 DEP-10: add timezone and locale settings. add java base image. add native APR for tomcat
smith@nwoca.org
parents: 3
diff changeset
8 echo "checking for existing $DB_NAME ( $result ) "
53671513b240 DEP-10: add timezone and locale settings. add java base image. add native APR for tomcat
smith@nwoca.org
parents: 3
diff changeset
9
53671513b240 DEP-10: add timezone and locale settings. add java base image. add native APR for tomcat
smith@nwoca.org
parents: 3
diff changeset
10 if [[ $result == "1" ]]; then
3
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
11 echo "$DB_NAME exists. continuing startup."
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
12 # database exists
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
13 # $? is 0
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
14 exit 0
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
15 else
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
16 echo "Creating $DB_NAME for $DB_USER"
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
17 psql <<- EOSQL
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
18 CREATE ROLE $DB_USER WITH LOGIN ENCRYPTED PASSWORD '${DB_PASS}' CREATEDB;
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
19 CREATE DATABASE $DB_NAME WITH OWNER $DB_USER TEMPLATE template0 ENCODING 'UTF8';
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
20 GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER;
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
21 EOSQL
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
22 fi
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
23
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
24 echo ""
0cdc167e6319 DEP-2: postgres dockerfile
smith@nwoca.org
parents:
diff changeset
25 echo "$DB_NAME database created"