Mercurial > gemma
changeset 258:2ce5cf4bca35
Merged.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 27 Jul 2018 13:04:17 +0200 |
parents | dfc2b035e055 (current diff) 1ff9aec9326f (diff) |
children | f1280801ba8c |
files | |
diffstat | 1 files changed, 37 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/schema/install-db.sh Fri Jul 27 13:03:56 2018 +0200 +++ b/schema/install-db.sh Fri Jul 27 13:04:17 2018 +0200 @@ -14,6 +14,7 @@ -d, --db=NAME connect to the database NAME -p, --port=PORT connect do the postgresql cluster at PORT -D, --demo install demo accounts and data + --drop drop database and all roles --help display this help and exit EOF @@ -31,12 +32,12 @@ db=gemma port=5432 demo=0 - +drop=0 # Parse options: OPTS=`getopt \ - -l help,demo,db:,port: \ + -l help,demo,db:,port:,drop \ -o Dd:p: -n "$ME" -- "$@"` [ $? -eq 0 ] || { usage ; exit 1 ; } @@ -56,6 +57,10 @@ demo=1 shift 1 ;; + --drop) + drop=1 + shift 1 + ;; --help) { usage ; exit 0 ; } ;; @@ -69,16 +74,35 @@ # Main ------------------------------------------------------------ -psql -p "$port" -f "$BASEDIR/roles.sql" -createdb -p "$port" "$db" -psql -p "$port" -d "$db" \ - -f "$BASEDIR/gemma.sql" \ - -f "$BASEDIR/manage_users.sql" \ - -f "$BASEDIR/auth.sql" +if [[ drop -eq 0 ]] ; then + # Default operation: create schema + psql -q -p "$port" -f "$BASEDIR/roles.sql" + createdb -p "$port" "$db" + psql -q -p "$port" -d "$db" \ + -f "$BASEDIR/gemma.sql" \ + -f "$BASEDIR/manage_users.sql" \ + -f "$BASEDIR/auth.sql" -if [[ $demo -eq 1 ]] ; then - psql -p "$port" -f "$BASEDIR/demo-data/responsibility_areas.sql" \ - -d "$db" - psql -p "$port" -f "$BASEDIR/demo-data/roles.sql" \ - -f "$BASEDIR/demo-data/users.sql" -d "$db" + if [[ $demo -eq 1 ]] ; then + psql -q -p "$port" -f "$BASEDIR/demo-data/responsibility_areas.sql" \ + -d "$db" + psql -q -p "$port" -f "$BASEDIR/demo-data/roles.sql" \ + -f "$BASEDIR/demo-data/users.sql" -d "$db" + fi +else + # Evil mode: drop everything gemma + echo "Really drop database '$db' and alle gemma roles? [type 'yes']: " + read a + if [[ $a == "yes" ]] ; then + dropdb -p "$port" "$db" + for r in `psql -p 5433 -t -c '\du' | awk -F '|' \ + '$3 ~/waterway_user|waterway_admin|sys_admin/ \ + || $1 ~/waterway_user|waterway_admin|sys_admin/ \ + {print $1}'` + do + dropuser -p "$port" "$r" + done + else + echo "No harm done." + fi fi