#!/bin/sh
#
#	temporary files to remove at end of script
#
MSG=/tmp/r5links.msg
PKGS=/tmp/r5linkspkgs.msg
REMOVEFPKGS=/tmp/r5linksRmpkgs.msg
#
#	These are the directories whose contents we need to keep
#	for the R6 way ; we may be installing anywhere: /a ;
#	/export/space/2.6intel ; and so on
#
#/a/usr/openwin/lib/app-defaults
#/a/usr/openwin/share/locale/C

touch $MSG $PKGS $REMOVEFPKGS
date 
echo ===  >> $MSG
#
#	pkgadd is giving us the full path to both of these.
#
while	read src dst
do
#
#	pkgadd gives us the install root
#
echo Source and Destination:  >> $MSG
echo $src $dst  >> $MSG
if [ "x${PKG_INSTALL_ROOT}x" = "xx" ] ; then
	DESTDIR=`dirname $dst`
	PKG_INSTALL_ROOT=/
else
	DESTDIR=`dirname $dst`
	DESTDIR=`echo $DESTDIR | sed s@${PKG_INSTALL_ROOT}@@` >> $MSG
fi
echo Root is:  >> $MSG
echo $PKG_INSTALL_ROOT  >> $MSG
#
#	Apparently one cannot execute a script from within pkgadd with
#	a directory. thus I pick one file as the target
#	when I really mean to mess with the whole directory
#	not just the $dst
#
echo New path is: $DESTDIR  >> $MSG
mkdir -p ${PKG_INSTALL_ROOT}/${DESTDIR}
#
# the new path is chosen in this case statement
#
case "${DESTDIR}" in 
	
	/usr/openwin/lib/X11/app-defaults)
	DIR_TO_FIX=/usr/openwin/lib/app-defaults
	;;
	/usr/openwin/share/locale/C)
	DIR_TO_FIX=/usr/openwin/lib/locale/C
	;;
esac
echo Comes from:  >> $MSG
echo $DIR_TO_FIX  >> $MSG
#
#	These are the actual targets of what we are doing.
#
		rm -rf ${PKG_INSTALL_ROOT}/${DIR_TO_FIX} 2>1 > /dev/null
		ln -s ${PKG_INSTALL_ROOT}/${DESTDIR} ${PKG_INSTALL_ROOT}/${DIR_TO_FIX}
		cp $src $dst 2>1 > /dev/null

done	# while src and dst 
#
#	nuke the junk files
#
rm $MSG $FILES $PKGS $REMOVEFPKGS 2>1 > /dev/null
for i in $FILES ; do
	rm -f /tmp/${PKG}.${i} 2>1 > /dev/null
done
