Changeset 41 for devel/dploy-pxe/bin


Ignore:
Timestamp:
04/15/08 17:49:15 (4 years ago)
Author:
bruno
Message:

Working dploy-add2dhcp with subnet

File:
1 edited

Legend:

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

    r29 r41  
    33use strict; 
    44use File::Copy; 
     5use File::Basename; 
    56 
    6 my $dhcp="/etc/dhcpd.d/dploy.org.conf"; 
    7 # 
    8 # /etc/dhcpd.conf should include that line: 
    9 # include "/etc/dhcpd.d/dploy.org.conf"; 
    10 # as part of the appropriate range 
    11 # does not support multiple ranges yet 
    12 # 
     7# Root of the PXE setup 
    138my $pxe="/tftpboot/pxelinux.cfg"; 
    14 # Where to find the LinuxCOE created ISO 
     9# Where to find the LinuxCOE created ISO on the SystemDesigner server 
    1510my $linuxcoe="/var/ftp/html/scratch_monkey/systemdesigner"; 
     11# Where to find the Mondorescue created ISO on the Images server 
     12my $mondorescue="/var/ftp/html/mondorescue/iso"; 
    1613# temporary mountpoint 
    17 my $mnt="/tmp/mnt-linuxcoe"; 
     14my $mnt="/tmp/mnt-dploy"; 
    1815 
    19 my $mac=$ARGV[0]; 
     16my $mac=$ARGV[0] || ""; 
    2017 
    2118if ($mac !~ /^(?:[[:xdigit:]]{1,2}[-:]){5}[[:xdigit:]]{1,2}$/) { 
    22     print "Syntax: add2pxe MAC ip url-to-LinuxCOE-iso\n"; 
    23     exit(-1); 
     19        print "Syntax: dploy-add2pxe MAC url-to-iso\n"; 
     20        exit(-1); 
    2421} 
    2522 
    26 my $ip=$ARGV[1]; 
    27  
    28 if ($ip !~ /^([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])\.([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])\.([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])\.([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])$/) { 
    29     print "Syntax: add2pxe mac IP url-to-LinuxCOE-iso\n"; 
    30     exit(-1); 
    31 } 
    32  
    33 my $url=$ARGV[2]; 
    34  
    35 if ($url !~ /(\w+):\/\/([^\/:]+)(:\d+)?\/(.*)/) { 
    36     print "Syntax: add2pxe mac ip URL-TO-LinuxCOE-ISO\n"; 
    37     exit(-1); 
    38 } 
    39  
    40 # Reads existing DHCP conf if any 
    41 # 
     23# only lowercase for homogeneity 
     24$mac =~ tr/A-Z/a-z/; 
    4225 
    4326# newmac replaces : separator with - and only lowercase for pxelinux 
     
    4629$newmac =~ s/:/-/g; 
    4730 
    48 my $foundit = 0; 
     31my $url=$ARGV[1]; 
    4932 
    50 open(DHCPNEW,"> $dhcp.new") || die "Unable to create $dhcp.new"; 
    51 if (open(DHCP,$dhcp)) { 
    52     while (<DHCP>) { 
    53         if (/host host-$newmac \{/ .. /}\n/) { 
    54             # We need to replace the old content with the new one 
    55             print "Skip $_"; 
    56             $foundit = 1; 
    57         } else { 
    58             print "Keep $_"; 
    59             # Just write the existing content 
    60             print DHCPNEW $_; 
    61         } 
    62     } 
    63     close(DHCP); 
    64 } else { 
    65     $foundit = 1; 
     33if ($url !~ /(\w+):\/\/([^\/:]+)(:\d+)?\/(.*)/) { 
     34    print "Syntax: dploy-add2pxe mac URL-TO-ISO\n"; 
     35    exit(-1); 
    6636} 
    6737 
    68 if ($foundit == 1) { 
    69     # Writes new DHCP conf from scratch 
    70     # 
    71     print DHCPNEW "\n"; 
    72     print DHCPNEW "host host-$newmac {\n"; 
    73     print DHCPNEW " hardware ethernet $mac;\n"; 
    74     print DHCPNEW " fixed-address $ip;\n"; 
    75     print DHCPNEW "}\n\n"; 
    76 } 
    77 close(DHCPNEW); 
    78 move("$dhcp.new",$dhcp); 
    79  
    80 # Relaunch DHCP server 
    81 system("sudo /etc/init.d/dhcpd restart"); 
    82  
    83 # Get the ID given by LinuxCOE to prepare kernel/initrd/ks 
     38# Get the ID given by LinuxCOE/MondoRescue to prepare kernel/initrd/ks 
    8439my $iso=basename($url); 
    8540my $id=$iso; 
     
    11469copy("$mnt/isolinux/initrd.img","$pxe/../linuxcoe/$i") or die "Copy failed: $!"; 
    11570system("sudo /bin/umount $mnt"); 
    116  
    117 # Based on Version 2.4  27-Sep-1996  Charles Bailey  bailey@genetics.upenn.edu 
    118 # in Basename.pm 
    119  
    120 sub basename { 
    121  
    122 my($fullname) = shift; 
    123 my($dirpath,$basename); 
    124 ($dirpath,$basename) = ($fullname =~ m#^(.*/)?(.*)#s); 
    125  
    126 return($basename); 
    127 } 
    128  
Note: See TracChangeset for help on using the changeset viewer.