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

# source: BLFS 11.3
TARBALL=postfix-$PKGVER.tar.gz
MD5SUM=2442d1e53d58e61842d99fb5978fec4a
SRC_URL=https://ghostarchive.org/postfix/postfix-release/official/$TARBALL
BUNDLE=

SLACKREQ='libbdb openssl sqlite3 libpcre libnsl'
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 &&

	cd /tmp/postfix* &&

	# BLFS: fix building with Linux 6.x onwards
	sed -i 's/Linux..345/&6/' makedefs &&
	sed -i 's/LINUX2/LINUX6/' src/util/sys_defs.h &&

	# 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 &&	

	CCARGS= AUXLIBS=
	
	# Use cyrus-sasl
	CCARGS="$CCARGS -DNO_NIS -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl"
	AUXLIBS="$AUXLIBS -lsasl2"
	
	# Use sqlite
	CCARGS="$CCARGS -DHAS_SQLITE"
	AUXLIBS="$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
}


