Commit ffde3e56 authored by Leigh Stoller's avatar Leigh Stoller

Support for tb-set-node-tarfiles. Everything but the front end parsing

code.
parent 847f0c95
......@@ -26,6 +26,7 @@ control-install:
client-install:
$(INSTALL_PROGRAM) create-delta /usr/local/bin/create-delta
$(INSTALL_PROGRAM) install-delta /usr/local/bin/install-delta
$(INSTALL_PROGRAM) install-tarfile /usr/local/bin/install-tarfile
clean: subdir-clean
......
#!/usr/bin/perl -wT
use English;
use Getopt::Std;
use POSIX 'setsid';
#
# Install a tarfile. This script is run from the setup code on client nodes.
#
# usage: install-tarfile <installdir> <filename>
#
# Exit Value Matters!: 0 if installed okay
# 1 if already installed
# -1 if something goes wrong.
#
# To ensure safety, the tar filename must start with /proj.
#
#
sub usage()
{
print STDOUT "Usage: install-tarfile <installdir> <filename>\n";
exit(-1);
}
my $optlist = "";
#
# Turn off line buffering on output
#
$| = 1;
#
# Untaint the path
#
$ENV{'PATH'} = "/bin:/sbin:/usr/bin:";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# No configure vars.
#
my $IDENTFILE = "/var/db/testbed.tarfiles";
my $tarfile = "";
my $decompressflag = "";
my $installdir = "/";
#
# Must be running as root to work.
#
if ($EUID != 0) {
die("Must be run as root! Try using sudo or su1!");
}
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (@ARGV != 2) {
usage();
}
$installdir = $ARGV[0];
$tarfile = $ARGV[1];
#
# Untaint the arguments.
#
# Note different taint check (allow /).
if ($tarfile =~ /^([-\w.\/]+)$/) {
$tarfile = $1;
}
else {
fatal("Tainted filename: $tarfile");
}
if ($installdir =~ /^([-\w.\/]+)$/) {
$installdir = $1;
}
else {
fatal("Tainted directory name: $installdir");
}
#
# The tarfile may only come from a /proj directory.
#
if (! ($tarfile =~ /^\/proj\//)) {
fatal("The tar file must reside in /proj");
}
#
# Make sure its really there.
#
if (! -r $tarfile) {
fatal("$tarfile does not exist or is not accessible!");
}
#
# Make sure the installdir exists!
#
if (! -d $installdir) {
fatal("$installdir does not exist or is not accessible!");
}
#
# Check to make sure this tarfile has not already been installed. Update
# the file now. If the tar fails, we got big problems.
#
if (-e $IDENTFILE) {
if (! `egrep -q -s '^${tarfile}' $IDENTFILE`) {
print STDOUT "Tarfile $tarfile has already been installed!\n";
exit(1);
}
}
system("echo \"$tarfile\" >> $IDENTFILE") == 0 or
fatal("Could not update $IDENTFILE");
#
# Figure what decompression flag is required, based on file extension.
#
SWITCH: for ($tarfile) {
/^.*\.tar\.Z$/ && do {$decompressflag = "-Z"; last SWITCH; } ;
/^.*\.tar\.gz$/ && do {$decompressflag = "-z"; last SWITCH; } ;
/^.*\.tar\.tgz$/ && do {$decompressflag = "-y"; last SWITCH; } ;
/^.*\.tar$/ && do {last SWITCH; } ;
}
#
# Install tar file from root?
#
if (! chdir($installdir)) {
fatal("Could not chdir to $installdir: $!\n");
}
#
# Run the tarfile.
#
system("tar $decompressflag -xf $tarfile");
$exit_status = $? >> 8;
exit($exit_status);
sub fatal {
local($msg) = $_[0];
print STDERR "$msg\n";
exit(-1);
}
......@@ -8,7 +8,7 @@ require 'ctime.pl';
#
my $SUPCHECKOUT = "/etc/testbed/sup/sup/FBSD40-STD/checkouts";
my $DUMPDATES = "/etc/dumpdates";
my $IDENTFILE = "/var/db/testbed.deltas";
my @DBFILES = ("/var/db/testbed.deltas", "/var/db/testbed.tarfiles");
my $FSTAB = "/etc/fstab";
#
......@@ -39,10 +39,12 @@ if (-e $SUPCHECKOUT) {
die("Could not unlink $SUPCHECKOUT");
}
print "Removing old delta list ...\n";
if (-e $IDENTFILE) {
unlink($IDENTFILE) or
die("Could not unlink $IDENTFILE");
print "Removing old DB files ...\n";
foreach my $dbfile (@DBFILES) {
if (-e $dbfile) {
unlink($dbfile) or
die("Could not unlink $dbfile");
}
}
#
......
......@@ -20,6 +20,11 @@ if [ -x /etc/testbed/rc.rpm ]; then
/etc/testbed/rc.rpm
fi
if [ -x /etc/testbed/rc.tarballs ]; then
echo "Installing Tarballs ..."
/etc/testbed/rc.tarballs
fi
/bin/rm -f /var/at/jobs/S*
if [ -s /etc/testbed/startupcmd ]; then
echo "Scheduling startup command to run in a little bit ..."
......
......@@ -62,6 +62,11 @@ doaccounts();
#
dorpms();
#
# Tar Balls
#
dotarballs();
#
# Experiment startup Command.
#
......
......@@ -8,13 +8,15 @@ my $TMCC = "/etc/testbed/tmcc";
my $TMIFC = "/etc/testbed/rc.ifc";
my $TMDELAY = "/etc/testbed/rc.delay";
my $TMRPM = "/etc/testbed/rc.rpm";
my $TMTARBALLS = "/etc/testbed/rc.tarballs";
my $TMSTARTUPCMD= "/etc/testbed/startupcmd";
my $TMGROUP = "/etc/testbed/group";
my $TMPASSWD = "/etc/testbed/master.passwd";
my $TMHOSTS = "/etc/testbed/hosts";
my $HOSTSFILE = "/etc/hosts";
my $TMNICKNAME = "/etc/testbed/nickname";
my @CONFIGS = ($TMIFC, $TMDELAY, $TMRPM, $TMSTARTUPCMD, $TMNICKNAME);
my @CONFIGS = ($TMIFC, $TMDELAY, $TMRPM, $TMSTARTUPCMD, $TMNICKNAME,
$TMTARBALLS);
my $REBOOTCMD = "reboot";
my $STATCMD = "status";
my $IFCCMD = "ifconfig";
......@@ -22,6 +24,7 @@ my $ACCTCMD = "accounts";
my $DELAYCMD = "delay";
my $HOSTSCMD = "hostnames";
my $RPMCMD = "rpms";
my $TARBALLCMD = "tarballs";
my $STARTUPCMD = "startupcmd";
my $DELTACMD = "deltas";
my $STARTSTATCMD= "startstatus";
......@@ -34,6 +37,7 @@ my $MKDB = "/usr/sbin/pwd_mkdb -p";
my $PW = "/usr/sbin/pw";
my $CHPASS = "/usr/bin/chpass";
my $DELTAINSTALL= "/usr/local/bin/install-delta";
my $TARINSTALL = "/usr/local/bin/install-tarfile";
my $IFACE = "fxp";
my $CTLIFACENUM = "4";
my $CTLIFACE = "${IFACE}${CTLIFACENUM}";
......@@ -452,6 +456,43 @@ sub dorpms ()
return 0;
}
#
# TARBALL configuration. Done after account stuff!
#
sub dotarballs ()
{
my @tarballs = ();
print STDOUT "Checking Testbed Tarball configuration ... \n";
open(TM, "$TMCC $NODE $TARBALLCMD |")
or die "Cannot start $TMCC: $!";
while (<TM>) {
push(@tarballs, $_);
}
close(TM);
if (! @tarballs) {
return 0;
}
open(TARBALL, ">$TMTARBALLS")
or die("Could not open $TMTARBALLS: $!");
print TARBALL "#!/bin/sh\n";
foreach my $tarball (@tarballs) {
if ($tarball =~ /DIR=([-\@\w.\/]+)\s+TARBALL=([-\@\w.\/]+)/) {
print STDOUT " $TARINSTALL $1 $2\n";
print TARBALL "echo \"Installing Tarball $2 in dir $1 \"\n";
print TARBALL "$TARINSTALL $1 $2\n";
}
}
close(TARBALL);
chmod(0755, "$TMTARBALLS");
return 0;
}
#
# Experiment startup Command.
#
......
......@@ -8,7 +8,7 @@ require 'ctime.pl';
#
my $SUPCHECKOUT = "/etc/rc.d/testbed/sup/sup/RHL62-STD/checkouts";
my $DUMPDATES = "/etc/dumpdates";
my $IDENTFILE = "/var/db/testbed.deltas";
my @DBFILES = ("/var/db/testbed.deltas", "/var/db/testbed.tarfiles");
my $FSTAB = "/etc/fstab";
#
......@@ -39,10 +39,12 @@ if (-e $SUPCHECKOUT) {
die("Could not unlink $SUPCHECKOUT");
}
print "Removing old $IDENTFILE file ...\n";
if (-e $IDENTFILE) {
unlink($IDENTFILE) or
die("Could not unlink $IDENTFILE");
print "Removing old DB files ...\n";
foreach my $dbfile (@DBFILES) {
if (-e $dbfile) {
unlink($dbfile) or
die("Could not unlink $dbfile");
}
}
#
......
......@@ -15,6 +15,11 @@ if [ -x /etc/rc.d/testbed/rc.rpm ]; then
/etc/rc.d/testbed/rc.rpm
fi
if [ -x /etc/rc.d/testbed/rc.tarballs ]; then
echo "Installing Tarballs ..."
/etc/rc.d/testbed/rc.tarballs
fi
/bin/rm -f /var/spool/at/S*
if [ -s /etc/rc.d/testbed/startupcmd ]; then
echo "Scheduling startup command to run in a little bit ..."
......
......@@ -57,6 +57,11 @@ doaccounts();
#
dorpms();
#
# Tar Balls
#
dotarballs();
#
# Experiment startup Command.
#
......
......@@ -7,6 +7,7 @@ use English;
my $TMCC = "/etc/rc.d/testbed/tmcc";
my $TMIFC = "/etc/rc.d/testbed/rc.ifc";
my $TMRPM = "/etc/rc.d/testbed/rc.rpm";
my $TMTARBALLS = "/etc/rc.d/testbed/rc.tarballs";
my $TMSTARTUPCMD= "/etc/rc.d/testbed/startupcmd";
my $TMGROUP = "/etc/rc.d/testbed/group";
my $TMPASSWD = "/etc/rc.d/testbed/passwd";
......@@ -15,7 +16,7 @@ my $TMGSHADOW = "/etc/rc.d/testbed/gshadow";
my $TMHOSTS = "/etc/rc.d/testbed/hosts";
my $TMNICKNAME = "/etc/rc.d/testbed/nickname";
my $HOSTSFILE = "/etc/hosts";
my @CONFIGS = ($TMIFC, $TMRPM, $TMSTARTUPCMD, $TMNICKNAME);
my @CONFIGS = ($TMIFC, $TMRPM, $TMSTARTUPCMD, $TMNICKNAME, $TMTARBALLS);
my @LOCKFILES = ("/etc/group.lock", "/etc/gshadow.lock");
my $REBOOTCMD = "reboot";
my $STATCMD = "status";
......@@ -24,6 +25,7 @@ my $ACCTCMD = "accounts";
my $DELAYCMD = "delay";
my $HOSTSCMD = "hostnames";
my $RPMCMD = "rpms";
my $TARBALLCMD = "tarballs";
my $STARTUPCMD = "startupcmd";
my $DELTACMD = "deltas";
my $IFCONFIG = "/sbin/ifconfig eth%d inet %s netmask %s\n";
......@@ -33,6 +35,7 @@ my $USERADD = "/usr/sbin/useradd";
my $USERMOD = "/usr/sbin/usermod";
my $GROUPADD = "/usr/sbin/groupadd";
my $DELTAINSTALL= "/usr/local/bin/install-delta";
my $TARINSTALL = "/usr/local/bin/install-tarfile";
my $IFACE = "eth";
my $CTLIFACENUM = "4";
my $CTLIFACE = "${IFACE}${CTLIFACENUM}";
......@@ -303,6 +306,40 @@ sub dorpms ()
return 0;
}
sub dotarballs ()
{
my @tarballs = ();
print STDOUT "Checking Testbed Tarball configuration ... \n";
open(TM, "$TMCC $NODE $TARBALLCMD |")
or die "Cannot start $TMCC: $!";
while (<TM>) {
push(@tarballs, $_);
}
close(TM);
if (! @tarballs) {
return 0;
}
open(TARBALL, ">$TMTARBALLS")
or die("Could not open $TMTARBALLS: $!");
print TARBALL "#!/bin/sh\n";
foreach my $tarball (@tarballs) {
if ($tarball =~ /DIR=([-\@\w.\/]+)\s+TARBALL=([-\@\w.\/]+)/) {
print STDOUT " $TARINSTALL $1 $2\n";
print TARBALL "echo \"Installing Tarball $2 in dir $1 \"\n";
print TARBALL "$TARINSTALL $1 $2\n";
}
}
close(TARBALL);
chmod(0755, "$TMTARBALLS");
return 0;
}
#
# Experiment startup Command.
#
......
......@@ -43,6 +43,7 @@ static int dodelay(int sock, struct in_addr ipaddr, char *rdata, int tcp);
static int dohosts(int sock, struct in_addr ipaddr, char *rdata, int tcp);
static int dorpms(int sock, struct in_addr ipaddr, char *rdata, int tcp);
static int dodeltas(int sock, struct in_addr ipaddr, char *rdata, int tcp);
static int dotarballs(int sock, struct in_addr ipaddr, char *rdata, int tcp);
static int dostartcmd(int sock, struct in_addr ipaddr, char *rdata, int tcp);
static int dostartstat(int sock, struct in_addr ipaddr, char *rdata,int tcp);
static int doready(int sock, struct in_addr ipaddr, char *rdata,int tcp);
......@@ -61,6 +62,7 @@ struct command {
{ "hostnames", dohosts },
{ "rpms", dorpms },
{ "deltas", dodeltas },
{ "tarballs", dotarballs },
{ "startupcmd", dostartcmd },
{ "startstatus",dostartstat }, /* Leave this before "startstat" */
{ "startstat", dostartstat },
......@@ -881,7 +883,7 @@ dorpms(int sock, struct in_addr ipaddr, char *rdata, int tcp)
char buf[MYBUFSIZE], *bp, *sp;
if (iptonodeid(ipaddr, nodeid)) {
syslog(LOG_ERR, "DELAY: %s: No such node",
syslog(LOG_ERR, "TARBALLS: %s: No such node",
inet_ntoa(ipaddr));
return 1;
}
......@@ -934,7 +936,76 @@ dorpms(int sock, struct in_addr ipaddr, char *rdata, int tcp)
}
/*
* Return Delats stuff.
* Return Tarball stuff.
*/
static int
dotarballs(int sock, struct in_addr ipaddr, char *rdata, int tcp)
{
MYSQL_RES *res;
MYSQL_ROW row;
char nodeid[32];
char pid[64];
char eid[64];
char buf[MYBUFSIZE], *bp, *sp, *tp;
if (iptonodeid(ipaddr, nodeid)) {
syslog(LOG_ERR, "TARBALLS: %s: No such node",
inet_ntoa(ipaddr));
return 1;
}
/*
* Now check reserved table
*/
if (nodeidtoexp(nodeid, pid, eid))
return 0;
/*
* Get Tarball list for the node.
*/
res = mydb_query("select tarballs from nodes where node_id='%s' ",
1, nodeid);
if (!res) {
syslog(LOG_ERR, "TARBALLS: %s: DB Error getting tarballs!",
nodeid);
return 1;
}
if ((int)mysql_num_rows(res) == 0) {
mysql_free_result(res);
return 0;
}
/*
* Text string is a colon separated list of "dir filename".
*/
row = mysql_fetch_row(res);
if (! row[0] || !row[0][0]) {
mysql_free_result(res);
return 0;
}
bp = row[0];
sp = bp;
do {
bp = strsep(&sp, ":");
if ((tp = strchr(bp, ' ')) == NULL)
continue;
*tp++ = '\0';
sprintf(buf, "DIR=%s TARBALL=%s\n", bp, tp);
client_writeback(sock, buf, strlen(buf), tcp);
syslog(LOG_INFO, "TARBALLS: %s", buf);
} while (bp = sp);
mysql_free_result(res);
return 0;
}
/*
* Return Deltas stuff.
*/
static int
dodeltas(int sock, struct in_addr ipaddr, char *rdata, int tcp)
......
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