#! /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

remove_lines_from_config_file() {
    # look for arbitrary number of " " and tabs
    # at beginning and end of line
    str="^[ 	]*$1[ 	]*\$"
    if grep -s "$str" $OPIDEVICES >/dev/null 2>&1
    then
        grep -v "$str" $OPIDEVICES >/tmp/grep$$
        cat /tmp/grep$$ >$OPIDEVICES  # this will retain modes/links
    fi
}

if [ ! -w $OPIDEVICES ]; then
   echo "Error: $OPIDEVICES not writeable"
   exit 2
fi

if [ ! -f $INPUTFILE ]; then
   echo "Could not find package removal data file"
   echo "$OPIDEVICES could not be modified"
   exit 0
fi

# 

# Delete newly added lines

while read line
do
  remove_lines_from_config_file "$line"
done <  $INPUTFILE

# remove if file exist but is now empty
if [ -f $dest ] ; then
   if [ ! -s $dest ] ; then
     removef $PKGINST $dest
     rm -f $dest
     removef -f $PKGINST || exit 2
   fi
fi



