5 kx #!/bin/bash
5 kx
5 kx PG_HOME=/var/lib/pgsql
5 kx PG_USER=postgres
5 kx PG_USER_ID=@UID@
5 kx PG_GROUP=postgres
5 kx PG_GROUP_ID=@GID@
5 kx PG_VERSION=@PG_VERSION@
5 kx
5 kx echo "Adding PostgreSQL user and group..."
5 kx groupadd -g $PG_GROUP_ID $PG_GROUP
5 kx useradd -g $PG_GROUP -u $PG_USER_ID -d $PG_HOME -c PostgreSQL $PG_USER
5 kx mkdir -p $PG_HOME/$PG_VERSION/data
5 kx
5 kx ## default permissions
5 kx echo "Setting up permissions..."
5 kx chown -R $PG_USER:$PG_GROUP $PG_HOME
5 kx chmod 700 $PG_HOME
5 kx chmod 700 $PG_HOME/$PG_VERSION
5 kx chmod 700 $PG_HOME/$PG_VERSION/data
5 kx
5 kx ## database cluster
5 kx if [ ! -f $PG_HOME/$PG_VERSION/data/PG_VERSION ]; then
5 kx echo "Creating database cluster in $PG_HOME/$PG_VERSION/data..."
5 kx su $PG_USER -c "initdb -D $PG_HOME/$PG_VERSION/data --locale=en_US.UTF-8 -A md5 -W"
5 kx else
5 kx echo "*** WARNING ***" >&2
5 kx echo " There is already a database cluster in $PG_HOME/$PG_VERSION/data." >&2
5 kx echo " If you are upgrading from an older version of PostgreSQL" >&2
5 kx echo " you will have to 'dump' and 'restore' your database." >&2
5 kx echo " See PostgreSQL manual for more details." >&2
5 kx fi
5 kx
5 kx echo "PostgreSQL post-installation setup completed"