Changeset 31 for devel/dploy-dhcp
- Timestamp:
- 01/17/08 11:32:08 (4 years ago)
- Location:
- devel/dploy-dhcp
- Files:
-
- 1 added
- 1 edited
-
bin/dploy-add2dhcp (modified) (5 diffs)
-
install.sh (added)
Legend:
- Unmodified
- Added
- Removed
-
devel/dploy-dhcp/bin/dploy-add2dhcp
r29 r31 1 1 #!/usr/bin/perl -w 2 # 3 # $Id$ 4 # 5 # (c) Bruno Cornec, HP, provided under the GPL v3 6 # 2 7 3 8 use strict; … … 10 15 # as part of the appropriate range 11 16 # 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 12 20 # 13 my $pxe="/tftpboot/pxelinux.cfg";14 # Where to find the LinuxCOE created ISO15 my $linuxcoe="/var/ftp/html/scratch_monkey/systemdesigner";16 # temporary mountpoint17 my $mnt="/tmp/mnt-linuxcoe";18 21 19 22 my $mac=$ARGV[0]; 20 23 21 24 if ($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"; 23 26 exit(-1); 24 27 } 28 29 # only lowercase for homogeneity 30 $mac =~ tr/A-Z/a-z/; 25 31 26 32 my $ip=$ARGV[1]; 27 33 28 34 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";35 print "Syntax: dploy-add2dhcp mac IP\n"; 30 36 exit(-1); 31 37 } 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 # 40 39 # Reads existing DHCP conf if any 41 40 # 42 43 # newmac replaces : separator with - and only lowercase for pxelinux44 my $newmac = $mac;45 $newmac =~ tr/A-Z/a-z/;46 $newmac =~ s/:/-/g;47 41 48 42 my $foundit = 0; … … 51 45 if (open(DHCP,$dhcp)) { 52 46 while (<DHCP>) { 53 if (/host host-$ newmac \{/ .. /}\n/) {47 if (/host host-$mac \{/ .. /}\n/) { 54 48 # We need to replace the old content with the new one 55 49 print "Skip $_"; … … 70 64 # 71 65 print DHCPNEW "\n"; 72 print DHCPNEW "host host-$ newmac {\n";66 print DHCPNEW "host host-$mac {\n"; 73 67 print DHCPNEW " hardware ethernet $mac;\n"; 74 68 print DHCPNEW " fixed-address $ip;\n"; … … 78 72 move("$dhcp.new",$dhcp); 79 73 74 # 80 75 # Relaunch DHCP server 76 # 81 77 system("sudo /etc/init.d/dhcpd restart"); 82 83 # Get the ID given by LinuxCOE to prepare kernel/initrd/ks84 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 PXElinux93 open(PXE, "> $pxe/01-$newmac") || die "Unable to open $pxe/01-$newmac for writing";94 print PXE << "EOF";95 default local96 prompt 197 timeout 60098 display msg/linuxcoe.msg99 allowoptions 1100 101 label local102 localboot 0103 104 label linuxcoe105 kernel linuxcoe/$k106 append ksdevice=eth0 ks=$ks initrd=linuxcoe/$i text107 EOF108 close(PXE);109 110 # mount the ISO to get kernel and initrd111 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.edu118 # in Basename.pm119 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.
