comparison schema/install-db.sh @ 330:fd04bccae6ca

Create standard roles as part of the base schema. We will always need: 1. a gemma service user 2. an initial sys_admin user so these are now created as part of the base gemma schema. The install-db script now creates random default passwords for this accounts. As the complexity is sufficiently increased by now I also changed the Quick Start guide to use an configuration file and provided an example file.
author Sascha Wilde <wilde@intevation.de>
date Fri, 03 Aug 2018 13:40:10 +0200
parents ac760b0f22a9
children a85f56207d80
comparison
equal deleted inserted replaced
329:71970f03c9e8 330:fd04bccae6ca
25 { 25 {
26 echo >&2 "$1" 26 echo >&2 "$1"
27 exit 23 27 exit 23
28 } 28 }
29 29
30 genpw()
31 # $1 - length
32 {
33 dd count=1 if=/dev/urandom 2>/dev/null \
34 | tr -cd '[:alnum:],._!?-' | tail -c "$1"
35 }
30 36
31 # Defaults: 37 # Defaults:
32 38
33 db=gemma 39 db=gemma
34 port=5432 40 port=5432
81 createdb -p "$port" "$db" 87 createdb -p "$port" "$db"
82 psql -qt -p "$port" -d "$db" \ 88 psql -qt -p "$port" -d "$db" \
83 -c "SET client_min_messages TO WARNING;" \ 89 -c "SET client_min_messages TO WARNING;" \
84 -f "$BASEDIR/gemma.sql" \ 90 -f "$BASEDIR/gemma.sql" \
85 -f "$BASEDIR/manage_users.sql" \ 91 -f "$BASEDIR/manage_users.sql" \
86 -f "$BASEDIR/auth.sql" 92 -f "$BASEDIR/auth.sql" \
93 -f "$BASEDIR/std_login_roles.sql"
87 94
88 if [[ $demo -eq 1 ]] ; then 95 if [[ $demo -eq 1 ]] ; then
89 psql -q -p "$port" -f "$BASEDIR/demo-data/responsibility_areas.sql" \ 96 psql -q -p "$port" -f "$BASEDIR/demo-data/responsibility_areas.sql" \
90 -d "$db" 97 -d "$db"
91 psql -q -p "$port" -f "$BASEDIR/demo-data/roles.sql" \ 98 psql -q -p "$port" -f "$BASEDIR/demo-data/roles.sql" \
92 -f "$BASEDIR/demo-data/users.sql" -d "$db" 99 -f "$BASEDIR/demo-data/users.sql" -d "$db"
93 fi 100 fi
101
102 # Generate and set Passwords
103 adminpw=`genpw 15`
104 servicepw=`genpw 15`
105
106 psql -qt -p "$port" -d "$db" \
107 -c "ALTER ROLE sysadmin PASSWORD '$adminpw'"
108 psql -qt -p "$port" -d "$db" \
109 -c "ALTER ROLE gemma_service PASSWORD '$servicepw'"
110 echo "Default admin user 'sysadmin' created with password '$adminpw'."
111 echo "Back end user 'gemma_service' created with password '$servicepw'."
94 else 112 else
95 # Evil mode: drop everything gemma 113 # Evil mode: drop everything gemma
96 echo "Really drop database '$db' and alle gemma roles? [type 'yes']: " 114 echo "Really drop database '$db' and alle gemma roles? [type 'yes']: "
97 read a 115 read a
98 if [[ $a == "yes" ]] ; then 116 if [[ $a == "yes" ]] ; then