Ignore:
Timestamp:
04/16/08 15:58:35 (4 years ago)
Author:
renaudga
Message:

Work done to pass parameters to aad2pxe. functions need to be writen.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/dploy-pxe/bin/dploy-add2pxe

    r47 r49  
    1212use File::Basename; 
    1313 
     14my %opts; 
     15my $type = ""; 
     16my $mac = ""; 
     17my $url = ""; 
     18my $ksdevice = "eth0"; 
     19my $prefix = ""; 
     20my $mrserver = ""; 
     21my $mrpath = ""; 
     22 
    1423GetOptions("help|?|h" => \$opts{'h'}, 
    15            "mode|m=s" => \$opts{'mode'},    # Mode is MR or SD 
    16            "mac|m=s" => \$opts{'mac'},      # Mac address 
    17              "ip|i=s" => \$opts{'ip'},      #  
    18         "netmask|n=s" => \$opts{'mask'}, 
    19         "gw|g=s" => \$opts{'gw'}, 
     24           "type|t=s" => \$opts{'type'},    # Type is MondoRescue or LinuxCOE 
     25            "mac|m=s" => \$opts{'mac'},     # Mac address 
     26            "url|u=s" => \$opts{'url'},     # URL of ISO image containing kernel, modules and answer file 
     27        ) || dploy_syntax(-1,0); 
    2028 
     29if (defined $opts{'type'}) { 
     30  $type = $opts{'type'}; 
     31} 
    2132 
     33if (defined $opts{'h'}) { 
     34  dploy_syntax(0,1); 
     35} 
    2236 
    2337# Root of the PXE setup 
    24 my $pxe="/tftpboot/pxelinux.cfg"; 
    25 # Where to find the LinuxCOE created ISO on the SystemDesigner server 
    26 my $linuxcoe="/var/ftp/html/scratch_monkey/systemdesigner"; 
    27 # Where to find the Mondorescue created ISO on the Images server 
    28 my $mondorescue="/var/ftp/html/mondorescue/iso"; 
     38my $pxe=dploy_get_conf("pathpxe"); 
     39 
    2940# temporary mountpoint 
    30 my $mnt="/tmp/mnt-dploy"; 
     41if (not defined $ENV {'TMPDIR'}) { 
     42    $ENV{'TMPDIR'} = "/tmp"; 
     43} 
     44my $tmp=tempdir("dploy.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1); 
     45my $mnt="$tmp/iso"; 
     46my $mnt2="$tmp/nfs"; 
    3147 
    3248my $mac=$ARGV[0] || ""; 
    3349 
     50# Check Mac consitency (to be done in an external function) 
    3451if ($mac !~ /^(?:[[:xdigit:]]{1,2}[-:]){5}[[:xdigit:]]{1,2}$/) { 
    3552        print "Syntax: dploy-add2pxe MAC url-to-iso\n"; 
     
    4562$newmac =~ s/:/-/g; 
    4663 
    47 my $url=$ARGV[1]; 
     64# Check URL syntax 
     65if (defined $opts{'url'}) { 
     66  $url = $opts{'url'}; 
     67} 
    4868 
    4969if ($url !~ /(\w+):\/\/([^\/:]+)(:\d+)?\/(.*)/) { 
     
    5171    exit(-1); 
    5272} 
     73 
     74# Get Mondorescue values 
     75$mrserver = dploy_get_url(); 
     76$mrpath = dploy_get_url(); 
    5377 
    5478# Get the ID given by LinuxCOE/MondoRescue to prepare kernel/initrd/ks 
     
    6084my $ks=$url; 
    6185$ks =~ s/img([0-9]+)\.iso/ks$1.cfg/; 
     86 
     87# mount the ISO to get kernel and initrd 
     88mkdir "$mnt",0755; 
     89if ($Type == "LinuxCOE") { 
     90    system("sudo /bin/mount -o loop $linuxcoe/$iso $mnt"); 
     91} else { 
     92    system("sudo /bin/mount -t nfs $mrserver:$mrpath $mnt2"); 
     93    system("sudo /bin/mount -o loop $mnt2/$prefix-1.iso $mnt"); 
     94} 
     95# Install script will have to check (and create if not existing) /tftpboot/tmp 
     96copy("$mnt/isolinux/vmlinuz","$pxe/../tmp/$k") or die "Copy failed: $!"; 
     97copy("$mnt/isolinux/initrd.img","$pxe/../tmp/$i") or die "Copy failed: $!"; 
     98 
     99# Get the Command Line parameters for MondoRescue restoration 
     100open(ISOLINUX, "$mnt/isolinux.cfg") || die "Unable to open $mnt/isolinux.cfg for writing"; 
     101while ( <ISOLINUX> ) { 
     102    if (/label nuke/) { 
     103        my $cliparams = <ISOLINUX>;     # kernel line 
     104        $cliparams = <ISOLINUX>;        # append line 
     105    } 
     106} 
     107$cliparams =~ s/initrd=[a-z.] /initrd=initrd=mondorescue\/$i /; 
     108 
     109close ISOLINUX; 
     110# All done with ISO image... umounting 
     111system("sudo /bin/umount $mnt"); 
     112 
    62113 
    63114# Updates PXElinux 
     
    73124  localboot 0 
    74125 
    75 label linuxcoe 
    76   kernel linuxcoe/$k 
    77   append ksdevice=eth0 ks=$ks initrd=linuxcoe/$i text 
    78126EOF 
    79127close(PXE); 
    80128 
    81 # mount the ISO to get kernel and initrd 
    82 mkdir "$mnt",0755; 
    83 system("sudo /bin/mount -o loop $linuxcoe/$iso $mnt"); 
    84 copy("$mnt/isolinux/vmlinuz","$pxe/../linuxcoe/$k") or die "Copy failed: $!"; 
    85 copy("$mnt/isolinux/initrd.img","$pxe/../linuxcoe/$i") or die "Copy failed: $!"; 
    86 system("sudo /bin/umount $mnt"); 
     129# Customize pxe file depending on Job type submited 
     130open(PXE, ">> $pxe/01-$newmac") || die "Unable to open $pxe/01-$newmac for writing"; 
     131if ($Type == "LinuxCOE") { 
     132    print PXE "label linuxcoe\n"; 
     133    print PXE "  kernel linuxcoe/$k\n"; 
     134    print PXE "  append ksdevice=$ksdevice ks=$ks initrd=linuxcoe/$i text\n"; 
     135} else { 
     136    print PXE "label mondorecue\n"; 
     137    print PXE "  kernel mondorescue/$k\n"; 
     138    print PXE "  append $cliparams pxe prefix=$prefix ipconf=$ksdevice:dhcp nfsmount=$mrserver:$mrpath\n"; 
     139} 
     140close(PXE); 
     141 
Note: See TracChangeset for help on using the changeset viewer.