Create database tablespace stubs on fritz
[hcoop/scripts.git] / create-user-database
diff --git a/create-user-database b/create-user-database
new file mode 100644 (file)
index 0000000..4725bd8
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/bash -ex
+
+# DO NOT EXECUTE DIRECTLY
+# This is only to be executed by create-user
+
+PATHBITS=$1
+DBPATH=/srv/databases/$PATHBITS
+PGDIR=$DBPATH/postgres
+MYSQLDIR=$DBPATH/mysql
+
+# Create postgres user and tablespace placeholder within volume
+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
+fi
+
+# Create mysql user and databases placeholder within volume
+mkdir -p $MYSQLDIR
+chown mysql:mysql $MYSQLDIR
\ No newline at end of file