#!/bin/sh

grep csnet-ns /etc/services > /dev/null 2>&1
if [ $? -ne 0 ]; then
	echo "adding csnet-ns to /etc/services..."
	cp /etc/services /etc/services.pre.${ENCAP_PKGNAME}
	echo "csnet-ns		105/tcp		ns	# PH" >> /etc/services
fi

if [ ! -d "@sysconfdir@" ]; then
	echo "creating directory @sysconfdir@...";
	mkdir -p "@sysconfdir@";
fi

if [ ! -f "@sysconfdir@/ph_server" ]; then
	PH_SERVER=`hostname | awk -F. '(NF > 1) { printf "ns.%s.%s\n", $(NF - 1), $NF; }'`;

	if [ -z "${PH_SERVER}" ]; then
		if [ -x /usr/sbin/nslookup ]; then
			NSLOOKUP=/usr/sbin/nslookup;
		elif [ -x /usr/bin/nslookup ]; then
			NSLOOKUP=/usr/bin/nslookup;
		fi

		if [ -n "${NSLOOKUP}" ]; then
			PH_SERVER=`hostname | xargs ${NSLOOKUP} | awk '/^Name:/ { print $2; exit; }' | awk -F. '{ printf("ns.%s.%s\n", $(NF - 1), $NF); }'`;
		fi
	fi

	if [ -n "${PH_SERVER}" ]; then
		echo "creating default @sysconfdir@/ph_server file...";
		echo "${PH_SERVER}" > @sysconfdir@/ph_server;
	else
		echo "WARNING: cannot determine PH server name - you must create @sysconfdir@/ph_server manually";
	fi
fi

if [ ! -f "@sysconfdir@/nphrc" ]; then
	echo "installing default @sysconfdir@/nphrc file...";
	cp ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/nphrc @sysconfdir@/nphrc;
fi



syntax highlighted by Code2HTML, v. 0.9.1