Changeset 7 for devel/dploy
- Timestamp:
- 05/10/07 19:22:32 (5 years ago)
- File:
-
- 1 edited
-
devel/dploy/bin/add2pxe (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
devel/dploy/bin/add2pxe
r6 r7 5 5 6 6 my $dhcp="/etc/dhcpd.d/linuxcoe.conf"; 7 # 8 # /etc/dhcpd.conf should include that line: 9 # include "/etc/dhcpd.d/linuxcoe.conf"; 10 # as part of the appropriate range 11 # does not support multiple ranges yet 12 # 7 13 my $pxe="/tftpboot/pxelinux.cfg"; 14 # Where to find the LinuxCOE created ISO 8 15 my $linuxcoe="/var/ftp/html/scratch_monkey/systemdesigner"; 16 # temporary mountpoint 9 17 my $mnt="/tmp/mnt-linuxcoe"; 10 my $dhcpcnt;11 18 12 19 my $mac=$ARGV[0]; 13 20 14 if ($mac !~ / :/) {15 print "Syntax: add2pxe mac ip URL-to-LinuxCOE-ISO\n";21 if ($mac !~ /^(?:[[:xdigit:]]{1,2}[-:]){5}[[:xdigit:]]{1,2}$/) { 22 print "Syntax: add2pxe MAC ip url-to-LinuxCOE-iso\n"; 16 23 exit(-1); 17 24 } … … 19 26 my $ip=$ARGV[1]; 20 27 21 if ($ip !~ / \./) {22 print "Syntax: add2pxe mac ip URL-to-LinuxCOE-ISO\n";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"; 23 30 exit(-1); 24 31 } … … 26 33 my $url=$ARGV[2]; 27 34 28 if ($url !~ / :/) {29 print "Syntax: add2pxe mac ip URL- to-LinuxCOE-ISO\n";35 if ($url !~ /(\w+):\/\/([^\/:]+)(:\d+)?\/(.*)/) { 36 print "Syntax: add2pxe mac ip URL-TO-LinuxCOE-ISO\n"; 30 37 exit(-1); 31 38 } … … 33 40 # Reads existing DHCP conf if any 34 41 # 35 if (! open(DHCP,$dhcp)) {36 # Doesn't exist yet => no content37 $dhcpcnt = "";38 } else {39 # reads dhcp content40 $/ = '\0';41 $dhcpcnt = <DHCP>;42 $/ = '\n';43 }44 close(DHCP);45 42 46 # Writes new DHCP conf 47 # 43 # newmac replaces : separator with - and only lowercase for pxelinux 48 44 my $newmac = $mac; 49 45 $newmac =~ tr/A-Z/a-z/; 50 46 $newmac =~ s/:/-/g; 51 open(DHCP, "> $dhcp") || die "Unable to open $dhcp for writing"; 52 print DHCP "$dhcpcnt"; 53 print DHCP "host host-$newmac {\n"; 54 print DHCP " hardware ethernet $mac;\n"; 55 print DHCP " fixed-address $ip;\n"; 56 print DHCP "}\n"; 57 close(DHCP); 47 48 my $foundit = 0; 49 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; 66 } 67 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); 58 79 59 80 # Relaunch DHCP server 60 81 system("sudo /etc/init.d/dhcpd restart"); 61 82 62 # mount the ISO to get kernel and initrd83 # Get the ID given by LinuxCOE to prepare kernel/initrd/ks 63 84 my $iso=basename($url); 64 85 my $id=$iso; … … 68 89 my $ks=$url; 69 90 $ks =~ s/img([0-9]+)\.iso/ks$1.cfg/; 70 mkdir "$mnt",0755;71 system("sudo /bin/mount -o loop $linuxcoe/$iso $mnt");72 copy("$mnt/isolinux/vmlinuz","$pxe/../linuxcoe/$k") or die "Copy failed: $!";73 copy("$mnt/isolinux/initrd.img","$pxe/../linuxcoe/$i") or die "Copy failed: $!";74 system("sudo /bin/umount $mnt");75 91 76 92 # Updates PXElinux … … 92 108 close(PXE); 93 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"); 94 116 95 117 # Based on Version 2.4 27-Sep-1996 Charles Bailey bailey@genetics.upenn.edu
Note: See TracChangeset
for help on using the changeset viewer.
