#!/bin/ksh 
#
# ident	"@(#)stripcpioerr.sh	1.1	00/09/05 SMI"
#
# Copyright (c) 2000 by Sun Microsystems, Inc.
# All rights reserved.
#
# stripcpioerr strips errors from a cpio command that
# can safely be ignored.  For example, chown() on /boot
# can be ignored on x86 since this is a harmless failure
# during install.
NO=no
YES=yes
TOTAL=0
hasinput=$NO

# first read each line.  If the line contains "chown()" then
# the failure was a chown failure.  If we were chown'ing
# the "boot" file or a file under that directory (e.g.
# "boot/any/file", then we can ignore it.
while read line ; do
    hasinput=$YES
    lastline=$line
    FOUND=$NO
    echo $line|grep 'chown()' 2> /dev/null > /dev/null
    if [ $? = 0 ] ; then
	echo $line|grep '"boot"' 2> /dev/null > /dev/null
	if [ $? != 0 ] ; then
	    echo $line|grep '"boot/' 2> /dev/null > /dev/null
	    if [ $? = 0 ] ; then
		FOUND=$YES
	    fi
	else
	    FOUND=$YES
	fi
    fi

    [ "$FOUND" = $YES ] && {
	TOTAL=`expr $TOTAL + 1`
    }
done

# if we had no input, just exit with success, this means cpio
# succeeded.
if [ "$hasinput" = "$NO" ] ; then
    exit 0
fi

# lastline is the last line of cpio, which should be a count of
# the number of errors encountered.  If this number is equal to the
# number of errors we are ignoring, then no error really
# occurred, and we exit with success.  Otherwise, an error really
# did occur that we can't ignore, so exit with non-zero failure
# status.
returncode=0
echo $lastline | grep 'error(s)' 2> /dev/null > /dev/null
if [ $? = 0 ] ; then
    CPIO_ERRS=`echo $lastline|awk '{print $1}'`
    [ "$CPIO_ERRS" != "$TOTAL" ] && {
	returncode=1
    }
fi

exit $returncode
	
