X-Git-Url: https://git.hcoop.net/hcoop/domtool2.git/blobdiff_plain/4cbaa5a74c199730a4601e3eff8a7512dda20165..a92add469211c33a0820839dae449853cd427b66:/src/plugins/domtool-postgres diff --git a/src/plugins/domtool-postgres b/src/plugins/domtool-postgres dissimilarity index 85% index 4f85765..03320d0 100755 --- a/src/plugins/domtool-postgres +++ b/src/plugins/domtool-postgres @@ -1,40 +1,37 @@ -#!/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 system:postgres l - fs setacl -dir /afs/hcoop.net/common/databases/$USERNAME -acl system:mysql 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 system:postgres write - 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 | createdb ]" - ;; -esac +#!/bin/sh -e + +export PGPORT="$2" + +case $1 in + adduser) + USERNAME=$3 + + sudo -u postgres psql -h postgres -c "CREATE USER $USERNAME" template1 + sudo -u postgres psql -h postgres -c "ALTER TABLESPACE user_$USERNAME OWNER TO $USERNAME" + ;; + + createdb) + USERNAME=$3 + DBNAME_BASE=$4 + ENCODING=$5 + DBNAME="${USERNAME}_${DBNAME_BASE}" + + if [ -n "$ENCODING" ]; then + ENCODING="-E $ENCODING" + fi + + sudo -u postgres createdb -h postgres -O $USERNAME -D user_$USERNAME $ENCODING $DBNAME + ;; + + dropdb) + USERNAME=$3 + DBNAME_BASE=$4 + DBNAME="${USERNAME}_${DBNAME_BASE}" + + sudo -u postgres dropdb -h postgres $DBNAME + ;; + + *) + echo "Usage: domtool-postgres [adduser | createdb | dropdb ]" + ;; +esac