From 0b21a22a82a1ed08f1b56f6b79213cc43fda9a66 Mon Sep 17 00:00:00 2001 From: memotype Date: Tue, 3 Jun 2008 15:49:45 +0000 Subject: [PATCH] copycds physical drive support git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@1564 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-client/bin/copycds-cdrom | 25 +++++++++++++++++++ xCAT-server/lib/xcat/plugins/copycds.pm | 32 +++++++++++++++++++++---- 2 files changed, 52 insertions(+), 5 deletions(-) create mode 100755 xCAT-client/bin/copycds-cdrom diff --git a/xCAT-client/bin/copycds-cdrom b/xCAT-client/bin/copycds-cdrom new file mode 100755 index 000000000..a6aa44376 --- /dev/null +++ b/xCAT-client/bin/copycds-cdrom @@ -0,0 +1,25 @@ +#!/usr/bin/env perl + +my $go=1; + +if (!@ARGV) +{ + print "No arguments given, assuming /dev/cdrom.\n"; + push @ARGV, "/dev/cdrom"; +} + +while ($go) +{ + $go = 0; + system("copycds @ARGV"); + print "Would you like to copy another CD (y/N)? "; + if ( =~ /^y/i) + { + $go = 1; + system("eject"); + print "Replace the CD and press enter."; + ; + } +} + +# vim: set ts=2 sts=2 sw=2 et ai : diff --git a/xCAT-server/lib/xcat/plugins/copycds.pm b/xCAT-server/lib/xcat/plugins/copycds.pm index d671af787..042924b0c 100644 --- a/xCAT-server/lib/xcat/plugins/copycds.pm +++ b/xCAT-server/lib/xcat/plugins/copycds.pm @@ -4,6 +4,7 @@ use Storable qw(dclone); use xCAT::Table; use Data::Dumper; use Getopt::Long; +use File::Basename; Getopt::Long::Configure("bundling"); Getopt::Long::Configure("pass_through"); @@ -49,15 +50,34 @@ sub process_request { } foreach (@args) { unless (/^\//) { #If not an absolute path, concatenate with client specified cwd - s/^/$request->{cwd}->[0]\//; + s/^/$request->{cwd}->[0]\//; } - unless (-r $_ and -f $_) { - $callback->({error=>"The management server was unable to find/read $_, ensure that file exists on the server at specified location"}); + + # /dev/cdrom is a symlink on some systems, we need to see if it points to a + # block device. + if (-l $_) { + my $link = readlink($_); + if ($link =~ m{^/}) + { $file = $link; } + else + { $file = dirname($_) . "/" . $link; } + } + else { $file = $_; } + + my $mntopts; + if (-r $file and -b $file) # Block device? + { $mntopts = "-o ro"; } + elsif (-r $file and -f $file) + { $mntopts = "-o ro,loop"; } + else { + $callback->({error=>"The management server was unable to find/read $file. Ensure that file exists on the server at the specified location."}); return; } + mkdir "/mnt/xcat"; - if (system("mount -o loop,ro $_ /mnt/xcat")) { - $callback->({error=>"copycds was unable to examine $_ as an install image"}); + + if (system("mount $mntopts $file /mnt/xcat")) { + $callback->({error=>"copycds was unable to mount $file to /mnt/xcat."}); return; } my $newreq = dclone($request); @@ -80,3 +100,5 @@ sub process_request { } 1; + +# vim: set ts=2 sts=2 sw=2 et ai: