Escape tablespace name when creating postgresql tablespace
[hcoop/scripts.git] / create-user-database
old mode 100644 (file)
new mode 100755 (executable)
index 4725bd8..bc2ca60
@@ -3,20 +3,25 @@
 # DO NOT EXECUTE DIRECTLY
 # This is only to be executed by create-user
 
-PATHBITS=$1
+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
 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 $PGDIR; then
   mkdir -p $PGDIR
   chown postgres:postgres $PGDIR
-fi
-
-sudo -u postgres psql -c "CREATE TABLESPACE user_$USER OWNER postgres LOCATION '$PGDIR'" template1
+  sudo -u postgres psql -c "CREATE TABLESPACE \"user_$USER\" OWNER postgres LOCATION '$PGDIR'" template1
 fi
 
 # Create mysql user and databases placeholder within volume
-mkdir -p $MYSQLDIR
-chown mysql:mysql $MYSQLDIR
\ No newline at end of file
+# FIXME: Same as postgres...
+if ! test -d $MYSQLDIR; then
+    mkdir -p $MYSQLDIR
+    chown mysql:mysql $MYSQLDIR
+fi
\ No newline at end of file