Temporary workaround to `domtool-postgres' script
[hcoop/domtool2.git] / src / plugins / domtool-postgres
CommitLineData
d541c618
AC
1#!/bin/sh -e
2
3case $1 in
4 adduser)
53cb7cc1
AC
5 USERNAME=$2
6
fd59cbe6 7 sudo -u postgres psql -h postgres -c "CREATE USER $USERNAME" template1
8 sudo -u postgres psql -h postgres -c "ALTER TABLESPACE user_$USERNAME OWNER TO $USERNAME"
d541c618 9 ;;
5ad00add 10
d541c618 11 createdb)
a215ab4e
AC
12 USERNAME=$2
13 DBNAME_BASE=$3
fe789bea 14 ENCODING=$4
a215ab4e
AC
15 DBNAME="${USERNAME}_${DBNAME_BASE}"
16
16eaea74 17 if [ -n "$ENCODING" ]; then
fe789bea
AC
18 ENCODING="-E $ENCODING"
19 fi
20
fd59cbe6 21 sudo -u postgres createdb -h postgres -O $USERNAME -D user_$USERNAME $ENCODING $DBNAME
d541c618 22 ;;
5ad00add
AC
23
24 dropdb)
25 USERNAME=$2
26 DBNAME_BASE=$3
27 DBNAME="${USERNAME}_${DBNAME_BASE}"
28
fd59cbe6 29 sudo -u postgres dropdb -h postgres $DBNAME
5ad00add
AC
30 ;;
31
d541c618 32 *)
5ad00add 33 echo "Usage: domtool-postgres [adduser <user> | createdb <user> <db> | dropdb <user> <db>]"
d541c618
AC
34 ;;
35esac