#ident	"@(#)i.build	1.5	02/09/23 SMI"	/* SVr4.0  1.6	*/ 

error=no
while read src dest
do
	[ "$src" = /dev/null ] && continue

	echo "Modifying $dest"
	
	# Strip PKG_INSTALL_ROOT from dest if installation is to an
	# alternate root.

	if [ -n "$PKG_INSTALL_ROOT" -a "$PKG_INSTALL_ROOT" != "/" ]; then
		client_dest=`echo $dest | \
			/usr/bin/nawk -v rootdir="$PKG_INSTALL_ROOT" '{
				{ print substr($0, length(rootdir)+1)} }'`
		savepath=$PKGSAV/build${client_dest}
	else
		savepath=$PKGSAV/build${dest}
	fi

	dirname=`dirname $savepath`
	if [ $? -ne 0 ]
	then
		error=yes
		continue
	fi

	if [ ! -d $dirname ]
	then
		# ignore return since mkdir has bug
		mkdir -p $dirname
	fi

	cp $src $savepath &&
		chmod 500 $savepath
	if [ $? -ne 0 ]
	then
		error=yes
		continue
	fi

#	if $savepath install $dest > /tmp/$$build
# bug id 1081806             vvv
	if $savepath install > /tmp/$$build
	then
		if [ -s /tmp/$$build ]
		then
			cp /tmp/$$build $dest || error=yes
		fi
	else
		error=yes
	fi
	rm -f /tmp/$$build
done
[ "$error" = yes ] &&
	exit 2
exit 0
