#! /bin/sh

PATH="/usr/bin:/usr/sbin:${PATH}"
export PATH

OPIDEVICES=$BASEDIR/SUNWopi/config/opi.devices
INPUTFILE=$PKG_INSTALL_ROOT/var/sadm/pkg/$PKGINST/install/opi.devices.bak

dest=$OPIDEVICES
src=$INPUTFILE

if [ ! -d `dirname $dest` ]
then
	echo "Directory has not been created"
	exit 2
fi

if [ ! -f $dest ];  then
   cp $src $dest
else
  if [ ! -w $dest ]; then
     echo "Error: $dest not writeable"
     exit 2
  fi

  echo "Performing merge for $dest..."	
  # merge existing and new version
  while read line
  do
    grep "^$line\$" $dest > /dev/null
    if [ $? != 0 ] ; then
       echo "$line" >> $dest
    fi
  done < $src
fi

