#!/bin/bash

set -e

CLUSTERARG=""
CLUSTERSUFFIX=""

if [ "${1}"x = "--virtual"x ]; then
    if [ "${2}"x != "default"x ]; then
        CLUSTERSUFFIX=-"${2}"
    fi
    shift
    shift
fi

PROGRAM=pg_restore
for i in /usr/lib/postgresql/9.1/bin/pg_restore /usr/pgsql-9.1/bin/pg_restore /usr/lib/postgresql/9.0/bin/pg_restore /usr/pgsql-9.0/bin/pg_restore /usr/lib/postgresql/8.4/bin/pg_restore /usr/pgsql-8.4/bin/pg_restore /usr/lib/postgresql/8.3/bin/pg_restore /usr/pgsql-8.3/bin/pg_restore; do
    if [ -x $i ]; then
        PROGRAM=$i
        break
    fi
done

if [ -x /bin/nice ]; then
    NICE=/bin/nice
else 
    NICE=/usr/bin/nice
fi

$NICE $PROGRAM "$@"
