summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Ginies <aginies@mandriva.com>2004-01-14 16:31:46 +0000
committerAntoine Ginies <aginies@mandriva.com>2004-01-14 16:31:46 +0000
commit17031b68099abee982c17eeafc9043cca361e3b1 (patch)
treed336f5735c360b58103eeb6ddb900ef5053d7f3b
parent48fd551cf6be41952a8f594fbb34cb169b4c26b0 (diff)
downloaddrakwizard-17031b68099abee982c17eeafc9043cca361e3b1.tar
drakwizard-17031b68099abee982c17eeafc9043cca361e3b1.tar.gz
drakwizard-17031b68099abee982c17eeafc9043cca361e3b1.tar.bz2
drakwizard-17031b68099abee982c17eeafc9043cca361e3b1.tar.xz
drakwizard-17031b68099abee982c17eeafc9043cca361e3b1.zip
can set default pxe, and add an image in PXE menu
-rw-r--r--pxe_wizard/Pxe.pm258
1 files changed, 216 insertions, 42 deletions
diff --git a/pxe_wizard/Pxe.pm b/pxe_wizard/Pxe.pm
index b06a8c8d..4066c8cb 100644
--- a/pxe_wizard/Pxe.pm
+++ b/pxe_wizard/Pxe.pm
@@ -30,39 +30,41 @@ use MDK::Wizard::Wizcommon;
my $wiz = new MDK::Wizard::Wizcommon;
+#my $INSTALLDIR = "/var/install/pxe";
+#my $IA64PATH = '/IA64PC';
+
my $TMPDIR = '/tmp';
-my $CLIENTPATH = 'PXEClient';
-my $IA64PATH = 'IA64PC';
+my $HOSTNAME = chomp_(`hostname`);
my $TFTPDIR = "/var/lib/tftpboot";
-my $INSTALLDIR = "/var/install/pxe";
+my $CLIENTPATH = '/X86PC/linux';
+my $X86 = $TFTPDIR . $CLIENTPATH;
+my $IMGPATH = $X86 . '/images';
+my $PXEHELP = $X86 . '/help.txt';
+my $PXEMESSAGE = $X86 . '/messages';
+my $PXEDEFAULT = $X86 . '/pxelinux.cfg/default';
+
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 $MEMDISK = $SYSLINUXPATH . '/memdisk';
+my $XINETDDIR = "/etc/xinetd.d";
my $o = {
- name => N("PXE Wizard"),
+ name => N("PXE Wizard (devel)"),
var => {
-
-
+ IMG => '/tmp/t.img',
+ PXENAME => '92',
+ DESCR => 'install 9.2',
},
- needed_rpm => [ 'pxe', 'tftp-server' ],
+ needed_rpm => [ 'pxe', 'tftp-server', 'xinetd' ],
};
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"),
+# 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."),
@@ -71,13 +73,13 @@ $o->{pages} = {
$o->{var}{wiz_level} ||= 1;
},
post => sub {
- if ($o->{var}{wiz_level} == 2) {
+ 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("Which operation:"), val => \$o->{var}{wiz_level}, list => [ keys %level ], format => sub { $level{$_[0]} } },
],
@@ -85,51 +87,78 @@ $o->{pages} = {
next => 'pxeserver',
},
addimg => {
- name => N("Add a boot Image") . "\n\n" . N("Where is that boot image ?"),
+ name => N("Add a boot Image") . "\n\n" . N("Path to image: Full path to image") . "\n\n" . N("PXE Name: Name in PXE menu (one word/number, no space)"),
data => [
- { label => "", val => \$o->{var}{dummy} },
+ { label => "PXE Name:", val => \$o->{var}{PXENAME} },
+ { label => "PXE Description:", val => \$o->{var}{DESCR} },
+ { label => "Full Path to image:", val => \$o->{var}{IMG} },
],
+ post => \&test_data,
next => 'summaryadd',
},
removeimg => {
- name => N("Remove a boot Image") . "\n\n" . N("Which one ?"),
- data => [
- { label => "", val => \$o->{var}{dummy} },
- ],
- next => 'summaryremove',
+ name => N("Remove a boot Image") . "\n\n" . N("Which one ?"),
+ data => [
+ { label => "Wich one ?", val => \$o->{var}{PXENAME} },
+ ],
+ next => 'summaryremove',
},
modifyimg => {
name => N("Add Option to boot image") . "\n\n" . N("on Which image ?"),
data => [
- { label => "", val => \$o->{var}{dummy} },
+ { label => "Wich one ?", val => \$o->{var}{PXENAME} },
],
next => 'summarymodify',
},
pxeserver => {
- name => N("Set PXE server") . "\n\n" . N("We will use a special dhcpd.conf"),
- data => [
- { label => "", val => \$o->{var}{dummy} },
- ],
- next => 'summaryserver',
+ name => N("Set PXE server") . "\n\n" . N("We will use a special dhcpd.conf"),
+ next => 'summaryserver',
},
error_dir => {
name => N('Error Should be a directory'),
next => '',
},
- summaryserver => {
- name => N(''),
- next => 'endserver',
+ error_img => {
+ name => N('Please provide a Bootable image...'),
+ next => 'addimg',
+ },
+ error_name => {
+ name => N('Please provide a correct name in PXE entry (one word)'),
+ next => 'addimg',
},
+ simmilar_entry => {
+ name => N('Similar Name is already used in PXE menu entry') . "\n\n" . N("Please provide another Pxe Menu Name"),
+ next => 'addimg',
+ },
+ summaryserver => {
+ name => N('Now will prepapre all default files to get PXE server'),
+ data => [
+ { label => N("Tftp directory"), fixed_val => \$TFTPDIR },
+ { label => N("Image path"), fixed_val => \$IMGPATH },
+ { label => N("PXE \'default\' file "), fixed_val => \$PXEDEFAULT },
+ { label => N("PXE \'help\' file"), fixed_val => \$PXEHELP },
+ ],
+ post => \&do_it_pxe,
+ next => 'endserver',
+ },
summarymodify => {
- name => N(''),
- next => 'endmodify',
+ name => N('Now will Modify boot options in image'),
+ post => \&do_it_modify,
+ next => 'endmodify',
},
summaryremove => {
- name => N(''),
- next => 'endremove',
+ name => N('Now will remove your PXE boot image'),
+ post => \&do_it_remove,
+ next => 'endremove',
},
summaryadd => {
- name => N(''),
+ name => N('Now will add your PXe boot image'),
+ data => [
+ { label => "PXE Name:", fixed_val => \$o->{var}{PXENAME} },
+ { label => "PXE Description:", fixed_val => \$o->{var}{DESCR} },
+ { label => "Path to image:", fixed_val => \$o->{var}{IMG} },
+ ],
+ post => \&do_it_add,
next => 'endadd',
},
endadd => {
@@ -162,16 +191,161 @@ $o->{pages} = {
},
};
-sub syslinux_prep {
- # cp_af( "/memdisk", $FULLINTEL);
+sub memlinux_prep {
+ if (!-f "$X86/memdisk") {
+ cp_af($MEMDISK, $X86);
+ }
+}
+
+sub test_data {
+ $o->{var}{PXENAME} =~ /^\w+$/ or return 'error_name';
+ if (!-f $o->{var}{IMG}) {
+ return 'error_img'
+ }
+ if (any { /^$o->{var}{PXENAME}/ } cat_($PXEHELP)) {
+ return 'simmilar_entry'
+ }
+}
+
+sub enable_tftps {
+ substInFile { s/disable.*/disable = no/ } "$XINETDDIR/tftp";
+}
+
+sub tftp_blksize {
+ # $o should be with W or not N
+ my ($o) = @_;
+ if ($o =~ /W/) {
+ substInFile { s/server_args.*/server_args = -r blksize -s $TFTPDIR/ } "$XINETDDIR/tftp";
+ } else {
+ substInFile { s/server_args.*/server_args = -s $TFTPDIR/ } "$XINETDDIR/tftp";
+ }
}
+
sub crea_wdir {
if (-e $TMPDIR) { rm_rf($TMPDIR);
}
mkdir_p($TMPDIR);
}
+sub add_in_default {
+ my ($NAME) = @_;
+ if (!any { /${NAME}_BEGIN/ } cat_($PXEDEFAULT)) {
+ append_to_file($PXEDEFAULT ,<<EOF);
+# TAG: ${NAME}_BEGIN
+label $NAME
+ KERNEL memdisk
+ APPEND initrd=images/$NAME.img
+# TAG: ${NAME}_END
+EOF
+ }
+}
+
+sub add_in_help {
+ my ($NAME, $DESCR) = @_;
+ append_to_file($PXEHELP ,<<EOF);
+$NAME : $DESCR
+EOF
+}
+
+sub add_img {
+ my ($SIMG, $PXENAME) = @_;
+ cp_af($SIMG, $IMGPATH . "/" . $PXENAME . '.img');
+}
+
+sub get_menu_entry {
+ my ($NAME) = @_;
+ my ($NAME_bloc) = $PXEDEFAULT =~ /# TAG: ${NAME}_BEGIN(.*?)# TAG: ${NAME}_END/s or die "unable to find Menu entry section";
+ $NAME_bloc;
+}
+
+sub remove_in_menu {
+ my ($NAME) = @_;
+ substInFile {
+ s/${NAME}_BEGIN.* \n\n\n//;
+ } $PXEDEFAULT;
+}
+
+sub remove_in_help {
+ my ($NAME) = @_;
+ substInFile {
+ s/^$NAME//;
+ } $PXEHELP;
+}
+
+sub remove_img {
+ my ($PXENAME) = @_;
+ rm_rf($IMGPATH . "/" . $PXENAME . '.img');
+}
+
+sub default_pxe_menu {
+ output($PXEHELP, <<EOF);
+Available images are:
+---------------------
+local: local boot
+EOF
+
+ output($PXEDEFAULT, <<EOF);
+PROMPT 1
+DEFAULT local
+DISPLAY messages
+TIMEOUT 50
+F1 help.txt
+label local
+ LOCALBOOT 0
+
+EOF
+}
+
+sub default_pxe_messages {
+ output($PXEMESSAGE, <<EOF);
+
+ Welcome to Mandrake Linux PXE Server
+ Pxelinux
+ . .-----------------------------------.
+ /|\\ / Press F1 for available images \\
+ /_|_\\ \\ Hosted by $HOSTNAME
+ \\ | / _ /'-----------------------------------'
+ \\|/ (') /
+ '. U / (O__
+ . '. / (o_ (o_ (0_ //\\
+ {o_ (o_ (o_ (o_ (o_ //\\ //\\ //\\ // )
+ (')_ (`)_ (/)_ (/)_ (/)_ V_/_ V_/_ V_/_ V__/_
+ ---------------------------------------------------------
+
+ press F1 for help
+EOF
+
+}
+
+sub do_it_add {
+ return if $::testing;
+ add_in_help($o->{var}{PXENAME}, $o->{var}{DESCR});
+ add_in_default($o->{var}{PXENAME});
+ add_img($o->{var}{IMG}, $o->{var}{PXENAME});
+}
+
+sub do_it_remove {
+ return if $::testing;
+}
+
+sub do_it_modify {
+ return if $::testing;
+}
+
+sub do_it_pxe {
+ return if $::testing;
+ my $in = 'interactive'->vnew('su', 'PXE server');
+ my $w = $in->wait_message(N("PXE server"), N("Configuring PXE server on your system..."));
+ memlinux_prep();
+ default_pxe_menu();
+ default_pxe_messages();
+ enable_tftps();
+ tftp_blksize('N');
+ map { system("service $_ restart"); $_ } qw(xinetd pxe);
+ undef $w;
+}
+
sub new {
my ($class, $conf) = @_;