[Bio] / FigCommon / make_sandbox.pl Repository:
ViewVC logotype

View of /FigCommon/make_sandbox.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (download) (as text) (annotate)
Mon Mar 3 20:40:03 2008 UTC (11 years, 8 months ago) by olson
Branch: MAIN
CVS Tags: mgrast_dev_08112011, rast_rel_2009_05_18, mgrast_dev_08022011, rast_rel_2014_0912, rast_rel_2008_06_18, rast_rel_2008_06_16, mgrast_dev_05262011, rast_rel_2008_12_18, mgrast_dev_04082011, rast_rel_2008_07_21, rast_rel_2010_0928, rast_2008_0924, mgrast_version_3_2, mgrast_dev_12152011, rast_rel_2008_04_23, help, mgrast_dev_06072011, rast_rel_2008_09_30, rast_rel_2009_0925, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, mgrast_rel_2008_0924, mgrast_rel_2008_1110_v2, rast_rel_2009_02_05, rast_rel_2011_0119, lwc, mgrast_rel_2008_0625, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, rast_rel_2008_10_09, mgrast_dev_04012011, rast_release_2008_09_29, mgrast_rel_2008_0806, mgrast_rel_2008_0923, mgrast_rel_2008_0919, rast_rel_2009_07_09, rast_rel_2010_0827, mgrast_rel_2008_1110, myrast_33, rast_rel_2011_0928, rast_rel_2008_09_29, mgrast_rel_2008_0917, rast_rel_2008_10_29, mgrast_dev_04052011, mgrast_dev_02222011, rast_rel_2009_03_26, mgrast_dev_10262011, rast_rel_2008_11_24, rast_rel_2008_08_07, HEAD
Changes since 1.7: +48 -5 lines
more cleanup.

#
# Copyright (c) 2003-2006 University of Chicago and Fellowship
# for Interpretations of Genomes. All Rights Reserved.
#
# This file is part of the SEED Toolkit.
# 
# The SEED Toolkit is free software. You can redistribute
# it and/or modify it under the terms of the SEED Toolkit
# Public License. 
#
# You should have received a copy of the SEED Toolkit Public License
# along with this program; if not write to the University of Chicago
# at info@ci.uchicago.edu or the Fellowship for Interpretation of
# Genomes at veronika@thefig.info or download a copy from
# http://www.theseed.org/LICENSE.TXT.
#

use strict;

use File::Spec;
use File::Copy;
use File::Basename;
use FileHandle;

#
# Assemble a FIGdisk sandbox from the current release data.
#
# Create the base directory structure.
# Symlink to Data, env, and BLASTMAT.
# Download latest snapshot and install.
# Snapshot the postgres db for the current FIGdisk.
# Run configure.
#
# If this is called with -duplicate, don't link into the
# source FIGdisk, but replicate as needed.
#

my $username = (getpwuid($>))[0];
my $cvsroot = ":ext:$username\@biocvs.mcs.anl.gov:/disks/cvs/bio";
my $cvs_packages = "seed_base";

my $make_duplicate;
my $rel;
my $makeCVS = 0;
my $config_file;

while ($ARGV[0] =~ /^-/)
{
    my $arg = shift;
    if ($arg eq '-duplicate')
    {
	$make_duplicate = 1;
    }
    elsif ($arg eq '-cvsroot')
    {
	$cvsroot = shift;
    }
    elsif ($arg eq '-cvspkgs')
    {
	$cvs_packages = shift;
	$makeCVS = 1;
    }
    elsif ($arg eq '-rel')
    {
	$rel = shift;
    }
    elsif ($arg eq '-config')
    {
	$config_file = File::Spec->rel2abs(shift);
    }
}

if (@ARGV != 1)
{
    print STDERR "Usage: $0 [-duplicate] [-cvsroot] [-cvspkgs] [-rel relname] [-config config-file] target-directory\n";
    exit;
}

$| = 1;

my($target_dir) = @ARGV;
$target_dir = File::Spec->rel2abs($target_dir);

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

print "Create '$target_dir'\n";

mkdir($target_dir) or die "mkdir $target_dir: $!";

