#!/bin/sh
#
#	Copyright (c) 2002, 2003 The SCO Group, Inc..
#	All Rights Reserved.
#
##############################################################################

. ${SSO_SHARED_ROOT}/cntl/cmpnt.desc

# source in std. library functions:
[ -f /ibin/ccsSetup.sh ] && . /ibin/ccsSetup.sh

[ -f /tmp/debug_$CMPNTCHECK ] && set -x

[ -f /tmp/$CMPNTCHECK.nocheck ] && exit $OK

IS507=0
need646=yes
needMP1=yes
failureval=$FAIL

osver=`/bin/uname -X | /bin/grep '^Release' | /bin/sed -e 's/Release = 3.2v//'`

case $osver in
  5\.0\.7)
    IS507=1
    need646=no
    ;;
  5\.0\.4 | 5\.0\.5 | 5\.0\.6)
    needMP1=no
    ;;
  *) ccsLog "Unsupported OS version $osver"
     ${SSO_SHARED_ROOT}/cntl/badver $osver "$CMPNTDESC"
     exit $STOP
     ;;
esac

UNIXPATCHES=`customquery ListPatches SCO:Unix 2> /dev/null`

if [ "x$IS507" = "x1" ]; then
  # Check for MP1
  echo " $UNIXPATCHES " | grep '^SCO:Unix::5.0.7Hw.*rs507a.Unix507' > /dev/null 2>&1
  if [ $? -eq 0 ]; then
    needMP1=no
    failureval=$STOP
  else
    # Work with the build supplement too
    echo " $UNIXPATCHES " | grep 'Unix5.0.'/dev/null 2>&1
    if [ $? -eq 0 ]; then
      needMP1=no
      failureval=$STOP
    fi
  fi
  if [ "x$needMP1" = "xyes" ]; then
    HASOLDVERSION=`customquery ListComponents SCO:$CMPNTCHECK 2> /dev/null`
    if [ -z "$HASOLDVERSION" ]; then
      failureval=$STOP
    fi
  fi
else
  # Not a 507 system
  echo " $UNIXPATCHES " | grep 'OSS646[B-Z]' > /dev/null 2>&1
  if [ $? -eq 0 ]; then
    need646=no
  else
    HASOLDVERSION=`customquery ListComponents SCO:$CMPNTCHECK 2> /dev/null`
    if [ -z "$HASOLDVERSION" ]; then
      failureval=$STOP
    fi
  fi
fi

if [ "x$need646" = "xyes" ]; then
  ccsLog "Missing OSS646"
  ${SSO_SHARED_ROOT}/cntl/need646 "$CMPNTDESC"
  exit $failureval
fi

if [ "x$needMP1" = "xyes" ]; then
  ccsLog "Missing 507MP1"
  ${SSO_SHARED_ROOT}/cntl/needMP1 "$CMPNTDESC"
  exit $failureval
fi

exit $OK

