#!/bin/sh

set -e

if [ "$1" ]; then
	psql -f /usr/share/postgresql-$1-plsh/createlang_pgplsh.sql
	psql -c 'CREATE FUNCTION hello(text) RETURNS text LANGUAGE plsh AS $$#!/bin/sh
echo "Hello $1" $$'
	str=$(psql -Atc "SELECT hello('world')")
	echo "$str"
	[ "$str" = "Hello world" ]

	exit 0
fi

unset TMPDIR

for version in $(pg_buildext supported-versions); do
	pg_virtualenv -v $version $0 $version
done
