#!/bin/sh
#
# Copyright 1999 Sun Microsystems, Inc. All Rights Reserved
#
# @(#)ss_activate.sh	3.7 00/02/18 Sun Microsystems, Inc.
#

PATH="/usr/bin"
export PATH

SS_LIBDIR=/opt/SUNWicg/SunScreen/lib
SS_ETCDIR=/etc/opt/SUNWicg/SunScreen

error()
{
	echo>&2 "$0: $1 -- Exiting..."
	exit 1
}

ACTIVE=${1-$SS_ETCDIR/.active}		# the new config being activated
OLD=$2					# the old config currently running

[ -d "$ACTIVE" ] ||
	error "There is no active configuration $ACTIVE"

cd $ACTIVE

$SS_LIBDIR/ss_plumb_interface -Z -d "$ACTIVE" -a ||
	error "ss_plumb_interface failed, return code $?"

if [ -n "$OLD" ] && [ -f $OLD/Interface.in ]
then if cmp -s "$ACTIVE/Interface.in" "$OLD/Interface.in"
     then :
     else (
	IFS='" '
	while read if rest
	do if $SS_LIBDIR/ss_plumb_interface -Z -d "$ACTIVE" $if >/dev/null 2>&1
	   then :
	   else $SS_LIBDIR/ss_plumb_interface -Z -d "$ACTIVE" -u $if
	   fi
	done < "$OLD/Interface.in"
	  )
     fi
fi

$SS_LIBDIR/ss_default_drop -Z -d "$ACTIVE" -a ||
	error "ss_default_drop failed, return code $?"

$SS_LIBDIR/ss_active_config -Z -d "$ACTIVE" activate ||
	error "activate failed, return code $?"

$SS_LIBDIR/ss_fix_multicast >/dev/null 2>&1 ||
	error "ss_fix_multicast failed, return code $?"

if [ -f /kernel/drv/skip_key ]
then	$SS_LIBDIR/load_group -d "$ACTIVE" >/dev/null 2>&1 ||
		error "load_group failed, return code $?"
fi

# If one or more HA hosts were removed from the HA configuration,
# sync them before activating so that they will be updated with
# the new configuration.
#
#if [ -n "$OLD" ] && [ -d "$OLD" ] && [ -f $OLD/HA ]
#then
#    fgrep -vxf HA $OLD/HA | grep '^HA_HOST' |
#    while read type name rest
#    do
#	${SS_LIBDIR}/ss_ha_sync_config $name <Configuration >/dev/null 2>&1
#    done
#fi
