#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos720 src/bos/usr/sbin/install/which_fileset/which_fileset.sh 1.4 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1997,2006 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)49	1.4  src/bos/usr/sbin/install/which_fileset/which_fileset.sh, cmdinstl, bos720 11/13/06 14:09:44
#
#   COMPONENT_NAME: cmdinstl
#
#   FUNCTIONS: none
#
#   ORIGINS: 27
#
#                    -- (                            when
#   combined with the aggregated modules for this product)
#   OBJECT CODE ONLY SOURCE MATERIALS
#
#   (C) COPYRIGHT International Business Machines Corp. 1997
#   All Rights Reserved
#   US Government Users Restricted Rights - Use, duplication or
#   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#

AIX_CONTENTS_FILE=/usr/lpp/bos/AIX_file_list

umask 077
unset PATH
export PATH="/usr/bin:/etc:/usr/sbin:/usr/ucb:/dev:$PATH"

TMPDIR=${TMPDIR:-$HOME/tmp}
[[ ! -d $TMPDIR ]] && TMPDIR=/tmp
TMPDIR=$TMPDIR/${0##*/}.$$
mkdir $TMPDIR || exit 1 
trap "/bin/rm -rf $TMPDIR 2>/dev/null" EXIT INT TERM QUIT HUP

TMP_GREP_FILE=$TMPDIR/tmpfile1

TRUE=1
FALSE=0
FOUND=0

INU_WH_FS_SYNTAX=199
INU_WH_FS_CONTENTS_FILE=200
INU_WH_FS_FILE_NOT_FOUND=201


if (( $# != 1 ))
then
    inuumsg $INU_WH_FS_SYNTAX 1>&2
    exit 1
fi

if [ "$1" = "-h" -o "$1" = "-?" -o "$1" = "-help" ]
then
    inuumsg $INU_WH_FS_SYNTAX 1>&2
    exit 1
fi

if [ ! -f $AIX_CONTENTS_FILE ]
then 
    inuumsg $INU_WH_FS_CONTENTS_FILE $AIX_CONTENTS_FILE 1>&2
    exit 1
fi

echo $1 | grep "/" > /dev/null 2>&1

if [ $? -eq 0 ]
then

   /usr/bin/egrep "$1$" $AIX_CONTENTS_FILE > $TMP_GREP_FILE
   [ $? -eq 0 ] && FOUND=$TRUE

else

   /usr/bin/egrep "/$1$" $AIX_CONTENTS_FILE > $TMP_GREP_FILE
   [ $? -eq 0 ] && FOUND=$TRUE

fi

if (( $FOUND == $FALSE ))
then

   echo $1 | grep "/" > /dev/null 2>&1

   if [ $? -eq 0 ]
   then

      /usr/bin/egrep "$1 ->" $AIX_CONTENTS_FILE > $TMP_GREP_FILE
      [ $? -eq 0 ] && FOUND=$TRUE


   else

      /usr/bin/egrep "/$1 ->" $AIX_CONTENTS_FILE > $TMP_GREP_FILE
      [ $? -eq 0 ] && FOUND=$TRUE
 
   fi

   if (( $FOUND == $FALSE ))
   then
      inuumsg $INU_WH_FS_FILE_NOT_FOUND $1 1>&2
      exit 1
   fi

fi

cat $TMP_GREP_FILE | awk -F":" '
        {
            len = length($2)
            spaces1 = " "
            for (i = 1; i < 40 - len; i++)
                spaces1 = spaces1 " "
            len = length($1)
            spaces2 = " "
            for (i = 1; i < 23 - len; i++)
                spaces2 = spaces2 " "
            print $2 spaces1 $1 spaces2 
        }'

exit 0