chdir($target_dir) or die;
mkdir("FIG") or die;
mkdir("FIG/Tmp") or die;
chmod(0777, "FIG/Tmp") or die;

mkdir("dist") or die;
mkdir("dist/releases") or die;

my $config_arch;
if ($make_duplicate)
{
    my $fd = $FIG_Config::fig_disk;

    if ($FIG_Config::env_config_type eq 'config_file')
    {
	#
	# Need to ensure target env dir is a directory, and copy the config file there.
	# The architecture named on the configure script invocation becomes the
	# name of the config file.
	#

	mkdir("env") or die "cannot mkdir env: $!\n";
	$config_arch = basename($FIG_Config::env_config_file);
	
	copy("$FIG_Config::env_config_file", "env/$config_arch") or die "Error copying $FIG_Config::env_config_file to env/$config_arch: $!";
    }
    else
    {
	if (-l "$fd/env")
	{
	    my $targ = readlink("$fd/env");
	    print "$fd/env is a link, linking to $targ\n";
	    symlink($targ, "env") or die "cannot symlink $targ $fd/env: $!\n";
	}
	elsif (-d "$fd/env" and -l (my $l = "$fd/env/$FIG_Config::arch"))
	{
	    my $targ = readlink($l);
	    print "env/arch is a link, linking $l $targ\n";
	    mkdir("env") or die "cannot mkdir env: $!\n";
	    symlink($targ, "env/$FIG_Config::arch") or die "cannot sy mlink $targ env/$FIG_Config::arch: $!\n";
	}
    }

    my $bl = "$fd/BLASTMAT";
    while (-l $bl)
    {
	$bl = readlink($bl);
    }
    system("cp", "-rp", $bl, ".");

    my $data = `cd $FIG_Config::data; /bin/pwd`;

    if ($data)
    {
	chomp $data;
    }
    else
    {
	$data =$FIG_Config::data;
    }

    symlink($data, "FIG/Data") or die "cannot symlink $data FIG/Data: $!\n";
}
else
{
    symlink("$FIG_Config::fig_disk/env", "env") or 
	die "symlink $FIG_Config::fig_disk/env failed";
    symlink("$FIG_Config::fig_disk/BLASTMAT", "BLASTMAT") or 
	die "symlink $FIG_Config::fig_disk/BLASTMAT failed";
    symlink("$FIG_Config::fig_disk/FIG/Data", "FIG/Data") or 
	die "symlink $FIG_Config::fig_disk/FIG/Data failed";
}

my $cvs_warn = 0;
if ($ENV{CVS_RSH} != "ssh")
{
    $cvs_warn = 1;
    $ENV{CVS_RSH} = "ssh";
}

open(OUT, ">config.out");
OUT->autoflush(1);

chdir("dist/releases") or die;

if ($makeCVS)
{
    $rel = "dev" unless $rel;
    mkdir($rel) or die;
    chdir($rel) or die;

    my $cmd = "cvs -d $cvsroot co $cvs_packages";
    print "Checking out code with $cmd:\n";
    print OUT "Checking out code with $cmd\n";

    if (!open(CPIPE, "$cmd 2>&1| "))
    {
	print OUT "Error running $cmd pipe: $!\n";
	die "Error running $cmd pipe: $!\n";
    }
    while (<CPIPE>)
    {
	print OUT $_;
	print "." if $. % 50 == 0;
    }
    print ". done\n";
    my $ex = close(CPIPE);
    
    if (!$ex)
    {
	my $errmsg;
	if ($!)
	{
	    $errmsg = "Error closing pipe from $cmd: $!\n";
	}
	else
	{
	    $errmsg = "Bad exit status $? from $cmd\n";
	}
	print OUT $errmsg;
	close(OUT);
	die $errmsg;
    }
    else
    {
	print OUT "Successful checkout\n";
    }
}
else
{
    $rel = `curl http://www-unix.mcs.anl.gov/~olson/SEED/CURRENT_RELEASE`;
    chomp $rel;

    system("curl http://www-unix.mcs.anl.gov/~olson/SEED/code-$rel.tgz| tar xfz -");
    if ($? != 0)
    {
	warn "download of release failed\n";
    }
}
chdir($rel);
copy("FigCommon/configure", "$target_dir/configure") or die;
chmod(0755, "$target_dir/configure") or die;
copy("ReleaseTools/Makefile.top", "Makefile") or die;

