Commit 603b59f9 authored by Leigh Stoller's avatar Leigh Stoller

Add ability to check out a specific source tag from the mirrored CVS

tree we keep on boss (which is update each night). Still need to
arrange for tmcd to pass back CVSSRCTAG=xyz in the emulabconfig
request, but if it did, that tag is passed along to the web interface,
which calls new backend script to do the checkout, tar it up, gzip
it, and spit to stdout.
parent 5f1de646
......@@ -1104,9 +1104,12 @@ sub GetEmulabSource($)
my $keyhash = `cat $keyfile`;
chomp($keyhash);
my $cvstag = (! defined($emulabconfig{"CVSSRCTAG"}) ? "" :
"&cvstag=" . $emulabconfig{"CVSSRCTAG"});
mysystem("fetch -q -o /tmp/foo.tar.gz ".
"'https://${bossname}/spewrpmtar.php3?nodeid=${nodeid}&".
"key=${keyhash}&elabinelab_source=1'");
"'https://${bossname}/spew.php3?nodeid=${nodeid}&".
"key=${keyhash}&elabinelab_source=1${cvstag}'");
mysystem("tar xzf /tmp/foo.tar.gz -C $destdir/testbed");
}
......
......@@ -21,7 +21,7 @@ SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \
opsreboot deletenode node_statewait grabwebcams \
grabswitchconfig backupswitches
LIBEXEC_SCRIPTS = webcreateimage newnode webdeletenode spewleds webcopy \
websetdest
websetdest spewsource
#
# Force dependencies on the scripts so that they will be rerun through
......
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Getopt::Std;
#
# Spew a source code tarball in gzip format. Used by the web interface
#
sub usage()
{
print(STDOUT
"Usage: spewsource [-t tag] [-o file]\n" .
"-t <tag> - Specify CVS tag\n");
exit(-1);
}
my $optlist = "t:o:";
my $tag = "HEAD";
my $output;
#
# Configure variables
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $CVS = "/usr/bin/cvs";
my $TAR = "/usr/bin/tar";
my $GZIP = "/usr/bin/gzip";
my $CVSREPO = "/usr/testbed/CVS";
# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/usr/site/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Turn off line buffering on output. Very important for this script!
#
$| = 1;
# Load the Testbed support stuff.
use lib "@prefix@/lib";
use libdb;
use libtestbed;
# Be careful not to exit on transient error
$libdb::DBQUERY_MAXTRIES = 30;
#
# Locals
#
my $logfile;
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"t"})) {
$tag = $options{"t"};
# Untaint of course.
if ($tag =~ /^([-\w\.]*)$/) {
$tag = $1;
}
else {
die("*** $0:\n".
" Bad data in tag: $tag\n");
}
}
if (defined($options{"o"})) {
$output = $options{"o"};
# Untaint of course.
if ($output =~ /^([-\w\.\/\+]*)$/) {
$output = $1;
}
else {
die("*** $0:\n".
" Bad data in output: $output\n");
}
}
#
# Make a temp directory.
#
$ENV{'TMPDIR'} = "/var/tmp";
my $tempdir = `mktemp -d -t tempsrc`;
if ($?) {
die("*** $0:\n".
" Could not create a temporary directory!\n");
}
if ($tempdir =~ /^([-\w\/\.]*)$/) {
$tempdir = $1;
}
else {
die("*** $0:\n".
" Bad data in tag: $tempdir\n");
}
#
# Check out the code.
#
system("$CVS -f -R -Qd $CVSREPO export -r $tag " .
"-d $tempdir testbed") == 0
or fatal("Failed to checkout testbed source code (tag $tag)!");
#
# Tar and gzip. Send to stdout (for web interface) unless an output file
# is specified.
#
system("$TAR --ignore-failed-read -cf - -C $tempdir . | gzip -c -1 ".
(defined($output) ? "> $output" : "")) == 0
or fatal("Failed to tar/gzip testbed source code (tag $tag)!");
if (defined($tempdir) && $tempdir ne "" && -d $tempdir) {
system("/bin/rm -rf $tempdir");
}
exit(0);
sub fatal($)
{
my($mesg) = $_[0];
if (defined($tempdir) && $tempdir ne "" && -d $tempdir) {
system("/bin/rm -rf $tempdir");
}
die("*** $0:\n".
" $mesg\n");
}
......@@ -78,6 +78,25 @@ if (strcmp($row["keyhash"], $key)) {
SPITERROR(403, "Wrong Key!");
}
#
# A cleanup function to keep the child from becoming a zombie, since
# the script is terminated, but the children are left to roam.
#
$fp = 0;
function SPEWCLEANUP()
{
global $fp;
if (!$fp || !connection_aborted()) {
exit();
}
pclose($fp);
exit();
}
ignore_user_abort(1);
register_shutdown_function("SPEWCLEANUP");
#
# Special case. If requesting elab source code, the experiment must
# be an elabinelab experiment.
......@@ -97,37 +116,49 @@ if (isset($elabinelab_source)) {
if ($row["elab_in_elab"] != "1") {
SPITERROR(403, "Not an elabinelab experiment!");
}
if (!is_readable("/usr/testbed/src/emulab-src.tar.gz")) {
SPITERROR(404, "Could not find $file!");
}
header("Content-Type: application/octet-stream");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
flush();
readfile("/usr/testbed/src/emulab-src.tar.gz");
exit(0);
}
#
# A cleanup function to keep the child from becoming a zombie, since
# the script is terminated, but the children are left to roam.
#
$fp = 0;
function SPEWCLEANUP()
{
global $fp;
if (!$fp || !connection_aborted()) {
exit();
#
# If a specific tag is requested, call out to the spewsource program.
# Otherwise send it the usual file.
#
if (isset($cvstag)) {
if (! preg_match("/^[-\w\@\/\.]+$/", $cvstag)) {
SPITERROR(400, "Invalid characters in cvstag!");
}
# Do it anyway.
$cvstag = escapeshellarg($cvstag);
if ($fp = popen("$TBSUEXEC_PATH $creator $pid,$unix_gid ".
"spewsource -t $cvstag", "r")) {
header("Content-Type: application/x-gzip");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
flush();
fpassthru($fp);
$fp = 0;
flush();
return;
}
else {
SPITERROR(404, "Could not find $file!");
}
}
else {
if (!is_readable("/usr/testbed/src/emulab-src.tar.gz")) {
SPITERROR(404, "Could not find $file!");
}
header("Content-Type: application/octet-stream");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
flush();
readfile("/usr/testbed/src/emulab-src.tar.gz");
exit(0);
}
pclose($fp);
exit();
}
ignore_user_abort(1);
register_shutdown_function("SPEWCLEANUP");
#
# MUST DO THIS!
......
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