#!/bin/sh
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
# 
# Filename: package/.../postgresql/postgresql.conf
# Copyright (C) 2006 - 2007 The OpenSDE Project
# Copyright (C) 2004 - 2006 The T2 SDE Project
# Copyright (C) 1998 - 2003 Clifford Wolf
# 
# More information can be found in the files COPYING and README.
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---

if [ $prefix_auto = 1 ] ; then
	if [ "$SDECFG_PKG_POSTGRESQL_PREFIX" ] ; then
		prefix="$SDECFG_PKG_POSTGRESQL_PREFIX"
	else
        	prefix="opt/postgresql"
	fi
        set_confopt
fi

# check if we should build and install the contributed 3rd. party
# applications and tools
[ "$SDECFG_PKG_POSTGRESQL_CONTRIB" == 0 ] || 
	var_append patchfiles ' ' "$confdir/build_contrib.diff"

var_append extraconfopt " " "--with-gnu-ld"

# Enable thread-safety for libpq and ecpg by default
var_append confopt ' ' "--enable-thread-safety"

# SSL support
pkginstalled openssl && \
	var_append extraconfopt " " "--with-openssl"

#  --with-tcl              build Tcl modules (PL/Tcl)

# Perl module support (PL/Perl)
if pkginstalled perl; then
	var_append extraconfopt " " "--with-perl"
fi

# Python modules support (PL/Python)
if pkginstalled python; then
	var_append extraconfopt " " "--with-python"
fi

postgresql_pm() {
	# Create the data directory
	mkdir -p $root/$localstatedir/data
	chown -R postgres:postgres $root/$localstatedir/data

	# Create the Profile
	echo "Creating /etc/profile.d/$pkg ..."
	cat <<- EOT > $root/etc/profile.d/$pkg
		export PGDATA=$localstatedir/data
	EOT
}

hook_add postmake 5 "postgresql_pm"