freeze: use rmdom and revoke instead of rmuser
[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
d0d39404 11PGNEWDIR="$DBPATH/postgres-9"
82cda9f8
CE
12MYSQLDIR=$DBPATH/mysql
13
14# Create postgres user and tablespace placeholder within volume
658c76a0 15# FIXME: This assumes the status-quo of database accounts not being
16# removed by destroy-user...
2735eb24 17if ! test -d $PGNEWDIR; then
18# postgres 9.1
19 mkdir -p $PGNEWDIR
20 chown postgres:postgres $PGNEWDIR
d0d39404 21 chmod 700 $PGNEWDIR
2735eb24 22 sudo -u postgres psql --cluster 9.1/main -c "CREATE TABLESPACE \"user_$USER\" OWNER postgres LOCATION '$PGNEWDIR'" template1
82cda9f8
CE
23fi
24
82cda9f8 25# Create mysql user and databases placeholder within volume
658c76a0 26# FIXME: Same as postgres...
27if ! test -d $MYSQLDIR; then
28 mkdir -p $MYSQLDIR
d0d39404 29 chmod 700 $MYSQLDIR
658c76a0 30 chown mysql:mysql $MYSQLDIR
d0d39404 31fi