#!/usr/bin/perl

# You *must* run this from the i386/RedHat/base directory!

# Directory containing workgroup directories relative to
# the current directory
$WorkgroupsDir = "../../Fermi/workgroups";

# The final output file, relative to the current directory
$MainCompsFile = "comps";

# The individual Workgroup comps files, relative to the
# $WorkgroupsDir/WORKGROUPNAME/ directory
$WorkgroupCompsFile = "default.rpm.list";

# This is the list of base RPMs
$BaseRPMList = "comps.base";

system("cp $BaseRPMList $MainCompsFile");
open (OUT, ">>$MainCompsFile") or die "Can't open output file: $MainCompsFile\n";

opendir (WGDIR, "$WorkgroupsDir") or die "Can't open Workgroups directory: $WorkgroupsDir\n";
while ($ThisWorkgroup = readdir(WGDIR)) {
   unless ($ThisWorkgroup =~ /^\./) {
   	print "Processing Workgroup: $ThisWorkgroup...";
   	open (FILE, "$WorkgroupsDir/$ThisWorkgroup/$WorkgroupCompsFile") or die "No list of RPMs for $ThisWorkgroup!\n";
   	print OUT "\n0 --hide $ThisWorkgroup\n";
   	print OUT <FILE>;
   	print OUT "end\n";
   	close (FILE);
   	print " Done.\n";
   }
}

print "\nAll Done.\nOutput file: $MainCompsFile\n\n";

close (OUT);

