Changeset 31


Ignore:
Timestamp:
01/17/08 11:32:08 (4 years ago)
Author:
bruno
Message:

Adds install script for dploy-dhcp
Split useless code from dploy-add2dhcp

Location:
devel/dploy-dhcp
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • devel/dploy-dhcp/bin/dploy-add2dhcp

    r29 r31  
    11#!/usr/bin/perl -w 
     2# 
     3# $Id$ 
     4#  
     5# (c) Bruno Cornec, HP, provided under the GPL v3 
     6# 
    27 
    38use strict; 
     
    1015# as part of the appropriate range 
    1116# does not support multiple ranges yet 
     17# This is done at install time by the install script 
     18# Also a dploy account should exist to run that script 
     19# and be referenced in sudo. Also done by install script 
    1220# 
    13 my $pxe="/tftpboot/pxelinux.cfg"; 
    14 # Where to find the LinuxCOE created ISO 
    15 my $linuxcoe="/var/ftp/html/scratch_monkey/systemdesigner"; 
    16 # temporary mountpoint 
    17 my $mnt="/tmp/mnt-linuxcoe"; 
    1821 
    1922my $mac=$ARGV[0]; 
    2023 
    2124if ($mac !~ /^(?:[[:xdigit:]]{1,2}[-:]){5}[[:xdigit:]]{1,2}$/) { 
    22     print "Syntax: add2pxe MAC ip url-to-LinuxCOE-iso\n"; 
     25    print "Syntax: dploy-add2dhcp MAC ip\n"; 
    2326    exit(-1); 
    2427} 
     28 
     29# only lowercase for homogeneity 
     30$mac =~ tr/A-Z/a-z/; 
    2531 
    2632my $ip=$ARGV[1]; 
    2733 
    2834if ($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"; 
     35    print "Syntax: dploy-add2dhcp mac IP\n"; 
    3036    exit(-1); 
    3137} 
    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  
     38# 
    4039# Reads existing DHCP conf if any 
    4140# 
    42  
    43 # newmac replaces : separator with - and only lowercase for pxelinux 
    44 my $newmac = $mac; 
    45 $newmac =~ tr/A-Z/a-z/; 
    46 $newmac =~ s/:/-/g; 
    4741 
    4842my $foundit = 0; 
     
    5145if (open(DHCP,$dhcp)) { 
    5246    while (<DHCP>) { 
    53         if (/host host-$newmac \{/ .. /}\n/) { 
     47        if (/host host-$mac \{/ .. /}\n/) { 
    5448            # We need to replace the old content with the new one 
    5549            print "Skip $_"; 
     
    7064    # 
    7165    print DHCPNEW "\n"; 
    72     print DHCPNEW "host host-$newmac {\n"; 
     66    print DHCPNEW "host host-$mac {\n"; 
    7367    print DHCPNEW " hardware ethernet $mac;\n"; 
    7468    print DHCPNEW " fixed-address $ip;\n"; 
     
    7872move("$dhcp.new",$dhcp); 
    7973 
     74# 
    8075# Relaunch DHCP server 
     76# 
    8177system("sudo /etc/init.d/dhcpd restart"); 
    82  
    83 # Get the ID given by LinuxCOE to prepare kernel/initrd/ks 
    84 my $iso=basename($url); 
    85 my $id=$iso; 
    86 $id =~ s/img([0-9]+)\.iso/$1/; 
    87 my $k="k-$id"; 
    88 my $i="i-$id"; 
    89 my $ks=$url; 
    90 $ks =~ s/img([0-9]+)\.iso/ks$1.cfg/; 
    91  
    92 # Updates PXElinux 
    93 open(PXE, "> $pxe/01-$newmac") || die "Unable to open $pxe/01-$newmac for writing"; 
    94 print PXE << "EOF"; 
    95 default local 
    96 prompt 1 
    97 timeout 600 
    98 display msg/linuxcoe.msg 
    99 allowoptions 1 
    100  
    101 label local 
    102   localboot 0 
    103  
    104 label linuxcoe 
    105   kernel linuxcoe/$k 
    106   append ksdevice=eth0 ks=$ks initrd=linuxcoe/$i text 
    107 EOF 
    108 close(PXE); 
    109  
    110 # mount the ISO to get kernel and initrd 
    111 mkdir "$mnt",0755; 
    112 system("sudo /bin/mount -o loop $linuxcoe/$iso $mnt"); 
    113 copy("$mnt/isolinux/vmlinuz","$pxe/../linuxcoe/$k") or die "Copy failed: $!"; 
    114 copy("$mnt/isolinux/initrd.img","$pxe/../linuxcoe/$i") or die "Copy failed: $!"; 
    115 system("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.