--- a/test/pgpool_setup
+++ b/test/pgpool_setup
@@ -1,4 +1,6 @@
 #! /bin/sh
+set -x
+#set -e
 # Copyright (c) 2013-2014 PgPool Global Development Group
 #
 # Permission to use, copy, modify, and distribute this software and
@@ -57,6 +59,13 @@ NUMCLUSTERS=2
 # Where to look for pgpool.conf.sample*
 PGPOOL_INSTALL_DIR=${PGPOOL_INSTALL_DIR:-"/usr/local"}
 PGPOOLDIR=$PGPOOL_INSTALL_DIR/etc
+# Debian: look for etc files in .../etc/pgpool2
+[ -d "$PGPOOLDIR/pgpool2" ] && PGPOOLDIR="$PGPOOLDIR/pgpool2"
+SAMPLECONFDIR="$PGPOOLDIR"
+# Debian: look for .conf.sample in /usr/share
+[ -d "/usr/share/doc/pgpool2/examples" ] && SAMPLECONFDIR="/usr/share/doc/pgpool2/examples"
+# Debian: look for binaries in .../usr/bin
+[ -d "$PGPOOL_INSTALL_DIR/usr" ] && PGPOOL_INSTALL_DIR="$PGPOOL_INSTALL_DIR/usr"
 # PostgreSQL commands(initdb, pg_ctl, psql) install dir
 PGBIN=${PGBIN:-"/usr/local/pgsql/bin"}
 # LD_LIBRARY_PATH 
