Changeset 49 for devel/dploy-pxe/bin/dploy-add2pxe
- Timestamp:
- 04/16/08 15:58:35 (4 years ago)
- File:
-
- 1 edited
-
devel/dploy-pxe/bin/dploy-add2pxe (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
devel/dploy-pxe/bin/dploy-add2pxe
r47 r49 12 12 use File::Basename; 13 13 14 my %opts; 15 my $type = ""; 16 my $mac = ""; 17 my $url = ""; 18 my $ksdevice = "eth0"; 19 my $prefix = ""; 20 my $mrserver = ""; 21 my $mrpath = ""; 22 14 23 GetOptions("help|?|h" => \$opts{'h'}, 15 "mode|m=s" => \$opts{'mode'}, # Mode is MR or SD 16 "mac|m=s" => \$opts{'mac'}, # Mac address 17 "ip|i=s" => \$opts{'ip'}, # 18 "netmask|n=s" => \$opts{'mask'}, 19 "gw|g=s" => \$opts{'gw'}, 24 "type|t=s" => \$opts{'type'}, # Type is MondoRescue or LinuxCOE 25 "mac|m=s" => \$opts{'mac'}, # Mac address 26 "url|u=s" => \$opts{'url'}, # URL of ISO image containing kernel, modules and answer file 27 ) || dploy_syntax(-1,0); 20 28 29 if (defined $opts{'type'}) { 30 $type = $opts{'type'}; 31 } 21 32 33 if (defined $opts{'h'}) { 34 dploy_syntax(0,1); 35 } 22 36 23 37 # Root of the PXE setup 24 my $pxe="/tftpboot/pxelinux.cfg"; 25 # Where to find the LinuxCOE created ISO on the SystemDesigner server 26 my $linuxcoe="/var/ftp/html/scratch_monkey/systemdesigner"; 27 # Where to find the Mondorescue created ISO on the Images server 28 my $mondorescue="/var/ftp/html/mondorescue/iso"; 38 my $pxe=dploy_get_conf("pathpxe"); 39 29 40 # temporary mountpoint 30 my $mnt="/tmp/mnt-dploy"; 41 if (not defined $ENV {'TMPDIR'}) { 42 $ENV{'TMPDIR'} = "/tmp"; 43 } 44 my $tmp=tempdir("dploy.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1); 45 my $mnt="$tmp/iso"; 46 my $mnt2="$tmp/nfs"; 31 47 32 48 my $mac=$ARGV[0] || ""; 33 49 50 # Check Mac consitency (to be done in an external function) 34 51 if ($mac !~ /^(?:[[:xdigit:]]{1,2}[-:]){5}[[:xdigit:]]{1,2}$/) { 35 52 print "Syntax: dploy-add2pxe MAC url-to-iso\n"; … … 45 62 $newmac =~ s/:/-/g; 46 63 47 my $url=$ARGV[1]; 64 # Check URL syntax 65 if (defined $opts{'url'}) { 66 $url = $opts{'url'}; 67 } 48 68 49 69 if ($url !~ /(\w+):\/\/([^\/:]+)(:\d+)?\/(.*)/) { … … 51 71 exit(-1); 52 72 } 73 74 # Get Mondorescue values 75 $mrserver = dploy_get_url(); 76 $mrpath = dploy_get_url(); 53 77 54 78 # Get the ID given by LinuxCOE/MondoRescue to prepare kernel/initrd/ks … … 60 84 my $ks=$url; 61 85 $ks =~ s/img([0-9]+)\.iso/ks$1.cfg/; 86 87 # mount the ISO to get kernel and initrd 88 mkdir "$mnt",0755; 89 if ($Type == "LinuxCOE") { 90 system("sudo /bin/mount -o loop $linuxcoe/$iso $mnt"); 91 } else { 92 system("sudo /bin/mount -t nfs $mrserver:$mrpath $mnt2"); 93 system("sudo /bin/mount -o loop $mnt2/$prefix-1.iso $mnt"); 94 } 95 # Install script will have to check (and create if not existing) /tftpboot/tmp 96 copy("$mnt/isolinux/vmlinuz","$pxe/../tmp/$k") or die "Copy failed: $!"; 97 copy("$mnt/isolinux/initrd.img","$pxe/../tmp/$i") or die "Copy failed: $!"; 98 99 # Get the Command Line parameters for MondoRescue restoration 100 open(ISOLINUX, "$mnt/isolinux.cfg") || die "Unable to open $mnt/isolinux.cfg for writing"; 101 while ( <ISOLINUX> ) { 102 if (/label nuke/) { 103 my $cliparams = <ISOLINUX>; # kernel line 104 $cliparams = <ISOLINUX>; # append line 105 } 106 } 107 $cliparams =~ s/initrd=[a-z.] /initrd=initrd=mondorescue\/$i /; 108 109 close ISOLINUX; 110 # All done with ISO image... umounting 111 system("sudo /bin/umount $mnt"); 112 62 113 63 114 # Updates PXElinux … … 73 124 localboot 0 74 125 75 label linuxcoe76 kernel linuxcoe/$k77 append ksdevice=eth0 ks=$ks initrd=linuxcoe/$i text78 126 EOF 79 127 close(PXE); 80 128 81 # mount the ISO to get kernel and initrd 82 mkdir "$mnt",0755; 83 system("sudo /bin/mount -o loop $linuxcoe/$iso $mnt"); 84 copy("$mnt/isolinux/vmlinuz","$pxe/../linuxcoe/$k") or die "Copy failed: $!"; 85 copy("$mnt/isolinux/initrd.img","$pxe/../linuxcoe/$i") or die "Copy failed: $!"; 86 system("sudo /bin/umount $mnt"); 129 # Customize pxe file depending on Job type submited 130 open(PXE, ">> $pxe/01-$newmac") || die "Unable to open $pxe/01-$newmac for writing"; 131 if ($Type == "LinuxCOE") { 132 print PXE "label linuxcoe\n"; 133 print PXE " kernel linuxcoe/$k\n"; 134 print PXE " append ksdevice=$ksdevice ks=$ks initrd=linuxcoe/$i text\n"; 135 } else { 136 print PXE "label mondorecue\n"; 137 print PXE " kernel mondorescue/$k\n"; 138 print PXE " append $cliparams pxe prefix=$prefix ipconf=$ksdevice:dhcp nfsmount=$mrserver:$mrpath\n"; 139 } 140 close(PXE); 141
Note: See TracChangeset
for help on using the changeset viewer.
