Specifying encoding on database creation
[hcoop/domtool2.git] / src / plugins / domtool-postgres
dissimilarity index 81%
index ded559d..214e9ac 100755 (executable)
@@ -1,40 +1,35 @@
-#!/bin/sh -e
-
-case $1 in
-       adduser)
-               USERNAME=$2
-               DIR=/afs/hcoop.net/common/databases/$USERNAME/postgres
-
-               kinit -k -t /etc/keytabs/root.admin.keytab root/admin
-               aklog
-
-               if ! vos examine db.$USERNAME >/dev/null 2>/dev/null; then
-                       vos create -server afs -partition a -name db.$USERNAME -maxquota 5000
-                       fs mkmount -dir /afs/.hcoop.net/common/.databases/$USERNAME -vol db.$USERNAME -rw
-                       vos release common.databases
-                       fs setacl -dir /afs/hcoop.net/common/databases/$USERNAME -acl databases l
-                       fs setacl -dir /afs/hcoop.net/common/databases/$USERNAME -acl system:backup rl
-               fi
-
-               if ! [ -d $DIR ]; then
-                       sudo -u postgres psql -c "CREATE USER $USERNAME" template1
-                       mkdir -p $DIR
-                       chown postgres:postgres $DIR
-                       fs setacl -dir $DIR -acl postgres write
-                       fs setacl -dir $DIR -acl databases none
-                       fs setacl -dir $DIR -acl system:backup rl
-
-                       sudo -u postgres psql -c "CREATE TABLESPACE user_$USERNAME OWNER $USERNAME LOCATION '$DIR'" template1
-               fi
-       ;;
-       createdb)
-               USERNAME=$2
-               DBNAME_BASE=$3
-               DBNAME="${USERNAME}_${DBNAME_BASE}"
-
-               sudo -u postgres createdb -O $USERNAME -D user_$USERNAME $DBNAME
-       ;;
-       *)
-               echo "Usage: domtool-postgres [adduser <user> | createdb <user> <table>]"
-       ;;
-esac
+#!/bin/sh -e
+
+case $1 in
+       adduser)
+               USERNAME=$2
+
+               sudo -u postgres psql -c "CREATE USER $USERNAME" template1
+               sudo -u postgres psql -c "ALTER TABLESPACE user_$USERNAME OWNER TO $USERNAME"
+       ;;
+
+       createdb)
+               USERNAME=$2
+               DBNAME_BASE=$3
+               ENCODING=$4
+               DBNAME="${USERNAME}_${DBNAME_BASE}"
+
+               if [ -n $ENCODING ]; then
+                   ENCODING="-E $ENCODING"
+               fi
+
+               sudo -u postgres createdb -O $USERNAME -D user_$USERNAME $ENCODING $DBNAME
+       ;;
+
+       dropdb)
+               USERNAME=$2
+               DBNAME_BASE=$3
+               DBNAME="${USERNAME}_${DBNAME_BASE}"
+
+               sudo -u postgres dropdb $DBNAME
+       ;;
+
+       *)
+               echo "Usage: domtool-postgres [adduser <user> | createdb <user> <db> | dropdb <user> <db>]"
+       ;;
+esac