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

# post BLFS 7.8 2016-01-23
TARBALL=postfix-$PKGVER.tar.gz
MD5SUM=61caffae689c11d09b4c972a394ae3b1
SRC_URL=ftp://ftp.porcupine.org/mirrors/postfix-release/official/$TARBALL
BUNDLE=

SLACKREQ='libdb 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: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:33" >> ./etc/group
'

### default pkg_download
### default pkg_prepare
### default pkg_package
### build
pkg_build() {
	# users - required for installation
	echo "nobody:x:65534:65534::/tmp:" >> /etc/passwd
	echo "postfix:x:32:32:Postfix Daemon,,,:/var/spool/postfix:/bin/false" >> /etc/passwd &&
	echo "postfix:x:32" >> /etc/group &&
	echo "postdrop:x:33" >> /etc/group &&
	mkdir -p /var/mail &&
	chown -v postfix:postfix /var/mail &&

	cd /tmp/postfix*
	#sed -i -e "s/DB_VERSION_MAJOR == 5/DB_VERSION_MAJOR >= 5/" src/util/dict_db.c &&
	sed -i -e 's/.\x08//g' README_FILES/* &&
	
	# 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\\\""
	
	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 &&
	   
	install -m644 /tmp/pkg/aliases /etc/aliases &&
	pkg_build_slackdesc &&
	rm -f /etc/passwd /etc/group
}


