#!/bin/sh 
#
# Copyright 1998 Sun Microsystems, Inc. All Rights Reserved
#
#pragma ident "@(#)chkpkg.sh	3.8 99/11/29 Sun Microsystems, Inc."
#
# Script for checking required packages SunScreen EFS after a
# fresh installation of SKIP and SunScreen EFS.
#
# For this script to work the following must be completed:
#    1. SKIP packages are installed
#    2. SunScreen EFS packages are installed
#    3. the machine was rebooted (to start SKIP)
#
# Exit Codes:
#    0       success
#    2       missing packages
#    3       bad argument
#

PATH="/opt/SUNWicg/bin:/opt/SUNWicg/SunScreen/bin:/usr/bin"
export PATH


cmdline=true

msg() {
  if $cmdline
  then echo "$*"
  fi
}
    
set_num=138     # SI18N_INST_CHKPKG
LS()		# localize a string
{
	msg_num=$1; shift
        if [ -x ${SS_LIBDIR}/catgets ]
        then ${SS_LIBDIR}/catgets $set_num $msg_num "$*"
        else echo "$*"
	fi
}

# ---Main---

if [ $# = "1" ] && [ $1 = "-w" ]
then
  cmdline=false
fi

# check os for 2.6, 2.7 or 2.8
os=`/bin/uname -r 2>/dev/null`
major_os=`expr $os : '\(.\)'`
minor_os=`expr $os : '..\(.\)'`
if [ $minor_os -lt 6 ] || [ $minor_os -gt 8 ]; then
  echo  `LS 10 "SunScreen EFS 3.0 is supported on Solaris 2.6, 2.7 and 2.8."`
  echo "`LS 11 'This system'` (`uname -n`) `LS 12 'is running Solaris'` $os."
  exit 3
fi

processor=`uname -p 2>/dev/null`

# Make sure that required packages are installed
# Only checks packages not installed by the SUNWcore package cluster
#

# Solaris
REQ_PKGS="SUNWdoc SUNWlibC SUNWlibms SUNWsprot SUNWvolr SUNWvolu SUNWtoo SUNWxwplt SUNWmfrun SUNWjvrt SUNWeuluf SUNWloc" 
# XWindows
REQ_PKGS="$REQ_PKGS SUNWxwice SUNWxwrtl"

if $cmdline
then
  # SKIP
  REQ_PKGS="$REQ_PKGS SUNWbdc SUNWkeymg SUNWkusup SUNWrc2 SUNWrc4 SUNWdes"
  # SunScreen
  REQ_PKGS="$REQ_PKGS SUNWicgSA SUNWicgSS"
fi

msg `LS 30 "Checking for required packages"`

LOCAL_PKGS=`pkginfo | awk '{printf("%s ",$2)}'`

#
# Build the missing list
#
MISSING=""
for R in $REQ_PKGS
do FOUND=false
   for L in $LOCAL_PKGS
     do if [ "$R" = "$L" ]
        then FOUND=true
	    break
	 fi
     done
   $FOUND || MISSING="$MISSING $R"
done

if [ "$MISSING" != "" ] ; then

  if $cmdline
  then
    clear
    lmsg=`LS 40 '                           Missing Packages'`
    printf "$lmsg\n\n"
    lmsg=`LS 41 'The following packages are needed to run the SunScreen EFS software.\n  Install these packages before continuing with the SunScreen install.'`
    printf "$lmsg\n"
  fi
  msg `LS 42 "Missing packages:"`
  for M in $MISSING
  do echo "        $M"
  done
  echo ""
  exit 2
fi
