#!/usr/bin/perl
# 4218585, 4540334

my $target = $ARGV[2];
my $pkg = $ARGV[0];

my $bom = $target .'/Library/Application Support/Apple/System Image Utility/Append.bom';
my @files = ("/System/Library/User Template");
my $nullbom = $pkg . "/Contents/Resources/nullbom";
my $insertFilesIntoBom = $pkg . "/Contents/Resources/insertFilesIntoBom";

if ( !-e $bom)
{
	##create it
	system("$nullbom",$bom);
	system("$insertFilesIntoBom",$bom,"/",".");
}

chdir($target);

foreach $file (@files)
{
	##This wont follow links presently
	my @parts = split('/',$file);
	shift(@parts);
	my $currentPath = ".";
	foreach $part (@parts)
	{
		$currentPath .= "/$part"; 
		system("$insertFilesIntoBom",$bom,"/",$currentPath);
	}
}

unlink($ENV{'RECEIPT_PATH'}."/nullbom");
unlink($ENV{'RECEIPT_PATH'}."/insertFilesIntoBom");
