X-Git-Url: https://git.hcoop.net/hcoop/domtool2.git/blobdiff_plain/d541c6185fb0f426dce0b16e85327b53635169e0..599a99d3b90eb0ba81ba09cca4d69fff45f6eae6:/src/plugins/domtool-postgres diff --git a/src/plugins/domtool-postgres b/src/plugins/domtool-postgres index 276637f..45d7735 100755 --- a/src/plugins/domtool-postgres +++ b/src/plugins/domtool-postgres @@ -1,13 +1,37 @@ #!/bin/sh -e +export PGPORT="$2" + case $1 in adduser) - echo "I would create PostgreSQL user $2." + USERNAME=$3 + + sudo -u postgres psql -h postgres -p $PGPORT -c "CREATE USER $USERNAME" template1 + sudo -u postgres psql -h postgres -p $PGPORT -c "ALTER TABLESPACE user_$USERNAME OWNER TO $USERNAME" ;; + createdb) - echo "I would create PostgreSQL table $2_$3 for user $2." + 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 -p $PGPORT -O $USERNAME -D user_$USERNAME $ENCODING $DBNAME ;; + + dropdb) + USERNAME=$3 + DBNAME_BASE=$4 + DBNAME="${USERNAME}_${DBNAME_BASE}" + + sudo -u postgres dropdb -h postgres -p $PGPORT $DBNAME + ;; + *) - echo "Usage: domtool-postgres [adduser | createdb ]" + echo "Usage: domtool-postgres [adduser | createdb | dropdb ]" ;; esac