Changeset 50

Show
Ignore:
Timestamp:
05/02/08 15:38:40 (2 years ago)
Author:
renaudga
Message:

Rework on the syntax of add2pxe file

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • devel/dploy-pxe/bin/dploy-add2pxe

    r49 r50  
    1111use File::Copy; 
    1212use File::Basename; 
     13use ProjectBuilder::Base; 
     14use Dploy::Base; 
    1315 
    1416my %opts; 
    15 my $type = ""; 
    16 my $mac = ""; 
    17 my $url = ""; 
     17my $url = undef; 
    1818my $ksdevice = "eth0"; 
    19 my $prefix = ""
    20 my $mrserver = ""
    21 my $mrpath = ""
     19my $prefix = undef
     20my $mrserver = undef
     21my $mrpath = undef
    2222 
    2323GetOptions("help|?|h" => \$opts{'h'}, 
     
    2525            "mac|m=s" => \$opts{'mac'},     # Mac address 
    2626            "url|u=s" => \$opts{'url'},     # URL of ISO image containing kernel, modules and answer file 
    27         ) || dploy_syntax(-1,0); 
    28  
    29 if (defined $opts{'type'}) { 
    30   $type = $opts{'type'}; 
    31 
     27        ) || pb_syntax(-1,0); 
    3228 
    3329if (defined $opts{'h'}) { 
    34   dploy_syntax(0,1); 
     30    pb_syntax(0,1); 
    3531} 
    3632 
     
    4642my $mnt2="$tmp/nfs"; 
    4743 
    48 my $mac=$ARGV[0] || ""; 
    49  
    50 # Check Mac consitency (to be done in an external function) 
    51 if ($mac !~ /^(?:[[:xdigit:]]{1,2}[-:]){5}[[:xdigit:]]{1,2}$/) { 
    52         print "Syntax: dploy-add2pxe MAC url-to-iso\n"; 
    53         exit(-1); 
    54 
    55  
    56 # only lowercase for homogeneity 
    57 $mac =~ tr/A-Z/a-z/; 
    58  
    59 # newmac replaces : separator with - and only lowercase for pxelinux 
    60 my $newmac = $mac; 
    61 $newmac =~ tr/A-Z/a-z/; 
    62 $newmac =~ s/:/-/g; 
     44# Check Mac consitency  
     45my $mac = dploy_check_mac($opt{'mac'}); 
    6346 
    6447# Check URL syntax 
    6548if (defined $opts{'url'}) { 
    66   $url = $opts{'url'}; 
     49    $url = $opts{'url'}; 
    6750} 
    6851 
     
    8770# mount the ISO to get kernel and initrd 
    8871mkdir "$mnt",0755; 
    89 if ($Type == "LinuxCOE") { 
    90     system("sudo /bin/mount -o loop $linuxcoe/$iso $mnt"); 
     72if ($opt{'type'} == "LinuxCOE") { 
     73    pb_system("sudo /bin/mount -o loop $linuxcoe/$iso $mnt","Error mounting $linuxcoe/$iso"); 
     74} else if ($opt{'type'} == "MondoRescue") { 
     75    pb_system("sudo /bin/mount -t nfs $mrserver:$mrpath $mnt2","Error mountig NFS $mrserver:$mrpath"); 
     76    pb_system("sudo /bin/mount -o loop $mnt2/$prefix-1.iso $mnt","Error mounting LOOP $mnt2/$prefix-1.iso"); 
    9177} else { 
    92     system("sudo /bin/mount -t nfs $mrserver:$mrpath $mnt2"); 
    93    system("sudo /bin/mount -o loop $mnt2/$prefix-1.iso $mnt"); 
     78    # Type passed has parameter does not contain a valid value 
     79    pb_syntax(-1.0); 
    9480} 
     81 
    9582# Install script will have to check (and create if not existing) /tftpboot/tmp 
    9683copy("$mnt/isolinux/vmlinuz","$pxe/../tmp/$k") or die "Copy failed: $!"; 
     
    10996close ISOLINUX; 
    11097# All done with ISO image... umounting 
    111 system("sudo /bin/umount $mnt"); 
    112  
     98pb_system("sudo /bin/umount $mnt","Error umount ISO image); 
    11399 
    114100# Updates PXElinux 
    115 open(PXE, "> $pxe/01-$newmac") || die "Unable to open $pxe/01-$newmac for writing"; 
     101open(PXE, "> $pxe/01-$mac") || die "Unable to open $pxe/01-$mac for writing"; 
    116102print PXE << "EOF"; 
    117103default local 
     
    128114 
    129115# Customize pxe file depending on Job type submited 
    130 open(PXE, ">> $pxe/01-$newmac") || die "Unable to open $pxe/01-$newmac for writing"; 
    131 if ($Type == "LinuxCOE") { 
     116open(PXE, ">> $pxe/01-$mac") || die "Unable to open $pxe/01-$mac for writing"; 
     117if ($opt{'type'} == "LinuxCOE") { 
    132118    print PXE "label linuxcoe\n"; 
    133119    print PXE "  kernel linuxcoe/$k\n"; 
     
    139125} 
    140126close(PXE); 
    141