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

# post BLFS 8.3 2018-10-16
TARBALL=postfix-$PKGVER.tar.gz
MD5SUM=4381c6492f415e4a69cf5099d4acea76 
SRC_URL=ftp://ftp.porcupine.org/mirrors/postfix-release/official/$TARBALL
BUNDLE=

SLACKREQ='libbdb openssl sqlite3 libpcre'
SLACKDESC="postfix: postfix $PKGVER (Mail Server)  
postfix:  
postfix: The Postfix package contains a Mail Transport Agent (MTA). This is 
postfix: useful for sending email to other users of your host machine. It can 
postfix: also be configured to be a central mail server for your domain, a 
postfix: mail relay agent or simply a mail delivery agent to your local 
postfix: Internet Service Provider.  
postfix: 
postfix: This build works best with dovecot IMAP/POP3 server.
postfix: 
postfix:
"
SLACKSUG='dovecot'
SLACKINSTALL='
! grep -q postfix  ./etc/passwd && echo "postfix:x:32:32:Postfix Daemon,,,:/var/spool/postfix:/bin/false" >> ./etc/passwd
! grep -q postfix  ./etc/group  && echo "postfix:x:32" >> ./etc/group
! grep -q postdrop ./etc/group  && echo "postdrop:x:34" >> ./etc/group
'

### default pkg_download
### default pkg_prepare
### default pkg_package
### build
pkg_build() {
	# create users - must be the same as the ones specified in SLACKINSTALL
	echo "nobody:x:65534:65534::/tmp:" >> /etc/passwd	
	{	echo "cd /"
		echo "$SLACKINSTALL"
	} > /tmp/create-user &&
	sh /tmp/create-user

	# fatdog defaults
	mkdir -p /var/mail &&
	chown -v postfix:postfix /var/mail &&

	# BLFS: patch to recognise older libbdb
	cd /tmp/postfix* &&	
	sed -i 's/DB_VERSION_MAJOR == 6 .*||/DB_VERSION_MAJOR > 4 ||/' \
		src/util/dict_db.c &&	
	
	# Use sqlite
	CCARGS="-DHAS_SQLITE"
	AUXLIBS="-lsqlite3 -lpthread"
	
	# Use mariadb
	CCARGS="$CCARGS -DHAS_MYSQL -I/usr/include/mysql"
	AUXLIBS="$AUXLIBS -lmysqlclient -lz -lm"

	# Use postgresql
	CCARGS="$CCARGS -DHAS_PGSQL -I/usr/include/postgresql"
	AUXLIBS="$AUXLIBS -lpq -lz -lm"

	# Use StartTLS authentication
	CCARGS="$CCARGS -DUSE_TLS -I/usr/include/openssl"
	AUXLIBS="$AUXLIBS -lssl -lcrypto"
	
	# Use Dovecot authentication
	CCARGS="$CCARGS -DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE=\\\"dovecot\\\""

	# use libicu
	export ICU_DATA=/usr/share/icu/current/ && # so ICU knows where its data is
	make CCARGS="$CCARGS" AUXLIBS="$AUXLIBS" makefiles &&
	make $MAKEFLAGS &&
	
	sh postfix-install -non-interactive \
	   daemon_directory=/usr/$LIBDIR/postfix \
	   manpage_directory=/usr/share/man \
	   html_directory=/usr/share/doc/postfix-$PKGVER/html \
	   readme_directory=/usr/share/doc/postfix-$PKGVER/readme &&

	# BLFS default aliases
	install -m644 /tmp/pkg/aliases /etc/aliases &&
	
	pkg_build_slackdesc &&
	rm -f /etc/passwd /etc/group
}