open(F, ">$target_dir/DEFAULT_RELEASE") or die "open $target_dir/RELEASE failed: $!";
print F "$rel\n";
close(F);

#
# Determine arch name.
#

my $arch;
open(FH, "<$FIG_Config::fig_disk/config/fig-user-env.sh");
while (<FH>)
{
    chomp;
    if (/^RTARCH=\"(.*)\"/)
    {
        $arch = $1;
        last;
    }
}

if (!$arch)
{
    die "Couldn't determine FIG architecture name\n";
}

chdir($target_dir) or die;

if (!$make_duplicate)
{
    
    $ENV{FIGCONFIG_DBNAME} = "fig_dev";
    $ENV{FIGCONFIG_DBPORT} = 10000;
    $ENV{FIGCONFIG_DBBUFS} = 300;
    $ENV{FIGCONFIG_SANDBOX} = $username;
}

$config_arch = $arch if $config_arch eq '';

my $here = `pwd`;
chomp $here;
my $cmd = "./configure $config_arch";

print OUT "Beginning configuration in $here with command:\n";
print OUT "\t$cmd\n";
print "Beginning configuration in $here with command:\n";
print "\t$cmd\n";
open(CPIPE, "$cmd 2>&1 |");

while (<CPIPE>)
{
    print OUT $_;
    print "." if $. % 100 == 0;
}
print ". done\n";

my $ex = close(CPIPE);

if (!$ex)
{
    my $errmsg;
    if ($!)
    {
	$errmsg = "Error closing pipe from $cmd: $!\n";
    }
    else
    {
	$errmsg = "Bad exit status $? from $cmd\n";
    }
    print OUT $errmsg;
    close(OUT);
    die $errmsg;
}
close(OUT);

# my $sedcmd =" -e '/temp_url/s,FIG-Tmp,$username/FIG-Tmp,' -e '/cgi_url/s,FIG,$username/FIG,' -e '/temp_base/s,FIG-Tmp,$username/FIG-Tmp,' -e '/cgi_base/s,FIG,$username/FIG,' -e '/dbuser/s,$username,fig,'";
# print "$sedcmd\n";

# chdir("config") or die;
# copy("FIG_Config.pm", "FIG_Config.pm.bak");
# copy("FIG_Config.py", "FIG_Config.py.bak");
# system("sed $sedcmd < FIG_Config.pm.bak > FIG_Config.pm");
# system("sed $sedcmd < FIG_Config.py.bak > FIG_Config.py");

if (-f $config_file)
{
    rename("config/FIG_Config.pm", "config/FIG_Config.pm.orig") or die "rename config failed: $!\n";
    open(C, "<$config_file") or die "cannot open $config_file: $!\n";
    open(F, "<config/FIG_Config.pm.orig") or die "cannot open config/FIG_Config.pm.orig: $!\n";
    open(T, ">config/FIG_Config.pm") or die "cannot open config/FIG_Config.pm: $!\n";
    while (<F>)
    {
	next if /^\s*1;/;
	print T $_;
    }
    while (<C>)
    {
	print T $_;
    }
    print T "\n1;\n";
    close(T);
    close(C);
    close(F);
}

print "Need to run :\n";
print "mkdir /var/www/html/$username\n";
print "ln -s $target_dir/FIG/CGI /var/www/html/$username/FIG\n";
print "ln -s $target_dir/FIG/Tmp /var/www/html/$username/FIG-Tmp\n";

exit;
__DATA__

open(F, ">DEFAULT_RELEASE");
print F "$code_version\n";
close(F);



(system("cd dist/releases; tar zxf $code_file") == 0) or die "Extract of code from $code_file failed: $!\n";

copy("dist/releases/$code_version/FigCommon/configure", "configure");
chmod(0755, "configure");

copy("dist/releases/$code_version/ReleaseTools/Makefile.top", "dist/releases/$code_version/Makefile");

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3