### this file is sourced not run
PKGVER=15.4
PKGBUILD=1
PKGARCH=x86_64

# BLFS post-7.5 (2014-08-04) updated to 15.3 - synced with BLFS 11.3 then updated to latest.
TARBALL=postgresql-$PKGVER.tar.bz2
MD5SUM=f2f861fb99d742cb9c2f8aa46a8a947d
SRC_URL=http://ftp.postgresql.org/pub/source/v$PKGVER/$TARBALL
BUNDLE=

SLACKREQ='openssl libxml2 libxslt'
SLACKDESC="postgresql: postgresql $PKGVER (Database server)  
postgresql:  
postgresql: PostgreSQL is an advanced object-relational database management 
postgresql: system (ORDBMS), derived from the Berkeley Postgres database 
postgresql: management system.  
postgresql: 
postgresql: The default database cluster location is /srv/pgsql/data.
postgresql: You need to initialise this yourself, using the "postgres" user,
postgresql: like this: 'su -c \"initdb -D /srv/pgsql/data\" postgres'.
postgresql: Then type \"service postgresql start\", as root,
postgresql: to start the database server.
"

SLACKINSTALL='
! grep -q postgres ./etc/passwd && echo "postgres:x:41:41:PostgreSQL Server,,,:/srv/pgsql:/bin/sh" >> ./etc/passwd
! grep -q postgres ./etc/group  && echo "postgres:x:41:postgres" >> ./etc/group
'

### default pkg_download
### default pkg_prepare
### default pkg_package
### build
pkg_build() {
	cd /tmp/postgresql*
	
	# create users - must be the same as the ones specified in SLACKINSTALL
	{	echo "cd /"
		echo "$SLACKINSTALL"
	} > /tmp/create-user &&
	sh /tmp/create-user
	
	# change socket from /tmp to /run/postgresql - we don't use this patch
	# sed -i '/DEFAULT_PGSOCKET_DIR/s@/tmp@/run/postgresql@' src/include/pg_config_manual.h &&
	
	# configure and build and install
	export ICU_DATA=/usr/share/icu/current/ && # so ICU knows where its data is
	CONFFLAGS="$CONFFLAGS \
		--enable-thread-safety \
		--docdir=/usr/share/doc/postgresql-$PKGVER \
		--with-icu --with-libxml --with-libxslt --with-openssl \
		" &&
	pkg_build_autoconf &&

	# install docs
	make install-docs &&

	# build and install contributed binaries
	make -C contrib && make -C contrib install &&

	# install init script
	install -dm755 /etc/init.d &&
	install -m644 /tmp/pkg/99-postgresql /etc/init.d &&

	# setup initial database location as specified in init script and user-id
	install -v -dm700 /srv/pgsql/data &&
	chown -R postgres:postgres /srv/pgsql &&
	
	# finish and cleanup
	pkg_build_slackdesc &&
	rm -f /etc/passwd /etc/group
}