@@ -100,6 +109,7 @@ function create_failover_script()
 {
 cat >> $FAILOVER_SCRIPT <<'EOF'
 #! /bin/sh
+set -ex
 # Execute command by failover.
 # special values:  %d = node id
 #                  %h = host name
@@ -162,6 +172,7 @@ function create_follow_master_script()
 {
 cat >> $FOLLOW_MASTER_SCRIPT <<'EOF'
 #! /bin/sh
+set -ex
 # Execute command by failover.
 # special values:  %d = node id
 #                  %h = host name
@@ -227,6 +238,7 @@ function create_pgpool_remote_start_scri
 {
 cat >> $1/$PGPOOL_REMOTE_START_SCRIPT <<'EOF'
 #! /bin/sh
+set -ex
 #
 # start postmaster on the recoveried node
 #
@@ -303,6 +315,7 @@ function create_basebackup_stream {
 SCRIPT=basebackup.sh
 cat >> $1/$SCRIPT <<'EOF'
 #! /bin/sh
+set -ex
 psql=__PGBIN__/psql
 DATA0_PORT=__DATA0_PORT__
 DATA1_PORT=`expr $DATA0_PORT + 1`
@@ -377,6 +390,7 @@ function create_basebackup_replication {
 SCRIPT=basebackup.sh
 cat >> $1/$SCRIPT <<'EOF'
 #! /bin/sh
+set -ex
 psql=__PGBIN__/psql
 DATA0_PORT=__DATA0_PORT__
 DATA1_PORT=`expr $DATA0_PORT + 1`
@@ -450,6 +464,7 @@ function create_pgpool_recovery_pitr {
 SCRIPT=pgpool_recovery_pitr
 cat >> $1/$SCRIPT <<'EOF'
 #! /bin/sh
+set -ex
 psql=__PGBIN__/psql
 DATA0_PORT=__DATA0_PORT__
 DATA1_PORT=`expr $DATA0_PORT + 1`
@@ -634,13 +649,13 @@ done
 
 case $MODE in
 	r) MODENAME="native replication mode"
-		SAMPLE_CONF=$PGPOOLDIR/pgpool.conf.sample-replication
+		SAMPLE_CONF=$SAMPLECONFDIR/pgpool.conf.sample-replication
 		;;
 	s ) MODENAME="streaming replication mode"
-		SAMPLE_CONF=$PGPOOLDIR/pgpool.conf.sample-stream
+		SAMPLE_CONF=$SAMPLECONFDIR/pgpool.conf.sample-stream
 		;;
 	n ) MODENAME="raw mode"
-		SAMPLE_CONF=$PGPOOLDIR/pgpool.conf.sample
+		SAMPLE_CONF=$SAMPLECONFDIR/pgpool.conf.sample
 		;;
 esac
 
@@ -658,13 +673,17 @@ exec 5> $BASEDIR/pgpool_setup.log
 #-------------------------------------------
 # everything looks good. starting setup...
 #-------------------------------------------
-echo "Satrting set up in $MODENAME"
+echo "Starting set up in $MODENAME"
 
 #-------------------------------------------
 # install pgpool.conf
 #-------------------------------------------
 test ! -d etc && mkdir etc
-cp $SAMPLE_CONF $CONF
+if [ -f $SAMPLE_CONF.gz ]; then
+	zcat $SAMPLE_CONF.gz > $CONF
+else
+	cp $SAMPLE_CONF $CONF
+fi
 
 #-------------------------------------------
 # create startall, shutdownall and pgpool_reload
@@ -728,7 +747,7 @@ do
 	fi
 
 	echo "$PG_CTL -D $CLUSTERDIR -m f stop" >> $SHUTDOWNALL
-	echo "$PG_CTL -w -D $CLUSTERDIR start" >> $STARTALL
+	echo "$PG_CTL -w -o -k/tmp -D $CLUSTERDIR start" >> $STARTALL
 
 	n=`expr $n + 1`
 
@@ -740,8 +759,10 @@ set_pgpool_conf $CONF
 
 PGPOOL_PORT=`expr $PORT + 1`
 echo "port = $PGPOOL_PORT" >> $CONF
+echo "socket_dir = '/tmp'" >> $CONF
 PCP_PORT=`expr $PORT + 2`
 echo "pcp_port = $PCP_PORT" >> $CONF
+echo "pcp_socket_dir = '/tmp'" >> $CONF
 
 test ! -d run && mkdir run
 echo "pid_file_name = '$BASEDIR/run/pgpool.pid'" >> $CONF
@@ -751,7 +772,7 @@ echo "logdir = '$BASEDIR/log'" >> $CONF
 echo '$PGPOOL_INSTALL_DIR/bin/pgpool -D -n -f $dir/etc/pgpool.conf -F $dir/etc/pcp.conf -a $dir/etc/pool_hba.conf > $dir/log/pgpool.log 2>&1 &' >> $STARTALL
 
 # create pcp.conf
-cp $PGPOOLDIR/pcp.conf.sample etc/pcp.conf
+cp $PGPOOLDIR/pcp.conf etc/pcp.conf
 echo -n "${WHOAMI}:" >> etc/pcp.conf
 $PGPOOL_INSTALL_DIR/bin/pg_md5 $WHOAMI >> etc/pcp.conf
 
@@ -769,7 +790,7 @@ mkdir archivedir
 if [ $MODE = 's' ];then
 # temporarily start data0 cluster to create extensions
 	echo "temporarily start data0 cluster to create extensions"
-	$PG_CTL -w -D data0 start >&5 2>&1
+	$PG_CTL -w -o -k/tmp -D data0 start >&5 2>&1
 	$PSQL -p $BASEPORT template1 >&5 2>&1 <<EOF
 CREATE EXTENSION pgpool_regclass;
 CREATE EXTENSION pgpool_recovery;
@@ -780,7 +801,7 @@ EOF
 	PORT=$BASEPORT
 	CLUSTER="data"`expr $n`
 	CLUSTERDIR=$BASEDIR/$CLUSTER
-	echo "backend_hostname$n = ''" >> $CONF
+	echo "backend_hostname$n = '/tmp'" >> $CONF
 	echo "backend_port$n = $PORT" >> $CONF
 	echo "backend_weight$n = 1" >> $CONF
 	echo "backend_data_directory$n = '$CLUSTERDIR'" >> $CONF
@@ -797,7 +818,7 @@ EOF
 		do
 		# set up pgpool.conf
 			PORT=`expr $PORT + 1`
-			echo "backend_hostname$n = ''" >> $CONF
+			echo "backend_hostname$n = '/tmp'" >> $CONF
 			echo "backend_port$n = $PORT" >> $CONF
 			echo "backend_weight$n = 1" >> $CONF
 			CLUSTER="data"`expr $n`
@@ -837,7 +858,7 @@ else
 	while [ $n -lt $NUMCLUSTERS ]
 	do
 	# set up pgpool.conf
-		echo "backend_hostname$n = ''" >> $CONF
+		echo "backend_hostname$n = '/tmp'" >> $CONF
 		echo "backend_port$n = $PORT" >> $CONF
 		echo "backend_weight$n = 1" >> $CONF
 		CLUSTER="data"`expr $n`
--- a/test/regression/regress.sh
+++ b/test/regression/regress.sh
@@ -16,6 +16,8 @@ log=$dir/log
 fail=0
 ok=0
 
+export PGHOST=/tmp
+
 CRED=$(tput setaf 1)
 CGREEN=$(tput setaf 2)
 CBLUE=$(tput setaf 4)
@@ -42,6 +44,7 @@ function verify_pginstallation
 		echo "$0: cannot locate pg_config"
 		exit 1
 	fi
+	export PGPOOL_SETUP=$dir/../pgpool_setup
 }
 
 function export_env_vars
@@ -120,8 +123,8 @@ if [ "$MODE" = "install" ]; then
 
 elif [ "$MODE" = "noinstall" ]; then
 	echo not installing pgpool for the tests ...
-	if [[ -n "$PGPOOL_INSTALL_PATH" ]]; then
-		PGPOOL_PATH=$PGPOOL_INSTALL_PATH
+	if [[ -n "$PGPOOL_INSTALL_DIR" ]]; then
+		PGPOOL_PATH=$PGPOOL_INSTALL_DIR
 	fi
 else
 	echo $MODE : Invalid mode
--- a/test/regression/tests/001.load_balance/test.sh
+++ b/test/regression/tests/001.load_balance/test.sh
@@ -1,4 +1,4 @@
-#! /bin/sh -x
+#! /bin/bash -x
 #-------------------------------------------------------------------
 # test script for load balancing.
 #
@@ -14,7 +14,7 @@ do
 
 # create test environment
 	echo -n "creating test environment..."
-	sh $PGPOOL_SETUP -m $mode -n 2 || exit 1
+	bash $PGPOOL_SETUP -m $mode -n 2 || exit 1
 	echo "done."
 
 	source ./bashrc.ports
--- a/test/regression/tests/002.native_replication/test.sh
+++ b/test/regression/tests/002.native_replication/test.sh
@@ -1,4 +1,4 @@
-#! /bin/sh -x
+#! /bin/bash -x
 #-------------------------------------------------------------------
 # test script for native replication mode.
 #
@@ -13,7 +13,7 @@ cd $TESTDIR
 
 # create test environment
 echo -n "creating test environment..."
-sh $PGPOOL_SETUP -m r -n 2 || exit 1
+bash $PGPOOL_SETUP -m r -n 2 || exit 1
 echo "done."
 
 source ./bashrc.ports
--- a/test/regression/tests/003.failover/test.sh
+++ b/test/regression/tests/003.failover/test.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#! /bin/bash
 #-------------------------------------------------------------------
 # test script for failover
 #
@@ -15,7 +15,7 @@ do
 
 # create test environment
 	echo -n "creating test environment..."
-	sh $PGPOOL_SETUP -m $mode -n 2 --no-stop|| exit 1
+	bash $PGPOOL_SETUP -m $mode -n 2 --no-stop|| exit 1
 	echo "done."
 
 	source ./bashrc.ports
--- a/test/regression/tests/004.watchdog/test.sh
+++ b/test/regression/tests/004.watchdog/test.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#! /bin/bash
 #-------------------------------------------------------------------
 # test script for watchdog
 source $TESTLIBS
@@ -10,7 +10,7 @@ cd $TESTDIR
 
 # create master environment
 echo -n "creating master pgpool..."
-sh $PGPOOL_SETUP -m s -n 2 -p 11000|| exit 1
+bash $PGPOOL_SETUP -m s -n 2 -p 11000|| exit 1
 echo "done."
 cat ../master.conf >> etc/pgpool.conf
 
@@ -25,7 +25,7 @@ rm -fr $sdir
 mkdir $sdir
 cd $sdir
 echo -n "creating standby pgpool..."
-sh $PGPOOL_SETUP -m s -n 2 -p 11100|| exit 1
+bash $PGPOOL_SETUP -m s -n 2 -p 11100|| exit 1
 echo "done."
 cat ../standby.conf >> etc/pgpool.conf
 egrep 'backend_data_directory0|backend_data_directory1|failover_command|follow_master_command' ../$TESTDIR/etc/pgpool.conf >> etc/pgpool.conf
--- a/test/regression/tests/050.bug58/test.sh
+++ b/test/regression/tests/050.bug58/test.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#! /bin/bash
 #-------------------------------------------------------------------
 # test script for bug#58
 # 0000058: query cache invalidation does not fire for multiple DML in transaction
@@ -13,7 +13,7 @@ cd $TESTDIR
 
 # create test environment
 echo -n "creating test environment..."
-sh $PGPOOL_SETUP -m s -n 1 --no-stop|| exit 1
+bash $PGPOOL_SETUP -m s -n 1 --no-stop|| exit 1
 echo "done."
 
 source ./bashrc.ports
--- a/test/regression/tests/051.bug60/test.sh
+++ b/test/regression/tests/051.bug60/test.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#! /bin/bash
 #-------------------------------------------------------------------
 # test script for bug reported in bug track #60
 # The bug occurs when all of conditions below are met:
@@ -26,7 +26,7 @@ cd $TESTDIR
 
 # create test environment
 echo -n "creating test environment..."
-sh $PGPOOL_SETUP -m s -n 2 --no-stop || exit 1
+bash $PGPOOL_SETUP -m s -n 2 --no-stop || exit 1
 echo "done."
 
 source ./bashrc.ports
--- a/test/regression/tests/052.do_query/test.sh
+++ b/test/regression/tests/052.do_query/test.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#! /bin/bash
 #-------------------------------------------------------------------
 # test script for do_query.
 #
@@ -17,7 +17,7 @@ cd $TESTDIR
 
 # create test environment
 echo -n "creating test environment..."
-sh $PGPOOL_SETUP -m s -n 1 --no-stop|| exit 1
+bash $PGPOOL_SETUP -m s -n 1 --no-stop|| exit 1
 echo "done."
 
 source ./bashrc.ports
--- a/test/regression/tests/053.insert_lock_hangs/test.sh
+++ b/test/regression/tests/053.insert_lock_hangs/test.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#! /bin/bash
 #-------------------------------------------------------------------
 # test script for bug reported in [pgpool-general: 1684].
 # The bug occurs when all of conditions below are met:
@@ -20,7 +20,7 @@ cd $TESTDIR
 
 # create test environment
 echo -n "creating test environment..."
-sh $PGPOOL_SETUP -m r -n 1 --no-stop|| exit 1
+bash $PGPOOL_SETUP -m r -n 1 --no-stop|| exit 1
 echo "done."
 
 source ./bashrc.ports
--- a/test/regression/tests/054.postgres_fdw/test.sh
+++ b/test/regression/tests/054.postgres_fdw/test.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#! /bin/bash
 #-------------------------------------------------------------------
 # Check to see if postgres_fdw works with pgpool-II.  Since
 # postres_fdw sets search_path to pg_catalog, pgpool_regclass() should
@@ -19,7 +19,7 @@ cd $TESTDIR
 
 # create test environment
 echo -n "creating test environment..."
-sh $PGPOOL_SETUP -m r -n 2 --no-stop|| exit 1
+bash $PGPOOL_SETUP -m r -n 2 --no-stop|| exit 1
 echo "done."
 
 source ./bashrc.ports
--- a/test/regression/tests/055.backend_all_down/test.sh
+++ b/test/regression/tests/055.backend_all_down/test.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#! /bin/bash
 #-------------------------------------------------------------------
 # "pgpool -m f stop" hangs because unmanaged pgpool children remains. 
 # Starting pgpool without starting PostgreSQL servers triggers the bug.
@@ -14,7 +14,7 @@ cd $TESTDIR
 
 # create test environment
 echo -n "creating test environment..."
-sh $PGPOOL_SETUP -m s -n 2 || exit 1
+bash $PGPOOL_SETUP -m s -n 2 || exit 1
 echo "done."
 
 source ./bashrc.ports
@@ -27,7 +27,7 @@ grep pgpool.conf startall >> pgpool.sh
 
 # start pgpool only. This causes immediate failover and may leave
 # orphan pgpool children.
-sh pgpool.sh
+bash pgpool.sh
 
 while true
 do
@@ -49,4 +49,4 @@ if [ $? = 0 ];then
 fi
 
 ./shutdownall
-exit 0
\ No newline at end of file
+exit 0
--- a/test/regression/tests/056.bug63/test.sh
+++ b/test/regression/tests/056.bug63/test.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#! /bin/bash
 #-------------------------------------------------------------------
 # test script for bug#63
 # On memory query cache occasionally segfaults.
@@ -18,7 +18,7 @@ cd $TESTDIR
 
 # create test environment
 echo -n "creating test environment..."
-sh $PGPOOL_SETUP -m s -n 1 || exit 1
+bash $PGPOOL_SETUP -m s -n 1 || exit 1
 echo "done."
 
 source ./bashrc.ports
--- a/test/regression/tests/057.bug61/test.sh
+++ b/test/regression/tests/057.bug61/test.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#! /bin/bash
 #-------------------------------------------------------------------
 # test script for bug#61
 # Child process xxxx was terminated by segmentation fault
@@ -16,7 +16,7 @@ cd $TESTDIR
 
 # create test environment
 echo -n "creating test environment..."
-sh $PGPOOL_SETUP -m s -n 1 || exit 1
+bash $PGPOOL_SETUP -m s -n 1 || exit 1
 echo "done."
 
 source ./bashrc.ports
