#!/bin/sh -e
#
# debian/postinst for getpath
# Ask whether or not to overwrite the conf file.
# Make sure the login files are calling getpath.
#

umask 022
pkg=getpath
. /usr/share/debconf/confmodule

usrdoclink()
{
	#
	# Create the /usr/doc/getpath -> usr/share/doc/getpath link.
	#

	if [ -d /usr/doc -a ! -d /usr/doc/${pkg} -a -d /usr/share/doc/${pkg} ]; then
		ln -sf /usr/share/doc/${pkg} /usr/doc/${pkg}
	fi

}

writeconf()
{
	#
	# Overwrite /etc/getpath.conf if requested.
	#

	# now handled for us by dpkg
	return 0

	if [ -e /etc/getpath.conf ]; then
		db_get getpath/writeconf
		if [ "$RET" = "true" ]; then
			mv /etc/getpath.conf /etc/getpath.conf.old
			mv /etc/getpath.conf.new /etc/getpath.conf
		else
			rm -f /etc/getpath.conf.new
		fi
	else
		mv /etc/getpath.conf.new /etc/getpath.conf
	fi

}

writerc()
{
	#
	# Check login files.
	#

	db_get getpath/editrc
	if [ "$RET" = "true" ]; then
		if [ -e /etc/profile -a "`grep getpath /etc/profile`" = "" ]; then
			if [ "`sed -n \\$p /etc/profile`" != "" ]; then
				echo "" >> /etc/profile
			fi
			echo 'export PATH=`/usr/bin/getpath` # auto added by getpath' >> /etc/profile
		fi
		if [ -e /etc/csh.cshrc -a "`grep getpath /etc/csh.cshrc`" = "" ]; then
			if [ "`sed -n \\$p /etc/csh.cshrc`" != "" ]; then
				echo "" >> /etc/csh.cshrc
			fi
			echo 'setenv PATH `/usr/bin/getpath` # auto added by getpath' >> /etc/csh.cshrc
		fi
	fi

}

case "$1" in
	(configure)
		usrdoclink
		writeconf
		writerc
		;;
	(abort-upgrade|abort-remove|abort-deconfigure)
		;;
esac
exit 0
