Commit cb4e22dd authored by Leigh Stoller's avatar Leigh Stoller

Add -s option to get just the sig file for an image (use with -r).

Also fix bug in how imagevalidate is invoked, which resulted in the
hash being computed for the previous version of the image, not the
new version.
parent 28d23b05
......@@ -46,13 +46,15 @@ sub usage()
print(" -i name - Use name for imagename.\n".
" Defaults to name in the desciptor\n");
print(" -r - Refresh (update ndz file) imported image.\n");
print(" -s - With -r just update the sig file\n");
exit(-1);
}
my $optlist = "dvu:p:gi:Ir";
my $optlist = "dvu:p:gi:Irs";
my $debug = 0;
my $verify = 0;
my $getimage= 0;
my $update = 0;
my $dosig = 0;
my $force = 0;
my $user;
my $group;
......@@ -120,6 +122,7 @@ sub FetchMetadata($);
sub CreateImage($$$$$);
sub DownLoadImage($$$$);
sub FetchImageFile($$);
sub FetchSigFile($);
#
# There is no reason to run as root unless we need to ssh over
......@@ -144,6 +147,9 @@ if (defined($options{"v"})) {
if (defined($options{"g"})) {
$getimage = 1;
}
if (defined($options{"s"})) {
$dosig = 1;
}
if (defined($options{"i"})) {
$imagename = $options{i};
}
......@@ -326,11 +332,11 @@ if ($getimage) {
$image->Unlock();
exit(1);
}
# Update DB info. Use the hash we were given, no need to recalculate.
my $imageid = $image->imageid();
# Update DB info.
my $versname = $image->versname();
# Run as root to access /proj
$EUID = $UID = 0;
if (system("$IMAGEVALIDATE -uq $imageid")) {
if (system("$IMAGEVALIDATE -u $versname")) {
# XXX should this be fatal?
print STDERR "Could not update DB info for $image\n";
}
......@@ -345,6 +351,10 @@ if ($getimage) {
$EUID = $UID = $SAVEUID;
$image->Unlock();
}
elsif ($update && $dosig) {
FetchSigFile($image) == 0
or exit(1);
}
else {
print "Not downloading image ... add -g option\n";
}
......@@ -556,16 +566,7 @@ sub DownLoadImage($$$$)
# fail, which is okay since Mike says we can generate a new one,
# it just takes a while to do.
#
$image_url = uri_unescape($image->imagefile_url()) . "&sigfile=1";
$localfile = $image->path() . ".sig.new";
my $sigfile= $image->path() . ".sig";
if (! FetchImageFile($image_url, $localfile)) {
system("/bin/mv -f $localfile $sigfile");
# Do not need this.
unlink("${localfile}.sha1")
if (-e "${localfile}.sig.sha1");
}
FetchSigFile($image);
return 0;
}
......@@ -671,6 +672,25 @@ sub FetchMetadata($)
return $xmlparse;
}
#
# Fetch sig file.
#
sub FetchSigFile($)
{
my ($image) = @_;
my $image_url = uri_unescape($image->imagefile_url()) . "&sigfile=1";
my $localfile = $image->path() . ".sig.new";
my $sigfile = $image->path() . ".sig";
if (! FetchImageFile($image_url, $localfile)) {
system("/bin/mv -f $localfile $sigfile");
# Do not need this.
unlink("${localfile}.sha1")
if (-e "${localfile}.sha1");
}
return 0;
}
sub fatal($)
{
my ($mesg) = @_;
......
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