[Bio] / FigRelEngTools / InstallSEED Repository:
ViewVC logotype

View of /FigRelEngTools/InstallSEED

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (annotate)
Thu Jan 15 19:04:01 2004 UTC (15 years, 6 months ago) by olson
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +90 -2 lines
more fixes.

#!/usr/bin/perl

use strict;

#
# Install a SEED from distribution media.
#

#
# We expect to get a single argument, the target directory.
#

if (@ARGV != 1)
{
    die "Usage: InstallSEED target-directory\n";
}

#
# We need to set this so the data extraction is happy.
#

$ENV{LANG} = "C";

my $target_dir = shift(@ARGV);
my $pwd = `pwd`;
chop($pwd);

if (-d $target_dir)
{
    die "Installation directory $target_dir already exists\n";
}

mkdir($target_dir) or die "Cannot create target directory $target_dir: $!\n";

#
# We expect to find a file called MANIFEST in this directory. Verify the 
# contents of the directory against the manifest.
#

&verify_manifest(".", "MANIFEST");

#
# Extract the installation scripts.
#

(system("tar xzf scripts.tgz") == 0) or die "Extraction of installation scripts failed";

#
# Assemble a skeleton SEED.
#

#
# Determine the names of the environment/code/blastmat tarfiles.
#

my($env_file, $code_file, $blastmat_file);

my @a;
@a = glob("env*.tgz");
if (@a == 0)
{
    die "No environment distribution file found\n";
}
elsif (@a > 1)
{
    @a = sort(@a);
    $env_file = $a[$#a];
    
    warn "Multiple environment distribution files found, using $env_file\n";
}
else
{
    $env_file = $a[0];
}

@a = glob("code*.tgz");
if (@a == 0)
{
    die "No code distribution file found\n";
}
elsif (@a > 1)
{
    @a = sort(@a);
    $code_file = $a[$#a];
    
    warn "Multiple code distribution files found, using $code_file\n";
}
else
{
    $code_file = $a[0];
}

@a = glob("BLASTMAT*.tgz");
if (@a == 0)
{
    die "No BLASTMAP distribution file found\n";
}
elsif (@a > 1)
{
    @a = sort(@a);
    $blastmat_file = $a[$#a];
    
    warn "Multiple blastmat distribution files found, using $blastmat_file\n";
}
else
{
    $blastmat_file = $a[0];
}

print "Environment distribution: $env_file\n";
print "Code distribution: $code_file\n";
print "BLASTMAT distribution: $blastmat_file\n";

(system("cd $target_dir; $pwd/assemble_disk $pwd/$env_file $pwd/$code_file $pwd/$blastmat_file") == 0) or
    die "Assemble_disk failed: $!\n";

#
# Now extract the data.
#
# We expect the data to be in the current directory as well, and 
# that there will be a file called checksums that is a manifest
# of the data files. 
#
# We can assume the checksums file is here: it should have been
# included in the toplevel MANIFEST that we checked for earlier.
#
# We will invoke extract_transferred_data. It is run with the
# current directory set to the place to which the data
# should be extracted. This should be the FIG directory
# in the new FIGdisk tree.
#
# We will have to get a listing of the files in the FIG directory
# before and after the extract, in order to determine exactly
# the name of the extracted directory. If it's not named Data,
# rename. Verify the directory has the files we want.
#

{
    my $fig_dir = "$target_dir/FIG";
    if (! -d $fig_dir)
    {
	warn "FIG directory $fig_dir does not exist: assemble_disk should have created this\n";
	mkdir($fig_dir);
    }

    my(%files_before, @files_before, @files_after, @new_files);

    opendir(D, "$fig_dir") or die "Could not opendir $fig_dir: $!";
    @files_before = readdir(D);
    closedir(D);
    map { $files_before{$_}++ } @files_before;

    #
    # Do the extract.
    #

    (system("cd $fig_dir; $pwd/extract_transferred_data $pwd") == 0)
	or die "Data extraction failed\n";

    opendir(D, "$fig_dir") or die "Could not opendir $fig_dir: $!";
    @files_after = readdir(D);
    closedir(D);

    #
    # Collect new files.
    #
    for my $file (@files_after)
    {
	if (!$files_before{$file})
	{
	    push(@new_files, $file);
	}
    }

    if (@new_files == 0)
    {
	warn "No data directory created after extraction!\n";
    }
    elsif (@new_files > 1)
    {
	warn "Data extraction created multiple directories, examine $fig_dir by hand.\n";
    }
    else
    {
	#
	# Single new file created, this is the correct case.
	#

	my $file = $new_files[0];

	if ($file ne "Data")
	{
	    #
	    # Rename to be Data
	    #

	    rename("$fig_dir/$file", "$fig_dir/Data") or
		warn "Could not rename $fig_dir/$file to $fig_dir/Data\n";
	}
	
    }
}
    

sub verify_manifest
{
    my($dir, $manifest) = @_;

    #
    # A manifest contains one line per file of the form
    #   checksum size filename
    #

    my($fh);
    open($fh, "<$manifest") or die "Cannot open manifest $manifest: $!";

    while (<$fh>)
    {
	chop;
	my($checksum, $size, $file) = split(/\s+/, $_, 3);

	my $s = -s $file;

	if (!$s)
	{
	    die "verify_manifest: file $file not found \n";
	}
	if ($s != $size)
	{
	    die "verify_manifest: file $file is of the wrong size ($s should be $size\n";
	}

	my $cfh;
	open($cfh, "cksum $file|") or die "verify_manifest: cannot run cksum $file: $!";
	my $c = <$cfh>;
	chop($c);
	my($mck, $msz, $mfile) = split(/\s+/, $c, 3);
	if ($mck ne $checksum)
	{
	    die "verify_manifest: $file has incorrect checksum ($mck should be $checksum)\n";
	}
	close($cfh);
    }
    close($fh);
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3