#!/h/COE/Comp/PERL5/bin/perl -T -I/h/COE/lib  -w
use strict;
use Coe;

my $VERSION="1.1.4.0";
my $PRGM="COEListSegs";

sub useage {
  print "Useage: COEListSegs [flags]\n";
}

my $arg1;
my $file="";
my $flag="false";
my $flag31=0;
my $flagclass=0;
my $flaginstaller=0;
my $flagsortbyname=1;
my $flagsortbytype=0;
my $i=0;
my $ipaddr="127.0.0.1";
my $hostname="localhost";
my $path="";
my $ret;
my $seginfo="";
my $segname="";
my $segpath="";
my $segver="";
my $thisfile="";
my @class;
my @d;
my @date;
my @disk;
my @n;
my @segname;
my @segpath;
my @segtype;
my @t;
my @v;
my @version;
my @SEG;
	# SEG[0]=dummy field for sort
	# SEG[1]=segname
	# SEG[2]=segtype
	# SEG[3]=segpath
	# SEG[4]=version
	# SEG[5]=install date
	# SEG[6]=patches
	# SEG[7]=classification

sub openFile;
sub readFile;
sub getCoeHome;
sub getCoeAcct;
sub getCoeApps;
sub getCoeCots;
sub getCoeComp;
sub sortByField;

while (@ARGV > 0 ){
	$arg1=shift;
	$arg1=cleanString($arg1,4);
	if ("$arg1" eq "-h") {
		useage;
   		exit 0;
	} elsif ("$arg1" eq "-H") {
		coeMan("COE_HOME/docs/man/$PRGM");
   		exit 0;
	} elsif ("$arg1" eq "-V") {
   		print "VERSION: $VERSION\n";
   		exit 0;
	} elsif ("$arg1" eq "-31") {
		$flag31=1;
	} elsif ("$arg1" eq "--installer") {
		$flaginstaller=1;
	} elsif ("$arg1" eq "-i") {
		$ipaddr=cleanString(shift,4);
	} elsif ("$arg1" eq "-n") {
		$hostname=cleanString(shift,4);
	} elsif ("$arg1" eq "-sn") {
		$flagsortbyname=1;
	} elsif ("$arg1" eq "-st") {
		$flagsortbytype=1;
	} else {
		coeMan("COE_HOME/docs/man/$PRGM");
   		exit -1;
	}
}

#my @SEGPATH=("/h", "/h/COTS", "/h/AcctGrps", "/h/COE/Comp") ;
my @SEGPATH=(getCoeApps, getCoeCots, getCoeAcct, getCoeComp, getCoeHome) ;

# --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----|
# Standard Output
# --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----|
# The IP Address of this machine is : 
# The Host name of this machine: # The number of installed segments on this machine is : # SegName:Type:SegDir:Version:Date:[Patches] # --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----| # COE 3.1 Output # --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----| # output header -- style COE 3.1 #
: # # index : segment_name : segment_type : home_directory : # segment_version : date_of_installation : patches # --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----| $i=-1; foreach (@SEGPATH) { $path = coeFileConv("$_"); opendir DIR, "$path" || die "$0: cannot open dir $path: $_\n"; while ($file = readdir DIR) { if ("$file" !~ /^\./) { $thisfile = "$path/$file/SegDescrip/Installed"; $thisfile = coeFileConv($thisfile); if (-e "$thisfile") { my $FILE = readFile("$thisfile"); while (<$FILE>) { if ("$_" ne "not installed") { $i++; # - inititialize record $SEG[0][$i]=""; $SEG[1][$i]=""; $SEG[2][$i]=""; $SEG[3][$i]=""; $SEG[4][$i]=""; $SEG[5][$i]=""; $SEG[6][$i]=""; $SEG[7][$i]=""; # get Date chomp($_); $SEG[5][$i]=$_; # get SegName and SegType $SEG[3][$i]=coeFileConv("$path/$file"); $segname=coeFileConv("$path/$file/SegDescrip/SegName"); my $SEGNAME=readFile("$segname"); while (<$SEGNAME>) { if (/\$NAME/) { @n=split(":"); chomp($n[1]); $SEG[1][$i]=$n[1]; } elsif (/\$TYPE/) { @t=split(":"); chomp($t[1]); $SEG[2][$i]=$t[1]; } } close $SEGNAME; # get Version $segver=coeFileConv("$path/$file/SegDescrip/VERSION"); my $VERS=readFile("$segver"); while (<$VERS>) { if (! /^#/ && /^.*:/) { @v=split(":"); chomp$v[0]; $SEG[4][$i]=$v[0]; } } close $VERS; # get classification and disk size $SEG[7][$i]="UNCLASS"; $disk[$i]="0"; $seginfo=coeFileConv("$path/$file/SegDescrip/SegInfo"); my $SEGINFO=readFile("$seginfo"); while (<$SEGINFO>) { if (/\$DISK/) { @d=split(":"); chomp($d[1]); $disk[$i]=$d[1]; } elsif (/\[Classification]/) { $flagclass=1; } elsif ($flagclass == 1) { chomp($_); $SEG[7][$i]=$_; $flagclass=0; } } } } } } } closedir DIR; } if ($flagsortbytype == 1) { @SEG = sortByField 2, @SEG; } else { @SEG = sortByField 1, @SEG; } if ($flag31 == 1) { print "\n"; print "$ipaddr:$hostname\n"; print "$i\n"; print "\n"; $i=0; foreach (@SEG) { print "$i: $SEG[1][$i] : $SEG[2][$i] : $SEG[3][$i] : $SEG[4][$i] : $SEG[5][$i]\n"; $i++; } } elsif ($flaginstaller == 1 ) { $i=0; foreach (@SEG) { if ($SEG[2][$i]) { print "$SEG[2][$i] : $SEG[1][$i] : $SEG[4][$i] : $SEG[7][$i] : $disk[$i] : $SEG[3][$i] :\n"; $i++; } } } else { print "\n"; print "The IP Address of this machine is : $ipaddr\n"; print "The Host name of this machine: $hostname\n"; print "The number of installed segments of this machine is :$i\n"; print "\n"; $i=0; foreach (@SEG) { if ($SEG[1][$i]) { print "$i:$SEG[1][$i]:$SEG[2][$i]:$SEG[3][$i]:$SEG[4][$i]: $SEG[5][$i]:\n"; $i++; } } } exit 0; # ============================================================================== sub sortByField { my ($field, @s)=@_; my @segs; my @segss; #$field=2; $i=0; foreach (@s) { if ($s[$field][$i]) { $segs[$i]="$s[$field][$i]\^$s[1][$i]\^$s[2][$i]\^$s[3][$i]\^$s[4][$i]\^$s[5][$i]\^$s[6][$i]\^$s[7][$i]"; $i++; } } @s = sort @segs; $i=0; foreach (@s) { @segs=split('\^'); $segss[0][$i]=$segs[0]; $segss[1][$i]=$segs[1]; $segss[2][$i]=$segs[2]; $segss[3][$i]=$segs[3]; $segss[4][$i]=$segs[4]; $segss[5][$i]=$segs[5]; $segss[6][$i]=$segs[6]; $segss[7][$i]=$segs[7]; $i++; } #$i=0; #foreach (@segss) { #print "$segss[1][$i] $segss[2][$i]\n"; #$i++; #} return @segss; }