#!/usr/bin/perl -w

# Drakwizard

# Copyright (C) 2003 Mandrakesoft
#
# Author: Antoine Ginies <aginies _ateuh _ mandrakesoft.com>
#
# 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

package MDK::Wizard::Pxe;
use lib qw(/usr/lib/libDrakX);
use strict;

use common;
use services;
use MDK::Wizard::Wizcommon;

my $wiz = new MDK::Wizard::Wizcommon;

my $TMPDIR = '/tmp';
my $CLIENTPATH = 'PXEClient';
my $IA64PATH = 'IA64PC';
my $TFTPDIR = "/var/lib/tftpboot";
my $INSTALLDIR = "/var/install/pxe";
my $CONF = '/etc/pxe.conf';
my $SYSLINUXPATH = '/usr/lib/syslinux/';
my $PXEDEFAULT = 'pxelinux.cfg/default'

my $PXEMENU = "$TMPDIR/default.pxe";
my $PXEMESSAGE = "$TMPDIR/message.pxe";
my $PXEMENU = "$TMPDIR/default.pxe";
my $PXEMESSAGE = "$TMPDIR/message.pxe";
my $PXEHELP = "$TMPDIR/help.txt.pxe";

my $o = {
	 name => N("PXE Wizard"),
	 var => {


		},
	 needed_rpm => [ 'pxe', 'tftp-server' ],
	};

my %level = (
             1 => N("PXE - Set PXE server"),
             2 => N("add - Add image in PXE"),
	     3 => N("remove - remove image in PXE"),
	     4 => N("Modify - Modify image in PXE"),
	    );



$o->{pages} = {
	       welcome => {
			   name => N("PXE wizard") . "\n\n" . N("Set a PXE server.") . "\n\n" . N("This wizard will help you configuring the PXE server. This configuration will provide a pxe services, and ability to add/remove/modify boot images."),
			   no_back => 1,
			   pre => sub {
			     $o->{var}{wiz_level} ||= 1;
			   },
			   post => sub {
			     if ($o->{var}{wiz_level} == 2) { 
			       return 'addimg' }
			     elsif ($o->{var}{wiz_level} == 3) {
			       return 'removeimg' }
			     elsif ($o->{var}{wiz_level} == 4) {
			       return 'modifyimg' }
			     },
			   data => [
				    { label => N("Wich operation:"), val => \$o->{var}{wiz_level}, list => [ keys %level ], format => sub { $level{$_[0]} } },
				   ],
			   no_back => 1,
			   next => 'pxeserver',
			  },
	       addimg => {
			  name => N("Add a boot Image") . "\n\n" . N("Where is that boot image ?"),
			  data => [
				   { label => "", val => \$o->{var}{} },
				  ],
			  next => 'summaryadd',
			 },
	       removeimg => {
			  name => N("Remove a boot Image") . "\n\n" . N("Which one ?"),
			  data => [
				   { label => "", val => \$o->{var}{} },
				  ],
			  next => 'summaryremove',
			    },
	       modifyimg => {
			     name => N("Add Option to boot image") . "\n\n" . N("on Wich image ?"),
			     data => [
				      { label => "", val => \$o->{var}{} },
				     ],
			     next => 'summarymodify',
			    },
	       pxeserver => {
			  name => N("Set PXE server") . "\n\n" . N("We will use a special dhcpd.conf"),
			  data => [
				   { label => "", val => \$o->{var}{} },
				  ],
			  next => 'summaryserver',
			    },
	       error_dir => {
			     name => N('Error Should be a directory'),
			     next => '',
			    },
	       summaryserver => {
			      name => N(''),
			      next => 'endserver',
			     },
	       summarymodify => {
			      name => N(''),
			      next => 'endmodify',
				},
	       summaryremove => {
			      name => N(''),
			      next => 'endremove',
				},
	       summaryadd => {
			      name => N(''),
			      next => 'endadd',
			     },
	       endadd => {
			     name => N('Congratulations'),
			     data => [ { label => N('The wizard successfully add a PXE image.') } ],
                             no_back => 1,
                             end => 1,
                             next => 0
			    },
	       endremove => {
			     name => N('Congratulations'),
			     data => [ { label => N('The wizard successfully remove a PXE image.') } ],
                             no_back => 1,
                             end => 1,
                             next => 0
			    },
	       endmodify => {
			     name => N('Congratulations'),
			     data => [ { label => N('The wizard successfully modify image(s).') } ],
                             no_back => 1,
                             end => 1,
                             next => 0
			    },
	       endserver => {
			     name => N('Congratulations'),
			     data => [ { label => N('The wizard successfully configured Your PXE server.') } ],
                             no_back => 1,
                             end => 1,
                             next => 0
			    },
	      };

sub syslinux_prep {
  cp_af( . "/memdisk", $FULLINTEL);
}

sub crea_wdir {
  if (-e $TMPDIR) { rm_rf($TMPDIR);
	     }
  mkdir_p($TMPDIR);
}


sub new {
    my ($class, $conf) = @_;
    bless {
            o   => $o,
	   }, $class;
}

1;