pf-tools commit: r551 [ccaillet-guest] - /trunk/sbin/pxe_linuxcfg
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Thu Jan 17 15:29:46 UTC 2008
Author: ccaillet-guest
Date: Thu Jan 17 15:29:38 2008
New Revision: 551
URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=551
Log:
oops ... pxe_linuxcfg is missing :)
Added:
trunk/sbin/pxe_linuxcfg (with props)
Added: trunk/sbin/pxe_linuxcfg
URL: http://svn.debian.org/wsvn/pf-tools/trunk/sbin/pxe_linuxcfg?rev=551&op=file
==============================================================================
--- trunk/sbin/pxe_linuxcfg (added)
+++ trunk/sbin/pxe_linuxcfg Thu Jan 17 15:29:38 2008
@@ -1,0 +1,131 @@
+#!/usr/bin/perl
+##
+## $Id$
+##
+## Copyright (C) 2007-2008 Christophe Caillet <quadchris at free.fr>
+## Copyright (C) 2003-2005 Damien Clermonte <damien at sitadelle.com>
+## Copyright (C) 2001-2003 Olivier Molteni <olivier at molteni.net>
+##
+## This program is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License
+## as published by the Free Software Foundation; either version 2
+## of the License, or (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+##
+
+# use strict;
+use warnings;
+
+use PFTools::Net;
+use PFTools::Update;
+use Data::Dumper ;
+
+sub Mk_pxe_bootfile ($;$) {
+ my ( $Z, $template ) = @_;
+ my $oldout;
+ my $s;
+ my $hash_tpl = {} ;
+
+ my $pxelinuxconfdir = dirname ( $template ) ;
+ unless ( open ( TPL, $template ) ) {
+ die "Unable to open file ".$template.": ".$!."\n" ;
+ }
+ @{$hash_tpl->{'default'}} = <TPL> ;
+ close ( TPL ) ;
+
+ my $dhcpvlanregex
+ = '^([^.]+)\.('
+ . join( '|', @{ $Z->{'SOA'}->{'dhcpvlan'} } )
+ . ')(\.*)?$';
+
+ foreach $s ( sort ( keys %{ $Z->{'SERVERS'}->{'BY_ADDR'} } ) ) {
+ my $m;
+ my $N = $Z->{'SERVERS'}->{'BY_ADDR'}->{$s};
+
+ foreach $m ( sort ( keys %{ $N->{'SRVLIST'} } ) ) {
+ my $nam;
+ my $M = $N->{'SRVLIST'}->{$m};
+
+ foreach $nam ( sort ( keys %{ $M->{'zone'} } ) ) {
+ if ( $nam =~ /$dhcpvlanregex/ ) {
+ my $nam2 = $1;
+
+ #my $vlan2 = $2;
+ if ( defined( $M->{'zone'}->{$nam}->{'ether'} )
+ && defined( $M->{'filename'} )
+ && defined( $M->{'pxefilename'} ) )
+ {
+ if ( $M->{'filename'} ne 'pxelinux.0' ) {
+ Warn( $ERR_SYNTAX,
+ "Mk_pxelinuxconf["
+ . $nam2
+ . "]: pxefilename exists but filename is not pxelinux.0!"
+ );
+ }
+ my $addr = Resolv( $nam . '.' . $Z->{'SOA'}->{'name'}, $Z );
+ if ( defined $addr
+ && $addr ne $nam . '.' . $Z->{'SOA'}->{'name'} )
+ {
+ my $hexaddr = sprintf( '%02X%02X%02X%02X',
+ split( '\.', $addr ) );
+
+ if ( -e $pxelinuxconfdir . "/" . $hexaddr ) {
+ unlink( $pxelinuxconfdir . "/" . $hexaddr );
+ }
+
+ open( PXELINUXCFG,
+ ">" . $pxelinuxconfdir . "/" . $hexaddr )
+ || die "impossible d'ecrire "
+ . $pxelinuxconfdir . "/"
+ . $hexaddr . ": "
+ . $!;
+
+ my $temptemplatecontent ;
+ if ( ! defined ( $M->{'pxetemplate'} ) ) {
+ $temptemplatecontent = join ( "", @{$hash_tpl->{'default'}} ) ;
+ } else {
+ my $tpl_name ;
+ $tpl_name = $M->{'pxetemplate'} ;
+ $tpl_name =~ s%.*/%%;
+ if ( ! defined ( $hash_tpl->{$tpl_name} ) ) {
+ my $tpl ;
+ ( $M->{'pxetemplate'} =~ /^\// ) ? $tpl = $M->{'pxetemplate'} : $tpl = $pxelinuxconfdir."/".$M->{'pxetemplate'};
+ print "Need to open ".$tpl."\n" ;
+ open ( TPL, $tpl ) || die "impossible d'ouvrir " . $tpl . ": " . $!;
+ @{$hash_tpl->{$tpl_name}} = <TPL> ;
+ close ( TPL ) ;
+ }
+ $temptemplatecontent = join ( "", @{$hash_tpl->{$tpl_name}} ) ;
+ }
+ $temptemplatecontent =~ s/%KERNEL%/$M->{pxefilename}/gs;
+ $temptemplatecontent =~ s/%INITRD%/$M->{initrd}/gs;
+# my $ramdisk_size = Get_Ramdisk_size_from_Initrd($M->{'initrd'} );
+ my $ramdisk_size = 4096 ;
+ $temptemplatecontent =~ s/%RAMDISK_SIZE%/$ramdisk_size/gs;
+ my $cmdline = $M->{'cmdline'} || '';
+ $temptemplatecontent =~ s/%CMDLINE%/$cmdline/gs;
+ print PXELINUXCFG $temptemplatecontent;
+ close(PXELINUXCFG);
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+my ( $SRC, $TEMPLATE ) = @ARGV ;
+unless ( $SRC && $TEMPLATE ) {
+ warn "Usage: $0 src template\n";
+ die "\t(confs will be written do template's dirname)\n";
+}
+
+Mk_pxe_bootfile ( Init_lib_net ( Get_source ( $SRC ) ), Get_source ( $TEMPLATE ) ) ;
Propchange: trunk/sbin/pxe_linuxcfg
------------------------------------------------------------------------------
svn:executable = *
More information about the pf-tools-commits
mailing list