# -*- perl -*-
# vim: syntax=perl

# $Id: make_pxeboot.plm,v 1.2 2005/10/17 20:02:16 thomas Exp $

# Create the pxe boot default config from .xml files

# $Log: make_pxeboot.plm,v $
# Revision 1.2  2005/10/17 20:02:16  thomas
# [CSL #283524] file perms for tftpboot
#
# Revision 1.1  2005/07/11 19:26:53  thomas
# Create an arbitrary pxe boot config from .xml file(s)
#

=head1 NAME

What::Command::make_pxeboot -- Create pxe boot config from What config files

=head1 SYNOPSIS

what make_pxeboot I<output-file> I<config-file...>

=head1 DESCRIPTION

This command builds a pxe boot config file from one or more source
What config files.

=head1 OPTIONS

=head1 SEE ALSO

What::Node::Install
What::AllHosts::Install

=cut

package What::Command::make_pxeboot;

use strict;
use Getopt::Long;
use Pod::Usage;
use Data::Dumper;
use FileHandle;
use File::MkTemp;
use Net::hostent;
use Socket;

use base qw(What::Command);
use What::AllHosts::Install;

our $helpmsg = "Build a pxe config file";

###############################################################################

sub main {
  my $self = shift;
  my $what = shift;
  local (@ARGV) = @_;

  my %opts = (
	      debug => $::opts{debug},
	     );

  Getopt::Long::Configure ("bundling");
  my ($help);
  my $res = GetOptions (
			'help'       => \$help,
		       );

  $res or $what->err ("Bad option passed to make_pxeboot command!\n");

  ($help || !$res) and return $self->help;

  if (@ARGV<2) {
    $what->err ("Insufficient parameters given.\n");
    return $self->help;
  }

  my $outfile = shift @ARGV;

  my $pxe = What::AllHosts::Install->make_pxeboot ($what, @ARGV);

  if ($outfile eq '-') {
    print $pxe;
  } else {
    $what->check_and_replace_content ($outfile, $pxe, 1000, 1, undef, undef, 0644);
  }

  return 0;
}


###############################################################################

1;

