You need domtool-admin rights to destroy a user
[clinton/scripts.git] / create-user-database
... / ...
CommitLineData
1#!/bin/bash -ex
2
3# DO NOT EXECUTE DIRECTLY
4# This is only to be executed by create-user
5
6USER=$1
7# (If it's not clear, for user fred, PATHBITS = f/fr/fred)
8PATHBITS=`echo $USER | head -c 1`/`echo $USER | head -c 2`/$USER
9DBPATH=/srv/databases/$PATHBITS
10PGDIR=$DBPATH/postgres
11MYSQLDIR=$DBPATH/mysql
12
13# Create postgres user and tablespace placeholder within volume
14if ! test -d $PGDIR; then
15 mkdir -p $PGDIR
16 chown postgres:postgres $PGDIR
17fi
18
19sudo -u postgres psql -c "CREATE TABLESPACE user_$USER OWNER postgres LOCATION '$PGDIR'" template1
20
21# Create mysql user and databases placeholder within volume
22mkdir -p $MYSQLDIR
23chown mysql:mysql $MYSQLDIR