Index: trunk/ippScripts/scripts/dist_bundle.pl
===================================================================
--- trunk/ippScripts/scripts/dist_bundle.pl	(revision 28753)
+++ trunk/ippScripts/scripts/dist_bundle.pl	(revision 28942)
@@ -58,4 +58,5 @@
 my $missing_tools;
 my $streaksrelease   = can_run('streaksrelease') or (warn "Can't find streaksrelease" and $missing_tools = 1);
+my $bgtool   = can_run('bgtool') or (warn "Can't find bgtool" and $missing_tools = 1);
 if ($missing_tools) {
     warn("Can't find required tools.");
@@ -224,4 +225,48 @@
 }
 
+if (!$clean) {
+    if ($stage eq 'chip_bg') {
+        # add the variance file from the original chipRun
+        my $command = "$bgtool -listchip -chip_bg_id $stage_id -class_id $component";
+        $command .= " -dbname $dbname" if $dbname;
+        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run(command => $command, verbose => $verbose);
+        unless ($success) {
+            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+            &my_die("Unable to perform $command: $error_code", $component, $error_code);
+        }
+        my $mdcParser = PS::IPP::Metadata::Config->new; 
+        my $list = $mdcParser->parse( join "", @$stdout_buf) or 
+            &my_die("Unable to parse bgtool metadata", $component, $PS_EXIT_SYS_ERROR);
+        my $parsed = parse_md_list($list);
+
+        # result is an array with one element
+        my $chip_data = $parsed->[0];
+
+        my $chip_path_base = $chip_data->{path_base};
+        $variance = $ipprc->filename('PPIMAGE.CHIP.VARIANCE', $chip_path_base, $component) or
+            &my_die("Unable to resolve variance file name from $chip_path_base", $component, $PS_EXIT_SYS_ERROR);
+
+    } elsif ($stage eq 'warp_bg') {
+        # add the variance file from the original warpRun
+        my $command = "$bgtool -listwarp -warp_bg_id $stage_id -skycell_id $component";
+        $command .= " -dbname $dbname" if $dbname;
+        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run(command => $command, verbose => $verbose);
+        unless ($success) {
+            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+            &my_die("Unable to perform $command: $error_code", $component, $error_code);
+        }
+        my $mdcParser = PS::IPP::Metadata::Config->new; 
+        my $list = $mdcParser->parse( join "", @$stdout_buf) or 
+            &my_die("Unable to parse bgtool metadata", $component, $PS_EXIT_SYS_ERROR);
+        my $parsed = parse_md_list($list);
+        my $warp_data = $parsed->[0];
+        my $warp_path_base = $warp_data->{path_base};
+        $variance = $ipprc->filename('PSWARP.OUTPUT.VARIANCE', $warp_path_base) or
+            &my_die("Unable to resolve variance file name from $warp_path_base", $component, $PS_EXIT_SYS_ERROR);
+    }
+}
+
 if ($nan_masked_pixels) {
     # One last check as to whether magic has been applied to the inputs
@@ -239,4 +284,6 @@
         if (($stage ne "chip_bg") and ($stage ne "warp_bg")) {
             &my_die("no variance image found in file list", $component, $PS_EXIT_CONFIG_ERROR) if !$variance;
+        } else {
+            &my_die("variance is not defined", $component, $PS_EXIT_CONFIG_ERROR) if !$variance;
         }
     }
