Commit f39a629e authored by Ryan Jackson's avatar Ryan Jackson

Get rid of Linux-specific create-image script

Merge the Linux-specific changes made to create-image into the os/create-image
script.  This means A) check for sudo in /usr/local/bin and /usr/bin, and try
to convert BSD disk device names to Linux device names.
parent 51f9d936
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2004, 2007 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Getopt::Std;
#
# Create a disk image. Caller must have sudo permission!
#
sub usage()
{
print STDOUT "Usage: create-image [-s slice] <device file> <filename>\n";
exit(-1);
}
my $optlist = "rs:";
#
# 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 $sudo;
my $zipper = "/usr/local/bin/imagezip";
my $slice = "";
my $device;
my $filename;
for my $path (qw#/usr/local/bin /usr/bin#) {
if (-e "$path/sudo") {
$sudo = "$path/sudo";
last;
}
}
#
# 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();
}
if (defined($options{"s"})) {
my $num = $options{"s"};
if ($num =~ /(\d)/) {
$num = $1;
}
else {
die("Tainted slice number: $num");
}
$slice = "-s $num";
# XXX for now we do not generate relocation info on slices
# XXX there are still some issues with LILO/GRUB
$slice = "-N $slice";
}
$device = $ARGV[0];
$filename = $ARGV[1];
#
# Untaint the arguments.
#
# Note different taint check (allow /).
if ($device =~ /^([-\w.\/]+)$/) {
$device = $1;
}
else {
die("Tainted device name: $device");
}
if ($filename =~ /^([-\w.\/\+]+)$/) {
$filename = $1;
}
else {
die("Tainted output filename: $filename");
}
$device =~ m#/dev/(\D+)(\d+)#;
($dtype, $dunit) = ($1, $2);
$dunit -= 4 if ($dtype eq 'ad' && $dunit > 3);
$dunit =~ y/01234567/abcdefgh/;
$device = "/dev/sd$dunit";
#
# Run the command using sudo, since by definition only testbed users
# with proper trust should be able to zip up a disk. sudo will fail
# if the user is not in the proper group.
#
if (system("$sudo $zipper $slice $device $filename")) {
print STDERR "*** Failed to create image!\n";
exit 1;
}
exit 0;
......@@ -33,13 +33,20 @@ delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# No configure vars.
#
my $sudo = "/usr/local/bin/sudo";
my $sudo;
my $zipper = "/usr/local/bin/imagezip";
my $uploader = "/usr/local/bin/frisupload";
my $slice = "";
my $device;
my $filename;
for my $path (qw#/usr/local/bin /usr/bin#) {
if (-e "$path/sudo") {
$sudo = "$path/sudo";
last;
}
}
# Frisbee master server params
my $iserver = "boss"; # XXX
my $imageid;
......@@ -113,6 +120,21 @@ else {
die("Tainted output filename: $filename");
}
# Hack for the Linux MFS: we still use the BSD device
# names in the database so we try to convert them to
# the equivalent Linux devices here. This happens to
# work at the moment, but if device names change again
# it could break.
if (`uname -s` eq 'Linux') {
$device =~ m#/dev/(\D+)(\d+)#;
($dtype, $dunit) = ($1, $2);
$dunit -= 4 if ($dtype eq 'ad' && $dunit > 3);
$dunit =~ y/01234567/abcdefgh/;
$device = "/dev/sd$dunit";
}
#
# If imageid is defined, we use the frisbee uploader.
#
......
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