#!/bin/bash -ex # DO NOT EXECUTE DIRECTLY # This is only to be executed by create-user USER=$1 # (If it's not clear, for user fred, PATHBITS = f/fr/fred) PATHBITS=`echo $USER | head -c 1`/`echo $USER | head -c 2`/$USER DBPATH=/srv/databases/$PATHBITS PGDIR=$DBPATH/postgres PGNEWDIR="$DBPATH/postgres-9" MYSQLDIR=$DBPATH/mysql # Create postgres user and tablespace placeholder within volume # FIXME: This assumes the status-quo of database accounts not being # removed by destroy-user... if ! test -d $PGNEWDIR; then # postgres 9.1 mkdir -p $PGNEWDIR chown postgres:postgres $PGNEWDIR chmod 700 $PGNEWDIR sudo -u postgres psql --cluster 9.1/main -c "CREATE TABLESPACE \"user_$USER\" OWNER postgres LOCATION '$PGNEWDIR'" template1 fi # Create mysql user and databases placeholder within volume # FIXME: Same as postgres... if ! test -d $MYSQLDIR; then mkdir -p $MYSQLDIR chmod 700 $MYSQLDIR chown mysql:mysql $MYSQLDIR fi