#!/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-2000
# 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


#
#       Set up environment (similar to old /etc/Tivoli/setup_env.sh)
#
OSERV=`objcall 0.0.0 get_oserv`; export OSERV
INST_DIR=`objcall $OSERV query install_dir | tr "\\\\\\\\" "/"`; export INST_DIR
INTERP=`objcall $OSERV query interp`; export INTERP
BINDIR=$INST_DIR/$INTERP; export BINDIR
LINK_DIR=$INST_DIR/generic_unix/TME/PLUS/LINK; export LINK_DIR
DBDIR=`objcall $OSERV query db_dir | tr "\\\\\\\\" "/"`; export DBDIR
TEMP=/tmp; export TEMP
if [ x"$OS" = x"Windows_NT" ]; then
	TEMP=$DBDIR/tmp
fi
if [ ! -d $TEMP ]; then
	$LINK_DIR/mkdir.sh $TEMP
fi


#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 
