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

CMPNTCHECK=gnutools
CMPNTNAME=gnutools
CMPNTDESC="GNU Development Tools"

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

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

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

# We have two kinds of error conditions we provoke:
# 1) Unsupported OS version (5.0.0, 5.0.2 and anything later than 5.0.7)
# 2) Need OSS646B or, on 507, OSS646B or MP1

IS507=0
HAS507MP=0
need646=1
failureval=$FAIL

osver=`/bin/uname -X | /bin/grep '^Release' | /bin/sed -e 's/Release = 3.2v//'`
case $osver in
  5\.0\.7)
    IS507=1
    ;;
  5\.0\.4 | 5\.0\.5 | 5\.0\.6)
    # Do nothing right now
    ;;
  *) ccsLog "Unsupported OS version $osver"
     ${SSO_SHARED_ROOT}/cntl/badver $osver "$CMPNTDESC"
     exit $STOP
     ;;
esac

UNIXPATCHES=`customquery ListPatches SCO:Unix 2> /dev/null`
OLDVERSION=`customquery ListComponents SCO:$CMPNTNAME 2> /dev/null`
if [ -n "$OLDVERSION" ]; then
  HASOLDVERSION=1
else
  HASOLDVERSION=0
fi

if [ "x$IS507" = "x1" ]; then
  # Check for MP1 or later
  echo " $UNIXPATCHES " | grep '^SCO:Unix::5.0.7Hw.*rs507a.Unix507' > /dev/null 2>&1
  if [ $? -eq 0 ]; then
    HAS507MP=1
    failureval=$STOP
  else
    # Work with the build supplement too, Make that equiv to MP1
    echo " $UNIXPATCHES " | grep 'Unix5.0.'/dev/null 2>&1
    if [ $? -eq 0 ]; then
      HAS507MP=1
      failureval=$STOP
    fi
  fi
  if [ "x$HAS507MP" = "x1" ]; then
    need646=0
  else
    need646=2
  fi
else
  # Not a 507 system
  echo " $UNIXPATCHES " | grep 'OSS646[B-Z]' > /dev/null 2>&1
  if [ $? -eq 0 ]; then
    need646=0
  else
    if [ "x$HASOLDVERSION" = "x0" ]; then
      failureval=$STOP
    fi
  fi
fi

if [ "x$need646" = "x1" ]; then
  ${SSO_SHARED_ROOT}/cntl/need646 "$CMPNTDESC"
  exit $failureval
elif [ "x$need646" = "x2" ]; then
  ${SSO_SHARED_ROOT}/cntl/needMP1 "$CMPNTDESC"
  exit $failureval
fi

exit $OK

