Commit f2c59912 authored by Mike Hibler's avatar Mike Hibler

Employ Stupid Shell Tricks to get exit status out of pipeline command.

parent 49bf5b5c
......@@ -117,7 +117,7 @@ delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# No configure vars.
#
my $sudo;
my $sudo = "";
my $zipper = "/usr/local/bin/imagezip";
my $uploader = "/usr/local/bin/frisupload";
my $frisbee = "/usr/local/bin/frisbee";
......@@ -259,11 +259,16 @@ sub parse_params(@)
}
}
for my $path (qw#/usr/local/bin /usr/bin#) {
#
# If we are running as a user, then we will need sudo
#
if ($EUID != 0) {
for my $path (qw#/usr/local/bin /usr/bin#) {
if (-e "$path/sudo") {
$sudo = "$path/sudo";
last;
$sudo = "$path/sudo";
last;
}
}
}
#
......@@ -534,7 +539,7 @@ sub process_image($)
# frisupload -S $server -F $ifile -
# [ cat $localdir/$nsigfile | frisupload -S $server -F $nsigfile ]
#
my $cmd = "$zipper";
my $cmd = "$sudo $zipper";
if ($verbose) {
$cmd .= " -o";
}
......@@ -545,10 +550,10 @@ sub process_image($)
$cmd .= " -s " . $iinfo{$iid}{'part'};
}
if (exists($iinfo{$iid}{'sigfile'})) {
$cmd .= " -H /local/sigfile";
$cmd .= " -H $localdir/sigfile";
}
if (exists($iinfo{$iid}{'nsigfile'})) {
$cmd .= " -U /local/nsigfile";
$cmd .= " -U $localdir/nsigfile";
}
$cmd .= " " . $iinfo{$iid}{'disk'};
......@@ -557,14 +562,27 @@ sub process_image($)
$cmd .= " $image";
} elsif ($iinfo{$iid}{'method'} eq "frisbee") {
my $srv = $iinfo{$iid}{'server'};
$cmd .= " - | $uploader -S $srv -F $image -";
# use basic shell sleezy trick to capture exit status from imagezip
$cmd = "( $cmd - || echo \$? > $localdir/imagezip.stat )";
$cmd .= " | $uploader -S $srv -F $image -";
}
if (mysystem("$sudo $cmd")) {
if (mysystem("$cmd") || -e "$localdir/imagezip.stat") {
my $stat = sprintf("0x%04x", $?);
my $izstat = 0;
if (-e "$localdir/imagezip.stat") {
$izstat = `cat $localdir/imagezip.stat`;
chomp($izstat);
}
$izstat = sprintf("0x%04x", $izstat);
print STDERR "*** Failed to create image!\n";
print STDERR " command: '$sudo $cmd'\n";
print STDERR " status: $stat\n";
print STDERR " command: '$cmd'\n";
print STDERR " status: $stat\n";
print STDERR " izstatus: $izstat\n"
if ($izstat);
exit(3);
}
......@@ -579,7 +597,7 @@ sub process_image($)
}
}
mysystem("$sudo rm /local/*");
mysystem("$sudo rm $localdir/*");
}
sub mysystem($)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment