#!/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-1999.
# Unpublished Work
# All Rights Reserved
# Licensed Material - Property of Tivoli Systems, Inc.
#

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

USAGE="wpmsub profile-manager subscriber [ subscriber ... ]"

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

# Unregister the profile manager
wregister -u -r ProfileManager "$PMNAME#$IRONAME"

exit 0
