| 1 | #!/bin/bash -ex |
| 2 | |
| 3 | # DO NOT EXECUTE DIRECTLY |
| 4 | # This is only to be executed by create-user |
| 5 | |
| 6 | USER=$1 |
| 7 | # (If it's not clear, for user fred, PATHBITS = f/fr/fred) |
| 8 | PATHBITS=`echo $USER | head -c 1`/`echo $USER | head -c 2`/$USER |
| 9 | DBPATH=/srv/databases/$PATHBITS |
| 10 | PGDIR=$DBPATH/postgres |
| 11 | PGNEWDIR="$DBPATH/postgres-9" |
| 12 | MYSQLDIR=$DBPATH/mysql |
| 13 | |
| 14 | # Create postgres user and tablespace placeholder within volume |
| 15 | # FIXME: This assumes the status-quo of database accounts not being |
| 16 | # removed by destroy-user... |
| 17 | if ! test -d $PGNEWDIR; then |
| 18 | # postgres 9.1 |
| 19 | mkdir -p $PGNEWDIR |
| 20 | chown postgres:postgres $PGNEWDIR |
| 21 | chmod 700 $PGNEWDIR |
| 22 | sudo -u postgres psql --cluster 9.1/main -c "CREATE TABLESPACE \"user_$USER\" OWNER postgres LOCATION '$PGNEWDIR'" template1 |
| 23 | fi |
| 24 | |
| 25 | # Create mysql user and databases placeholder within volume |
| 26 | # FIXME: Same as postgres... |
| 27 | if ! test -d $MYSQLDIR; then |
| 28 | mkdir -p $MYSQLDIR |
| 29 | chmod 700 $MYSQLDIR |
| 30 | chown mysql:mysql $MYSQLDIR |
| 31 | fi |