Correct order of sudo in apache sync logs
[hcoop/scripts.git] / create-user-database
CommitLineData
82cda9f8
CE
1#!/bin/bash -ex
2
3# DO NOT EXECUTE DIRECTLY
4# This is only to be executed by create-user
5
58df4059
CE
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
82cda9f8
CE
9DBPATH=/srv/databases/$PATHBITS
10PGDIR=$DBPATH/postgres
11MYSQLDIR=$DBPATH/mysql
12
13# Create postgres user and tablespace placeholder within volume
658c76a0 14# FIXME: This assumes the status-quo of database accounts not being
15# removed by destroy-user...
82cda9f8
CE
16if ! test -d $PGDIR; then
17 mkdir -p $PGDIR
18 chown postgres:postgres $PGDIR
42255e0b 19 sudo -u postgres psql -c "CREATE TABLESPACE \"user_$USER\" OWNER postgres LOCATION '$PGDIR'" template1
82cda9f8
CE
20fi
21
82cda9f8 22# Create mysql user and databases placeholder within volume
658c76a0 23# FIXME: Same as postgres...
24if ! test -d $MYSQLDIR; then
25 mkdir -p $MYSQLDIR
26 chown mysql:mysql $MYSQLDIR
27fi