#!/bin/ksh -p
#
# ident "@(#)utspatches.ksh	1.4 12/09/10 Oracle"
#
# Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
#

PROGRAM_ID=$(/bin/basename $0)
CATEGORY=sunray
export PATH=/usr/bin:/bin:/sbin:/usr/sbin

function CleanUp {
    [ -n "$TMP_P1" ] && rm -f "TMP_P1"
    [ -n "$TMP_P2" ] && rm -f "$TMP_P2"
}

################################################################
#
# MAIN
#
################################################################

set -u
umask 022

OS=$(uname -s)
if [ "$OS" = "Linux" ]; then
    print "No Patch Information"
    exit 0
fi

TMP_P1=$(mktemp /tmp/utspatches.$$.XXXXXXXX)
TMP_P2=$(mktemp /tmp/utspatches.$$.XXXXXXXX)

trap CleanUp 0 1 2 3 14 15

showrev -p > ${TMP_P1}
touch ${TMP_P2}
pkginfo -c ${CATEGORY} 2> /dev/null | awk '{ print $2 }' | {
    while read PKG; do
	grep $PKG ${TMP_P1} >> ${TMP_P2}
    done
}
sort ${TMP_P2} | uniq | awk '{ print $2 }'

rm ${TMP_P1}
rm ${TMP_P2}
