# -*- mode: shell-script -*- include pretty export DB_NAME="postgres" export DB_DATADIR=/var/lib/postgresql/data export DB_PASSFILE=/root/.pgpass is_db_locked() { require lsof || apt-get install -y lsof /dev/null 2>&1 } db_create_user() { local user="$1" password="$2" ## Using this instead of pipes is important so that trap works ddb < <(echo "CREATE USER $user WITH PASSWORD '$password' CREATEDB NOCREATEROLE;") } db_change_password() { local user="$1" password="$2" ## Using this instead of pipes is important so that trap works ddb < <(echo "ALTER USER $user WITH PASSWORD '$password';") } db_grant_rights () { local dbname="$1" user="$2" require psql || apt-get install -y postgresql-client