Changeset 41 for devel/dploy-pxe/bin
- Timestamp:
- 04/15/08 17:49:15 (4 years ago)
- File:
-
- 1 edited
-
devel/dploy-pxe/bin/dploy-add2pxe (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
devel/dploy-pxe/bin/dploy-add2pxe
r29 r41 3 3 use strict; 4 4 use File::Copy; 5 use File::Basename; 5 6 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 13 8 my $pxe="/tftpboot/pxelinux.cfg"; 14 # Where to find the LinuxCOE created ISO 9 # Where to find the LinuxCOE created ISO on the SystemDesigner server 15 10 my $linuxcoe="/var/ftp/html/scratch_monkey/systemdesigner"; 11 # Where to find the Mondorescue created ISO on the Images server 12 my $mondorescue="/var/ftp/html/mondorescue/iso"; 16 13 # temporary mountpoint 17 my $mnt="/tmp/mnt- linuxcoe";14 my $mnt="/tmp/mnt-dploy"; 18 15 19 my $mac=$ARGV[0] ;16 my $mac=$ARGV[0] || ""; 20 17 21 18 if ($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); 24 21 } 25 22 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/; 42 25 43 26 # newmac replaces : separator with - and only lowercase for pxelinux … … 46 29 $newmac =~ s/:/-/g; 47 30 48 my $ foundit = 0;31 my $url=$ARGV[1]; 49 32 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; 33 if ($url !~ /(\w+):\/\/([^\/:]+)(:\d+)?\/(.*)/) { 34 print "Syntax: dploy-add2pxe mac URL-TO-ISO\n"; 35 exit(-1); 66 36 } 67 37 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 84 39 my $iso=basename($url); 85 40 my $id=$iso; … … 114 69 copy("$mnt/isolinux/initrd.img","$pxe/../linuxcoe/$i") or die "Copy failed: $!"; 115 70 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.
