#!/bin/sh
#
# Check for proper usage and print usage if necessary
#

if [ $# != 0 ]
then
   echo "Usage: $0 "
   echo
   echo "This program expects an updatep diskette in the floppy drive."
   echo "Output is the version of the LPPs, both on the update diskette"
   echo "and the installed version."
   echo
   exit 1
fi

#
# Restore just the file that contains the level
#

cd /tmp
/etc/restore -x ./usr/sys/inst_updt/control >/dev/null
cd usr/sys/inst_updt


#
# Find only those LPPs that exist on BOTH the hard file and diskette
#

for i in `(fgrep "_vrl" control |cut -f1 -d'_';ls /usr/lpp) | sort |uniq -d`
do

#
# Display the current version
#

   echo "Version of $i that is installed is: \c"
   tail -1 /usr/lpp/$i/lpp.hist | grep "^r" >/dev/null 2>&1
   if [ $? != 0 ]
     then grep "^[ac]" /usr/lpp/$i/lpp.hist | tail -1 | cut -c18-27
     else grep "^c" /usr/lpp/$i/lpp.hist | tail -1 | cut -c18-27
   fi

#
# Pull out line for this LPP from the diskette control file
#

   line=`fgrep -n "${i}_vrl" control | cut -f1 -d:`
   line=`expr $line + 1`

#
# Display the diskette version
#

   echo "Version of $i that is on diskette is: \c"
   ( echo ${line}p;echo q )|ed - control | cut -f1-3 -d' '
   echo
done

#
# Perform the cleanup.  Remove the directories separately in case some other pgm
# was using them as well.
#

cd /tmp
rm -f usr/sys/inst_updt/control
rmdir usr/sys/inst_updt usr/sys usr 2> /dev/null
