create-databases-users.sh 525 Bytes
#!/bin/bash

set -ex

mode=
touch /tmp/pgpass
chmod 0600 /tmp/pgpass
echo "*:*:*:*:CHANGEME" > /tmp/pgpass
export PGPASSFILE=/tmp/pgpass

while [[ $# -gt 0 ]]; do
	case "$1" in
		(--databases)
			mode="databases"
			;;
		(--users)
			mode="users"
			;;
		(--*)
			echo "Unknown mode: $1" 1>&2
			exit 1
			;;
		(*)
			case "$mode" in
				(databases)
					createdb -w -h ${POSTGRESQL_HOST} -U postgres "$1"
					;;
				(users)
					createuser -w -h ${POSTGRESQL_HOST} -U postgres "$1"
					;;
			esac
			;;
	esac
	shift
done