Ignore:
Timestamp:
06/02/08 19:14:30 (4 years ago)
Author:
bruno
Message:
  • pod content for dploy-add2pxe
  • type is changed to lowercase before usage
  • Fix various typos ($url inexistent, ...)
  • use a new $destdir var to designate the dir in which place tftpboot files
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/dploy-pxe/bin/dploy-add2pxe

    r53 r59  
    1818use Dploy::Base; 
    1919 
    20 my %opts; 
    21 my $url = undef; 
    22 my $ksdevice = "eth0"; 
    23 my $prefix = undef; 
     20=pod 
     21 
     22=head1 NAME 
     23 
     24dploy-add2pxe - Update PXE configuration file for dploy.org 
     25 
     26=head1 DESCRIPTION 
     27 
     28dploy-add2pxe helps you keeping your PXE configuration up to date  
     29 
     30=head1 SYNOPSIS 
     31 
     32dploy-add2pxe -t mondorescue|linuxcoe -m MAC-address -u ISO-image-URL 
     33 
     34dploy-add2pxe --type mondorescue|linuxcoe --mac MAC-address --url ISO-image-URL 
     35 
     36=head1 OPTIONS 
     37 
     38=over 4 
     39 
     40=item B<-h|--help> 
     41 
     42Print a brief help message and exits. 
     43 
     44=cut 
     45 
     46 
     47my %opts;                   # GetOpt Hash 
     48my $url = undef;            # url of the boot ISO image 
     49my $ksdevice = "eth0";      # NIC device to boot on 
     50my $prefix = undef;         # Prefix of the MondoRescue image 
     51my $cliparams;              # Command Line parames of the MondoRescue image 
     52my $destdir = undef;        # Destination driectory for tftp files 
    2453 
    2554pb_syntax_init("dploy-add2pxe Version PBVER-PBREV\n"); 
     
    3564} 
    3665 
    37 pb_conf_add("PBCONF/dploy.conf"); 
     66# type is always lowercase 
     67$opts{'type'} = lc($opts{'type'}); 
     68 
     69my $dploydir = "PBCONF"; 
     70pb_conf_add("$dploydir/dploy.conf"); 
    3871 
    3972# Root of the PXE setup 
    40 my $pxe=pb_conf_get("pathpxe"); 
     73my ($pxe)=pb_conf_get("pathpxe"); 
    4174my $pathpxe = $pxe->{"default"}; 
    4275 
     
    5285 
    5386# Get the ID given by LinuxCOE/MondoRescue to prepare kernel/initrd/ks 
    54 my $iso=basename($url); 
     87my $iso=basename($opts{'url'}); 
    5588my $id=$iso; 
    5689$id =~ s/img([0-9]+)\.iso/$1/; 
    5790my $k="k-$id"; 
    5891my $i="i-$id"; 
    59 my $ks=$url; 
     92my $ks=$opts{'url'}; 
    6093$ks =~ s/img([0-9]+)\.iso/ks$1.cfg/; 
    6194 
    6295# mount the ISO to get kernel and initrd 
    6396mkdir "$mnt",0755; 
    64 if ($opts{'type'} == "LinuxCOE") { 
     97if ($opts{'type'} =~ /linuxcoe/) { 
    6598    my $bn = basename($mrpath); 
    6699    unlink("$ENV{'PBTMP'}/$bn"); 
    67     pb_system("cd \$PBTMP ; wget $url","Downloading $url"); 
     100    pb_system("cd \$PBTMP ; wget $opts{'url'}","Downloading $opts{'url'}"); 
    68101    pb_system("sudo /bin/mount -o loop $ENV{'PBTMP'}/$bn $mnt","Mounting $bn"); 
    69 } elsif ($opts{'type'} == "MondoRescue") { 
     102} elsif ($opts{'type'} =~ /mondorescue/) { 
    70103    pb_system("sudo /bin/mount -t nfs $mrserver:$mrpath $mnt2","Mountig NFS $mrserver:$mrpath"); 
    71104    pb_system("sudo /bin/mount -o loop $mnt2/$prefix-1.iso $mnt","Mounting LOOP $mnt2/$prefix-1.iso"); 
     
    76109 
    77110# Install script will have to check (and create if not existing) /tftpboot/tmp 
    78 copy("$mnt/isolinux/vmlinuz","$pathpxe/../tmp/$k") or die "Copy failed: $!"; 
    79 copy("$mnt/isolinux/initrd.img","$pathpxe/../tmp/$i") or die "Copy failed: $!"; 
     111# $pathpxe is normaly setup correctly by package install 
     112$destdir = "$pathpxe/../$opts{'type'}"; 
     113copy("$mnt/isolinux/vmlinuz","$destdir/$k") or die "Copy of $mnt/isolinux/vmlinuz to $destdir/$k failed: $!"; 
     114copy("$mnt/isolinux/initrd.img","$destdir/$i") or die "Copy of $mnt/isolinux/initrd.img to $destdir/$i failed: $!"; 
    80115 
    81116# Get the Command Line parameters for MondoRescue restoration 
    82 my $cliparams; 
    83 open(ISOLINUX, "$mnt/isolinux.cfg") || die "Unable to open $mnt/isolinux.cfg for writing"; 
    84 while ( <ISOLINUX> ) { 
    85     if (/label nuke/) { 
    86         $cliparams = <ISOLINUX>;        # kernel line 
    87         $cliparams = <ISOLINUX>;        # append line 
     117if ($opts{'type'} =~ /MondoRescue/i) { 
     118    open(ISOLINUX, "$mnt/isolinux.cfg") || die "Unable to open $mnt/isolinux.cfg for writing"; 
     119    while ( <ISOLINUX> ) { 
     120        if (/label nuke/) { 
     121            $cliparams = <ISOLINUX>;        # kernel line 
     122            $cliparams = <ISOLINUX>;        # append line 
     123        } 
    88124    } 
     125    $cliparams =~ s/initrd=[A-z.] /initrd=mondorescue\/$i /; 
     126    close ISOLINUX; 
    89127} 
    90 $cliparams =~ s/initrd=[a-z.] /initrd=initrd=mondorescue\/$i /; 
    91128 
    92 close ISOLINUX; 
    93129# All done with ISO image... umounting 
    94130pb_system("sudo /bin/umount $mnt","Umount ISO image"); 
     
    110146 
    111147EOF 
    112 close(PXE); 
    113148 
    114149# Customize pxe file depending on Job type submited 
    115 open(PXE, ">> $pathpxe/01-$mac") || die "Unable to open $pathpxe/01-$mac for writing"; 
    116 if ($opts{'type'} == "LinuxCOE") { 
    117     print PXE "label linuxcoe\n"; 
    118     print PXE "  kernel linuxcoe/$k\n"; 
    119     print PXE "  append ksdevice=$ksdevice ks=$ks initrd=linuxcoe/$i text\n"; 
     150if ($opts{'type'} =~ /linuxcoe/) { 
     151    print PXE << "EOF"; 
     152label linuxcoe 
     153  kernel linuxcoe/$k 
     154  append ksdevice=$ksdevice ks=$ks initrd=linuxcoe/$i text 
     155EOF 
    120156} else { 
    121     print PXE "label mondorescue\n"; 
    122     print PXE "  kernel mondorescue/$k\n"; 
    123     print PXE "  append $cliparams pxe prefix=$prefix ipconf=$ksdevice:dhcp nfsmount=$mrserver:$mrpath\n"; 
     157    print PXE << "EOF"; 
     158label mondorescue 
     159  kernel mondorescue/$k 
     160  append $cliparams pxe prefix=$prefix ipconf=$ksdevice:dhcp nfsmount=$mrserver:$mrpath 
     161EOF 
    124162} 
    125163close(PXE); 
Note: See TracChangeset for help on using the changeset viewer.