setup.postgresql (1116B)
1 #!/bin/bash 2 #BLURB="PostgreSQL @PG_VERSION@" 3 4 PG_HOME=/var/lib/pgsql 5 PG_USER=postgres 6 PG_USER_ID=@UID@ 7 PG_GROUP=postgres 8 PG_GROUP_ID=@GID@ 9 PG_VERSION=@PG_VERSION@ 10 11 echo "Adding PostgreSQL user and group..." 12 groupadd -g $PG_GROUP_ID $PG_GROUP 13 useradd -g $PG_GROUP -u $PG_USER_ID -d $PG_HOME -c PostgreSQL $PG_USER 14 mkdir -p $PG_HOME/$PG_VERSION/data 15 16 ## default permissions 17 echo "Setting up permissions..." 18 chown -R $PG_USER:$PG_GROUP $PG_HOME 19 chmod 700 $PG_HOME 20 chmod 700 $PG_HOME/$PG_VERSION 21 chmod 700 $PG_HOME/$PG_VERSION/data 22 23 ## database cluster 24 if [ ! -f $PG_HOME/$PG_VERSION/data/PG_VERSION ]; then 25 echo "Creating database cluster in $PG_HOME/$PG_VERSION/data..." 26 su $PG_USER -c "initdb -D $PG_HOME/$PG_VERSION/data --locale=en_US.UTF-8 -A md5 -W" 27 else 28 echo "*** WARNING ***" >&2 29 echo " There is already a database cluster in $PG_HOME/$PG_VERSION/data." >&2 30 echo " If you are upgrading from an older version of PostgreSQL" >&2 31 echo " you will have to 'dump' and 'restore' your database." >&2 32 echo " See PostgreSQL manual for more details." >&2 33 fi 34 35 echo "PostgreSQL post-installation setup completed"