config() {
  NEW="$1"
  OLD="`dirname $NEW`/`basename $NEW .new`"
  # If there's no config file by that name, mv it over:
  if [ ! -r $OLD ]; then
    mv $NEW $OLD
  elif [ "`cat $OLD | md5sum`" = "`cat $NEW | md5sum`" ]; then # toss the redundant
    rm $NEW
  fi
  # Otherwise, we leave the .new copy for the admin to consider...
}

config etc/rc.d/rc.postgresql.new



###
# Create postgres user:group if they don't exist.
###
group_exists=`grep ^postgres etc/group`
if [[ "${group_exists}" == "" ]]; then
	groupadd -g 209 postgres
fi
user_exists=`grep ^postgres etc/passwd`
if [[ "${user_exists}" == "" ]]; then
	useradd -c "PostgreSQL ORDBMS" -d /var/lib/pgsql -u 209 -g 209 -s "/bin/false" postgres
fi



( cd usr/bin ; rm -rf postmaster )
( cd usr/bin ; ln -sf postgres postmaster )
( cd usr/lib ; rm -rf libecpg_compat.so.3 )
( cd usr/lib ; ln -sf libecpg_compat.so.3.2 libecpg_compat.so.3 )
( cd usr/lib/postgresql ; rm -rf plpython.so )
( cd usr/lib/postgresql ; ln -sf plpython2.so plpython.so )
( cd usr/lib ; rm -rf libpq.so.5 )
( cd usr/lib ; ln -sf libpq.so.5.3 libpq.so.5 )
( cd usr/lib ; rm -rf libpgtypes.so )
( cd usr/lib ; ln -sf libpgtypes.so.3.1 libpgtypes.so )
( cd usr/lib ; rm -rf libecpg.so )
( cd usr/lib ; ln -sf libecpg.so.6.2 libecpg.so )
( cd usr/lib ; rm -rf libpq.so )
( cd usr/lib ; ln -sf libpq.so.5.3 libpq.so )
( cd usr/lib ; rm -rf libecpg_compat.so )
( cd usr/lib ; ln -sf libecpg_compat.so.3.2 libecpg_compat.so )
( cd usr/lib ; rm -rf libpgtypes.so.3 )
( cd usr/lib ; ln -sf libpgtypes.so.3.1 libpgtypes.so.3 )
( cd usr/lib ; rm -rf libecpg.so.6 )
( cd usr/lib ; ln -sf libecpg.so.6.2 libecpg.so.6 )
