#!/bin/sh
#
# Component Name: TivoliPlus
#
# $Source: /tivoli/development/src/2.0/plus/Link/src/wcrtsprf,v $
#
# $Revision: 1.4 $
#
# Description:
#
# (C) COPYRIGHT Tivoli Systems, Inc. 1995-2000
# Unpublished Work
# All Rights Reserved
# Licensed Material - Property of Tivoli Systems, Inc.
#

[ "$DEBUG" = true ] && set -xv

THIS_CMD=`echo $0 | tr "\\\\\\\\" "/"`; THIS_CMD=`basename $THIS_CMD`
USAGE=`wbindmsg LinkCmdCat 20 "Usage: %1\\$s profile-manager subscriber [ subscriber ... ]" "$THIS_CMD" 2> /dev/null`
if [ ! "$USAGE" ]; then
	USAGE="Usage: $THIS_CMD profile-manager subscriber [ subscriber ... ]"
fi

if [ $# -lt 2 ] ; then 
	echo $USAGE
	exit 1
fi

PMNAME=$1
shift

#Get the region name to avoid collisions
IRO=`wlookup InterRegion`
IRONAME=`idlattr -t -g $IRO name string`
IRONAME=`eval echo $IRONAME`

#Check to see if profile manager exists
PM_CLASS=`wlookup -r Classes ProfileManager`
PRFMGR=`idlcall $PM_CLASS lookup_object '"'$PMNAME'" {0}'`
STATUS=$?
if [ $STATUS -ne 0 ] ; then
	exit $STATUS
elif wlookup -r ProfileManager "$PMNAME#$IRONAME" > /dev/null 2>& 1 ; then
	:
else
	#Make the existing one visible via wlookup
	wregister -r ProfileManager "$PMNAME" "$PRFMGR"
fi

while [ "$1" ]; do
	wsub @ProfileManager:"$PMNAME#$IRONAME" "$1#$IRONAME"
	shift
done

exit 0
