2013-02-25 21:46:36 +01:00
|
|
|
#/bin/sh -xe
|
|
|
|
|
2013-05-22 20:11:47 +02:00
|
|
|
ROOT_POSTGRES="sudo -u postgres psql"
|
|
|
|
DEFAULT_DB=""
|
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
|
|
|
ROOT_POSTGRES="psql"
|
|
|
|
DEFAULT_DB="postgres"
|
|
|
|
fi
|
|
|
|
|
2013-05-08 05:30:42 +02:00
|
|
|
if [[ $# == 0 ]]; then
|
|
|
|
USERNAME=humbug
|
|
|
|
PASSWORD=xxxxxxxxxxxx
|
|
|
|
DBNAME=humbug
|
|
|
|
SEARCH_PATH="$USERNAME",public
|
|
|
|
elif [[ $# == 4 ]]; then
|
|
|
|
USERNAME=$1
|
|
|
|
PASSWORD=$2
|
|
|
|
DBNAME=$3
|
|
|
|
SEARCH_PATH=$4
|
|
|
|
else
|
|
|
|
echo "Usage Instructions"
|
|
|
|
echo "Run with either no arguments (sets up devel db for local deploy--humbug with user humbug)"
|
|
|
|
echo "or specify <db-username> <password> <db-name> <user-schema-search-path>"
|
|
|
|
exit
|
|
|
|
fi
|
2013-02-25 21:46:36 +01:00
|
|
|
|
2013-05-22 20:11:47 +02:00
|
|
|
|
|
|
|
$ROOT_POSTGRES $DEFAULT_DB << EOF
|
2013-05-08 05:30:42 +02:00
|
|
|
CREATE USER $USERNAME WITH PASSWORD '$PASSWORD';
|
|
|
|
ALTER USER $USERNAME CREATEDB;
|
|
|
|
ALTER ROLE $USERNAME SET search_path TO $SEARCH_PATH;
|
|
|
|
EOF
|
|
|
|
|
|
|
|
umask go-rw
|
|
|
|
echo "*:*:*:$USERNAME:$PASSWORD" >> ~/.pgpass
|
|
|
|
chmod go-rw ~/.pgpass
|
|
|
|
|
|
|
|
psql -h localhost postgres $USERNAME <<EOF
|
2013-05-22 20:11:47 +02:00
|
|
|
DROP DATABASE IF EXISTS $DBNAME;
|
2013-05-08 05:30:42 +02:00
|
|
|
CREATE DATABASE $DBNAME;
|
|
|
|
EOF
|
|
|
|
|
2013-05-22 20:11:47 +02:00
|
|
|
DEFAULT_DB=$DBNAME
|
|
|
|
|
|
|
|
$ROOT_POSTGRES $DEFAULT_DB << EOF
|
2013-02-25 21:46:36 +01:00
|
|
|
DROP SCHEMA public CASCADE;
|
|
|
|
EOF
|
|
|
|
|
|
|
|
echo "Database created"
|
|
|
|
|