comparison db_schema/setup-db.sh @ 932:f5d5cc08966a

Remove wrong test operator and prepare for more options.
author Tom Gottfried <tom@intevation.de>
date Fri, 06 May 2016 12:13:15 +0200
parents 77ab53348966
children 56d2dd058906
comparison
equal deleted inserted replaced
931:77ab53348966 932:f5d5cc08966a
9 # There will be used a remote database server if there exists the enviroment variable DB_SRV 9 # There will be used a remote database server if there exists the enviroment variable DB_SRV
10 # and optional DB_PORT 10 # and optional DB_PORT
11 11
12 DIR=`dirname $0` 12 DIR=`dirname $0`
13 13
14 if [ " $1" == " -c" ] ; then 14 while getopts "c" opt; do
15 DROP_DB="true" 15 case "$opt" in
16 shift 16 c)
17 fi 17 DROP_DB="true"
18 ;;
19 esac
20 done
21
22 shift $((OPTIND-1))
18 23
19 ROLE_NAME=${1:-lada} 24 ROLE_NAME=${1:-lada}
20 echo "DROLE_NAME = $ROLE_NAME" 25 echo "DROLE_NAME = $ROLE_NAME"
21 ROLE_PW=${2:-$ROLE_NAME} 26 ROLE_PW=${2:-$ROLE_NAME}
22 echo "ROLE_PW = $ROLE_PW" 27 echo "ROLE_PW = $ROLE_PW"
34 if [ `psql $DB_CONNECT_STRING -t --command "SELECT count(*) FROM pg_catalog.pg_user WHERE usename = '$ROLE_NAME'"` -eq 0 ] ; then 39 if [ `psql $DB_CONNECT_STRING -t --command "SELECT count(*) FROM pg_catalog.pg_user WHERE usename = '$ROLE_NAME'"` -eq 0 ] ; then
35 echo create user $ROLE_NAME 40 echo create user $ROLE_NAME
36 psql $DB_CONNECT_STRING --command "CREATE USER $ROLE_NAME PASSWORD '$ROLE_PW';" 41 psql $DB_CONNECT_STRING --command "CREATE USER $ROLE_NAME PASSWORD '$ROLE_PW';"
37 fi 42 fi
38 43
39 if [ "$DROP_DB" == "true" ] && psql $DB_CONNECT_STRING -l | grep -q "^ $DB_NAME " ; then 44 if [ "$DROP_DB" = "true" ] && psql $DB_CONNECT_STRING -l | grep -q "^ $DB_NAME " ; then
40 echo drop db $DB_NAME 45 echo drop db $DB_NAME
41 psql $DB_CONNECT_STRING --command "DROP DATABASE $DB_NAME" 46 psql $DB_CONNECT_STRING --command "DROP DATABASE $DB_NAME"
42 fi 47 fi
43 48
44 echo create db $DB_NAME 49 echo create db $DB_NAME
45 psql $DB_CONNECT_STRING --command \ 50 psql $DB_CONNECT_STRING --command \
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)