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


#This script will create the policy region and collection for a new solution
#product

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

ETC=`odadmin environ get | grep '^ETC=' | awk -F= '{print \$2'}`

if [ -z "$ETC" ] ; then
	ETC=/etc
	if [ x"$OS" = x"Windows_NT" ] ; then
		ETC=$SystemRoot/system32/drivers/etc
	fi
fi

. $ETC/Tivoli/setup_env.sh

TEMP=/tmp
if [ x"$OS" = x"Windows_NT" ]; then
	TEMP=$DBDIR/tmp
else
	TEMP=/tmp
fi
export TEMP

if [ ! -d $TEMP ]; then
	mkdir -p $TEMP
fi

OSERV=`objcall 0.0.0 get_oserv`
INST_DIR=`objcall $OSERV query install_dir`
INST_DIR=`echo $INST_DIR | tr "\\\\\\\\" "/"`
LINK_DIR=$INST_DIR/generic_unix/TME/PLUS/LINK

#Determine the name of the top level PolicyRegion to use
if [ x"$TOP_PR_TO_USE" = x ] ; then
	TIVOLI_SOLUTIONS="TivoliPlus"
else
	TIVOLI_SOLUTIONS="$TOP_PR_TO_USE"
fi

#Dump GenericCollection dialog file
wgetdialog -I normal -r GenericCollection > $TEMP/dialog.d

#Add a state to Generic Collection for this Solution
if [ x"$COLL_ICON_TO_USE" = x ] ; then
	COLL_ICON_TO_USE=$LINK_DIR/Sol_icon.xpm
fi

if [ x"$NEW_COLL_STATE" = x ] ; then
	NEW_COLL_STATE=TSCOLL
fi

$LINK_DIR/waddstate GenericCollection "$NEW_COLL_STATE" $TEMP/dialog.d $COLL_ICON_TO_USE

rm $TEMP/dialog.d


#Create Solutions Collection
LIBRARY=`wlookup Library`
COLLECTIONGUI=`idlcall $LIBRARY lookup_object '"imp_TMF_TGC::CollectionGUI" {0}'`
COLLOBJ=`idlcall $COLLECTIONGUI lookup_object '"'$TIVOLI_SOLUTIONS'" {0}'`
if [ $? -ne 0 ] ; then
	COLLOBJ=`idlcall $COLLECTIONGUI create_instance  'OBJECT_NIL OBJECT_NIL "'$TIVOLI_SOLUTIONS'"'`
fi

idlcall $COLLOBJ  _set_state '"'$NEW_COLL_STATE'"'

# Get the collection on this admins desktop
ALI=`wlookup TME_server`
for var in `objcall $ALI get_identity`; do ADMIN=$var; done
if [ "$ADMIN" ]; then
  gcoadd $ADMIN $COLLOBJ
  #Refresh the desktop
  idlcall $ADMIN refresh_collection

  exit 0
else
  exit 1
fi 
