#!/bin/sh

if [ ! -f /etc/netperm-table ]; then
	echo "installing default /etc/netperm-table...";
	cp "${ENCAP_SOURCE}/${ENCAP_PKGNAME}/netperm-table" /etc/netperm-table \
		&& chmod 600 /etc/netperm-table;
fi

grep '7777/tcp' /etc/services > /dev/null;
if [ $? -ne 0 ]; then
	echo "adding tisauth entry to /etc/services..."
	cp /etc/services "/etc/services.pre.${ENCAP_PKGNAME}" \
		&& cat >> /etc/services <<EOF
tisauth         7777/tcp                # TIS authentication server
EOF
fi

if [ -f /etc/pam.conf ]; then
	grep pam_authsrv.so.1 /etc/pam.conf > /dev/null 2>&1;
	if [ $? -ne 0 ]; then
		echo "adding sample pam_authsrv.so.1 entry to /etc/pam.conf...";
		cp /etc/pam.conf "/etc/pam.conf.pre.${ENCAP_PKGNAME}" \
			&& sed "s:@ENCAP_TARGET@:${ENCAP_TARGET}:" >> /etc/pam.conf <<EOF
#
# authsrv authentication
#
#su	auth	sufficient	@ENCAP_TARGET@/lib/security/pam_authsrv.so.1 unknown_user=ignore
#su	auth	required	/usr/lib/security/pam_unix.so.1
EOF
	fi
elif [ -f /etc/pam.d/su ]; then
	grep pam_authsrv.so.1 /etc/pam.d/su > /dev/null 2>&1;
	if [ $? -ne 0 ]; then
		echo "adding sample pam_authsrv.so.1 entry to /etc/pam.d/su...";
		cp /etc/pam.d/su "/etc/pam.d/su.pre.${ENCAP_PKGNAME}" \
			&& sed "s:@ENCAP_TARGET@:${ENCAP_TARGET}:" >> /etc/pam.d/su <<EOF
#
# authsrv authentication
#
#auth	sufficient	@ENCAP_TARGET@/lib/security/pam_authsrv.so.1 unknown_user=ignore
#auth	required	/lib/security/pam_pwdb.so shadow nullok
EOF
	fi
fi

