#!/bin/sh -x
. /etc/dinit.d/config/postgres.conf
install -d -o postgres -g postgres /run/postgresql
if [ "$PGROOT" != /var/lib/postgres ]; then
    ! [ -L /var/lib/postgres ] && [ -d /var/lib/postgres ] && rmdir /var/lib/postgres
    ln -sf $PGROOT /var/lib/postgres
fi

if [ ! -d "$PGDATA" ]; then
    mkdir -p "$PGDATA"
    chown -R postgres:postgres "$PGDATA"
    chmod 0700 "$PGDATA"
fi
