+####################
+# borrowed from postgresql
+function debian_get_postgresql_versions () {
+ versions=()
+ for v in `ls /usr/lib/postgresql/ 2>/dev/null`; do
+ if [ -x /usr/lib/postgresql/$v/bin/pg_ctl ] && [ ! -x /etc/init.d/postgresql-$v ]; then
+ versions+=($v)
+ fi
+ done
+ if [[ ${#versions[*]} == "0" ]]; then
+ echo "E: Missing postgresql installation. Aborting."
+ exit
+ fi
+ if [[ ${#versions[*]} != "1" ]]; then
+ echo "E: Too many postgresql versions installed. Aborting."
+ exit
+ fi
+ pgver=${versions[0]}
+}
+
+####################
+if [ -f /etc/redhat-release ] ; then
+ # source function library
+ . /etc/init.d/functions
+ PGDATA=/var/lib/pgsql/data/
+ PGWATCH=postmaster
+ PGLOCK=/var/lock/subsys/postgresql
+ SFALOCK=/var/lock/subsys/sfa-start.pid
+elif [ -f /etc/debian_version ] ; then
+ . /etc/init.d/functions.sfa
+ debian_get_postgresql_versions
+ PGDATA=/etc/postgresql/$pgver/main/
+ PGWATCH=postgres
+ PGLOCK=/var/run/postgresql/$pgver-main.pid
+ SFALOCK=/var/run/sfa-start.pid
+else
+ echo "initscript can only handle redhat/fedora or debian/ubuntu systems"
+ exit 1
+fi
+