#!/bin/bash # sudo su postgres # postgresql://$USER:$PW@localhost/$DB INIFILE=$1 getter () { grep $1 $INIFILE | sed "s/^.*= //" } USER=$(getter "DB_USER") NAME=$(getter "DB_NAME") PASS=$(getter "DB_PASS") HOST=$(getter "DB_HOST") PORT=$(getter "DB_PORT") psql -c "CREATE USER \"${USER}\"" psql -c "ALTER USER \"${USER}\" with PASSWORD '${PW}'" psql -c "DROP DATABASE IF EXISTS \"${NAME}\"" createdb "${NAME}" psql "${NAME}" < extensions.sql # if new psql "${NAME}" < schema.sql psql ${NAME} < $2 psql -c "ALTER DATABASE \"${NAME}\" OWNER to \"${USER}\""