#!/bin/bash
set -e -x

mkdir -p /usr/local/pgsql/data
chown -R postgres /usr/local/pgsql

echo 'local all all trust' > /etc/postgresql/${PGVERSION}/main/pg_hba.conf
su postgres -c "/usr/lib/postgresql/${PGVERSION}/bin/initdb -E utf8"
su postgres -c "/usr/lib/postgresql/${PGVERSION}/bin/pg_ctl start"
sleep 10
su postgres -c 'createuser -s root'
su postgres -c 'createdb root -E utf8'

