#!/bin/ksh
#
#ident	"@(#)usb_filter.sh	1.3	04/12/08 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

if [ $# -ne 1 ]; then
    echo "!ERROR: $0 <hostname>"
    exit 1
fi

mnttab="/etc/mnttab"
prgdir="/opt/SUNWstaf/prgs"
diskfile="/opt/SUNWstaf/config-util/config.s+h.info" 
filterdiskfile="/tmp/filterdisk.info"
tmpfile="/tmp/filterdisk"
hname=$1

:>$filterdiskfile
:>$tmpfile
k=0

if [ -f $diskfile ]; then
    j=0
    while read i
    do
        disk=`echo $i | awk '{print $1}' | sed 's/^\/.*\/.*\///g' `
        $prgdir/usb_check.sh "${disk}s2" $hname
        if [ $? -eq 0 ]; then
            usb_disk[$j]=$i
            j=`expr $j + 1`
        else
            not_usb_disk[$k]="/dev/dsk/$disk"
            k=`expr $k + 1`
        fi
    done </opt/SUNWstaf/config-util/config.s+h.info
#    i=0
#:>$diskfile
#    while [ $i -ne $j ]
#    do
#        echo ${usb_disk[$i]} >> $diskfile
#        i=`expr $i + 1`
#    done

#    i=0
#    while [ $i -ne $k ]
#    do
#        echo ${not_usb_disk[$i]} >> $tmpfile
#        i=`expr $i + 1`
#    done
#    cat $tmpfile | sort | uniq > $filterdiskfile
else
    while read i
    do
        disk=`echo $i | awk '{print $1}' | grep "^/dev/" | sed -e 's/^\/.*\/.*\///g' -e 's/..$//' `
        if [ -z $disk ]; then
            continue;
        fi

        $prgdir/usb_check.sh "${disk}s2" $hname
        if [ $? -ne 0 ]; then
            not_usb_disk[$k]="/dev/dsk/$disk"
            k=`expr $k + 1`
        fi

    done <$mnttab
fi
    i=0
    while [ $i -ne $k ]
    do
        echo ${not_usb_disk[$i]} >> $tmpfile
        i=`expr $i + 1`
    done
    cat $tmpfile | sort | uniq > $filterdiskfile

