comparison schema/install-db.sh @ 331:a85f56207d80

db-setup script: Allow to set passwords manually. Especially during testing, when setting up a fresh db it is desirable to set the passwords to well known values instead of getting fresh random ones. This is now possible.
author Sascha Wilde <wilde@intevation.de>
date Fri, 03 Aug 2018 13:52:23 +0200
parents fd04bccae6ca
children 220a893318fa
comparison
equal deleted inserted replaced
330:fd04bccae6ca 331:a85f56207d80
13 Options: 13 Options:
14 -d, --db=NAME create the database NAME. Default: "gemma" 14 -d, --db=NAME create the database NAME. Default: "gemma"
15 -p, --port=PORT connect do the postgresql cluster at PORT. 15 -p, --port=PORT connect do the postgresql cluster at PORT.
16 Default is the postgresql standard port 5432 16 Default is the postgresql standard port 5432
17 -D, --demo also install demo accounts and data 17 -D, --demo also install demo accounts and data
18 --adminpw set the password to use for the "sysadmin" account.
19 Default is a random password.
20 --servicepw set the password to use for the "gemma_service" account.
21 Default is a random password.
18 --drop drop database and all roles 22 --drop drop database and all roles
19 --help display this help and exit 23 --help display this help and exit
20 24
21 EOF 25 EOF
22 } 26 }
38 42
39 db=gemma 43 db=gemma
40 port=5432 44 port=5432
41 demo=0 45 demo=0
42 drop=0 46 drop=0
47 adminpw=`genpw 15`
48 servicepw=`genpw 15`
43 49
44 # Parse options: 50 # Parse options:
45 51
46 OPTS=`getopt \ 52 OPTS=`getopt \
47 -l help,demo,db:,port:,drop \ 53 -l help,demo,db:,port:,drop,adminpw:,servicepw: \
48 -o Dd:p: -n "$ME" -- "$@"` 54 -o Dd:p: -n "$ME" -- "$@"`
49 [ $? -eq 0 ] || { usage ; exit 1 ; } 55 [ $? -eq 0 ] || { usage ; exit 1 ; }
50 56
51 eval set -- "$OPTS" 57 eval set -- "$OPTS"
52 58
56 db="$2" 62 db="$2"
57 shift 2 63 shift 2
58 ;; 64 ;;
59 --port|-p) 65 --port|-p)
60 port="$2" 66 port="$2"
67 shift 2
68 ;;
69 --adminpw)
70 adminpw="$2"
71 shift 2
72 ;;
73 --servicepw)
74 servicepw="$2"
61 shift 2 75 shift 2
62 ;; 76 ;;
63 --demo|-D) 77 --demo|-D)
64 demo=1 78 demo=1
65 shift 1 79 shift 1
96 psql -q -p "$port" -f "$BASEDIR/demo-data/responsibility_areas.sql" \ 110 psql -q -p "$port" -f "$BASEDIR/demo-data/responsibility_areas.sql" \
97 -d "$db" 111 -d "$db"
98 psql -q -p "$port" -f "$BASEDIR/demo-data/roles.sql" \ 112 psql -q -p "$port" -f "$BASEDIR/demo-data/roles.sql" \
99 -f "$BASEDIR/demo-data/users.sql" -d "$db" 113 -f "$BASEDIR/demo-data/users.sql" -d "$db"
100 fi 114 fi
101 115 # set passwords:
102 # Generate and set Passwords
103 adminpw=`genpw 15`
104 servicepw=`genpw 15`
105
106 psql -qt -p "$port" -d "$db" \ 116 psql -qt -p "$port" -d "$db" \
107 -c "ALTER ROLE sysadmin PASSWORD '$adminpw'" 117 -c "ALTER ROLE sysadmin PASSWORD '$adminpw'"
108 psql -qt -p "$port" -d "$db" \ 118 psql -qt -p "$port" -d "$db" \
109 -c "ALTER ROLE gemma_service PASSWORD '$servicepw'" 119 -c "ALTER ROLE gemma_service PASSWORD '$servicepw'"
110 echo "Default admin user 'sysadmin' created with password '$adminpw'." 120 echo "Default admin user 'sysadmin' created with password '$adminpw'."