#!/usr/bin/perl
# begin_generated_IBM_copyright_prolog                             
#                                                                  
# This is an automatically generated copyright prolog.             
# After initializing,  DO NOT MODIFY OR MOVE                       
# **************************************************************** 
# Licensed Materials - Property of IBM                             
# 5724-Y95                                                         
# (C) Copyright IBM Corp.  2014, 2014    All Rights Reserved.      
# US Government Users Restricted Rights - Use, duplication or      
# disclosure restricted by GSA ADP Schedule Contract with          
# IBM Corp.                                                        
#                                                                  
# end_generated_IBM_copyright_prolog                               

## lifted from old streamtool X-stream-envs cmd used only by streamsprofile.sh
# be careful and retain the exact pathname streamsetup was invoked
# with if possible.  The concern is maintaining support for the
# current "all hosts must use the same STREAMS_INSTALL" requirement
# in conjunction with a desire to support the "hetero install via symlinks" hack
# (e.g., /tmp/Distillery slink's to host specific bits and we need STREAMS_INSTALL
# to retain the value /tmp/Distillery when /tmp/Distillery/streatool is invoked.
#
# Even when streamtool is invoked via an absolute pathname, FindBin seems to
# resolve the input pathname, whereas File::Spec seems to preserves an input
# absolute pathname.

use File::Basename;
use File::Temp qw/ tempfile tempdir /;
use Cwd;

use FindBin;                
use lib $FindBin::Bin;  # this allows us to find setupUtils ie adds this modules current installed dir to perl @INC?
use setupUtils;

my $DBIN;


my $binDir = File::Basename::dirname($0);
if ($binDir eq '.') {
    $binDir = Cwd::getcwd();
}

my $installDirAbsPname = File::Spec->rel2abs(File::Basename::dirname($binDir));
$DBIN = $binDir; 
my %exportsHt = setupUtils::getInstallEvs($installDirAbsPname);
foreach my $evName (keys(%exportsHt)) {
     my $evVal = $exportsHt{$evName};
     print "export $evName=\"$evVal\"\n"; # need quotes for sh
}

my $iid = "";
my $did = ""; 
my $index = 0;
my $reset = 0;
$iid = $ENV{STREAMS_INSTANCE_ID};
$iid = $ENV{STREAMS_DEFAULT_IID} if ($iid eq '');
$did = $ENV{STREAMS_DOMAIN_ID};
foreach my $ARGV (@ARGV) {
	if ($ARGV[$index] eq '-i') {
	   $iid = $ARGV[$index+1];
	   $index += 1;
	} elsif ($ARGV[$index] eq '-d') {
           $did = $ARGV[$index+1];
	   $index += 1;
	}
	elsif ($ARGV[$index] eq '--default-iid') {
	    $reset = 1;           
	}
	$index += 1;
}
$iid = "StreamsInstance" if ( $iid eq "" | $reset eq 1);
$did = "StreamsDomain" if ( $did eq "" | $reset eq 1); 
print "export STREAMS_INSTANCE_ID=$iid\n";
print "export STREAMS_DOMAIN_ID=$did\n";
exit $rc;

