#!/bin/sh
#
# ident "@(#)postpatch.src	1.2 02/05/29 SMI"
#
# Copyright (c) 2001, by Sun Microsystems, Inc.
# All rights reserved.
#
# Check if the interconnect has been configured. If so,
# update the firmware on all units as soon as the patch 
# is installed.
#

# We may be installed as part of a jumpstart, so check
# the install root

UT_ROOTDIR=${2:-/}

HOSTS=${UT_ROOTDIR}/etc/inet/hosts
HOSTNAME_R=${UT_ROOTDIR}/etc/hostname

ETC_OPT_UT=${UT_ROOTDIR}/etc/opt/SUNWut
SMARTCARD_FILES_PATH=${ETC_OPT_UT}/smartcard
UTADMIN_GROUP=utadmin

# change the group ownership of the newly installed smartcard files

if [ -d $SMARTCARD_FILES_PATH ]; then
      chgrp $UTADMIN_GROUP $SMARTCARD_FILES_PATH
else
      echo "Smartcard config file directory doesn't exist"
fi

if [ -f $SMARTCARD_FILES_PATH/probe_order.conf ]; then
      chgrp $UTADMIN_GROUP $SMARTCARD_FILES_PATH/probe_order.conf
      chmod 0664 $SMARTCARD_FILES_PATH/probe_order.conf
else
      echo "Smartcard config probe order configuration file doesn't exist"
fi

# get a list of existing Sun Ray interfaces

grep 'SUNRAY ADD' ${HOSTS} | awk '{ print $2 }' >/tmp/newthosts.$$
fgrep -l -f /tmp/newthosts.$$ ${HOSTNAME_R}.* 2>/dev/null | sed "s!${HOSTNAME_R}.!!" >/tmp/newtifs.$$
rm /tmp/newthosts.$$ 2>/dev/null

INTFS=`cat /tmp/newtifs.$$`
rm /tmp/newtifs.$$ 2>/dev/null

# Check if the Sun Ray interconnect has been configured

if [ -z "${INTFS}" ]; then
	echo ""
	echo "WARNING: Firmware download has not been enabled as the"
	echo "         interconnect framework is not configured."
	echo ""
	echo "Refer to the patch README file for information on manually"
	echo "configuring firmware downloads."
	echo ""
else
	UT_BASEDIR=`pkginfo -R ${UT_ROOTDIR} -r SUNWuto`
	$UT_BASEDIR/SUNWut/sbin/utfwadm -A -a -n all
fi
