diff options
Diffstat (limited to 'drakpxelinux.pl')
-rw-r--r-- | drakpxelinux.pl | 221 |
1 files changed, 145 insertions, 76 deletions
diff --git a/drakpxelinux.pl b/drakpxelinux.pl index c92ea5c..e951c12 100644 --- a/drakpxelinux.pl +++ b/drakpxelinux.pl @@ -133,10 +133,8 @@ sub get_items() { my ($autocomp) = m!\bautomatic\b=(.*?)\s!; my ($devram) = m!root=/dev/ram3\srw!; my $optionsall = join(' ', grep { ! /$devram/ and ! /initrd=$initall/ and ! /display=$displayall/ and ! /ramdisk_size=$ramdiskall/ and ! /automatic=$autocomp/ and ! /vga=$vgaall/ } split(' ', $allopt)); - my $information; - foreach (cat_($PXEHELP)) { my ($information) = /$label\s:\s(\.*)/; } -# my ($information) = cat_($PXEHELP) =~ /$label\s:\s(\.*)/;# or my $information = "install $label"; if ($label and $kernel and $initall) { + my $information = get_information($label); push @listpxe, { label => $label, info => $information, @@ -157,6 +155,13 @@ sub get_items() { } } +sub get_information { + my ($label) = @_; + my $line = cat_($PXEHELP); + my ($information) = $line =~ /$label : (.*)/; + $information and return $information; +} + sub list_label_pxe() { my @labels; foreach (cat_($conf)) { @@ -179,8 +184,9 @@ sub get_default_pxe { } sub get_default_prompt() { - my ($prompt) = cat_($conf) =~ /^PROMPT\s(\d+)/; - return $prompt; + my $line = cat_($conf); + my ($prompt) = $line =~ /^PROMPT\s(\d+)/; + $prompt and return $prompt; } sub get_default_timeout() { @@ -250,45 +256,98 @@ sub create_model { return $model; } -sub add_item { - my ($model, $treeview) = @_; - my @a; - push @a, { - label => "cooker_add", - info => "install cooker", - kernel => "/images/cooker", - initrd => "images/cooker.rdz", - automatic => "http", - interface => "eth0", - network => "dhcp", - server => "10.0.1.33", - directory => "/install/cooker", - ramdisk => "64000", - vga => "788", - display => ":0", - option => "acpi=ht", - }; - - my $iter = $model->append; - $model->set($iter, - COLUMN_LABEL, $a[-1]{label}, - COLUMN_INFO, $a[-1]{info}, - COLUMN_KERNEL, $a[-1]{kernel}, - COLUMN_INITRD, $a[-1]{initrd}, - COLUMN_AUTOMATIC, $a[-1]{automatic}, - COLUMN_INTERFACE, $a[-1]{interface}, - COLUMN_NETWORK, $a[-1]{network}, - COLUMN_SERVER, $a[-1]{server}, - COLUMN_DIRECTORY, $a[-1]{directory}, - COLUMN_RAMDISK, $a[-1]{ramdisk}, - COLUMN_VGA, $a[-1]{vga}, - COLUMN_DISPLAY, $a[-1]{display}, - COLUMN_OPTION, $a[-1]{option}, - ); - create_dialog(N("add Entry in PXE"), N("A virtual entry in PXE list was created.\n -Now choose the last entry named 'cooker_add' -and choose edit buton. -Otherwise your new entry wont be added to PXE list.")); +sub wizard_add_entry { + my ($widget, $treeview) = @_; + my $model = $treeview->get_model; + + local $::isEmbedded = 0; + my $in = 'interactive'->vnew('su'); + undef $::WizardTable; + undef $::WizardWindow; + $::isWizard = 1; + use wizards; + my $WPXENAME = "cooker"; + my $WINFO = "install cooker"; + my $WALLRDZ = "/home/nis/install/clic/isolinux/alt0/all.rdz"; + my $WVMLINUZ = "/home/nis/install/clic/isolinux/alt0/vmlinuz"; + my $w = wizards->new; + my $wiz = { + name => N("Add PXE entry"), + pages => { + welcome => { + name => N("Add an all.rdz boot image"), + next => 'addimg', + }, + addimg => { + name => N("To boot through network, network computer need a boot image. Morever we need to name this image, so each boot image is related to a name in PXE menu. So user can choose wich image he wants to boot through PXE.") . "\n\n" . N("PXE description is used to explain the rule of the boot image, ie: Mandrake 10 image, Mandrake cooker image..") . N("For technical reason, in case of multiple boot image, it's more simple to boot network computer through a kernel (vmlinuz), and provide one file with all drivers needed (in our case all.rdz).") . "\n\n" . N("Path to all.rdz: provide the full path to all.rdz image") . "\n\n" . N("PXE name: the name displayed in PXE menu (please provide a word or a number, with no space)"), + data => [ + { label => "PXE label:", val => \$WPXENAME }, + { label => "PXE description:", val => \$WINFO }, + { label => "Full path to all.rdz image:", val => \$WALLRDZ }, + { label => "Full path to vmlinuz:", val => \$WVMLINUZ}, + ], + complete => sub { + if (any { /^$WPXENAME :/ } cat_($PXEHELP)) { + err_dialog(N("Error !"), N("Found a similar entry in PXE list labeled : $WPXENAME.\nChoose another label please")) and return 'addimg'; + } + }, + next => 'endadd', + post => sub { + add_in_help($WPXENAME, $WINFO); + my $vmlinuzpxe = basename($WVMLINUZ) . "-$WPXENAME"; + cp_af($WVMLINUZ, "$IMGPATH/" . $vmlinuzpxe); #basename($WVMLINUZ) . "-$WPXENAME"); + print "cp: $WALLRDZ $IMGPATH/$WPXENAME.rdz"; + cp_af($WALLRDZ, "$IMGPATH/$WPXENAME.rdz"); + print "debussssg\n"; + push @listpxe, { + label => $WPXENAME, + info => $WINFO, + kernel => "/images/$vmlinuzpxe", + initrd => "images/$WPXENAME.rdz", + automatic => "http", + interface => "eth0", + network => "dhcp", + server => "10.0.1.33", + directory => "/install/cooker", + ramdisk => "64000", + vga => "788", + display => ":0", + option => "acpi=ht", + }; + print "debug\n"; + my $iter = $model->append; + $model->set($iter, + COLUMN_LABEL, $listpxe[-1]{label}, + COLUMN_INFO, $listpxe[-1]{info}, + COLUMN_KERNEL, $listpxe[-1]{kernel}, + COLUMN_INITRD, $listpxe[-1]{initrd}, + COLUMN_AUTOMATIC, $listpxe[-1]{automatic}, + COLUMN_INTERFACE, $listpxe[-1]{interface}, + COLUMN_NETWORK, $listpxe[-1]{network}, + COLUMN_SERVER, $listpxe[-1]{server}, + COLUMN_DIRECTORY, $listpxe[-1]{directory}, + COLUMN_RAMDISK, $listpxe[-1]{ramdisk}, + COLUMN_VGA, $listpxe[-1]{vga}, + COLUMN_DISPLAY, $listpxe[-1]{display}, + COLUMN_OPTION, $listpxe[-1]{option}, + ); + write_conf_pxe(); + return; + }, + no_back => 1, + }, + endadd => { + name => N("Congratulations"), + data => [ { label => N("The wizard successfully added the PXE boot image.") } ], + post => sub { list_label_pxe() }, + no_back => 1, + end => 1, + next => 0, + }, + } + }; + $w->process($wiz, $in); + $::isWizard = 0; } sub remove_item { @@ -309,14 +368,17 @@ sub remove_item { } sub test_similar_label { - my ($newlabel) = @_; + my ($newlabel, $oldlabel) = @_; +# if ($newlabel eq $oldlabel) { +# err_dialog(N("hmm.."), N("You should provide a new label name.")) and return 0; +# } els if (any { /^label $newlabel$/ } cat_($conf)) { err_dialog(N("Error !"), N("Found a similar entry in PXE list labeled : $newlabel.\nChoose another label please")) and return 0; } else { return 1 }; } sub edit_box_item { - my ($widget, $treeview, $indice) = @_; + my ($widget, $treeview) = @_; # $::isWizard = 0; my $model = $treeview->get_model; my $selection = $treeview->get_selection; @@ -332,6 +394,7 @@ sub edit_box_item { my $label = Gtk2::Entry->new; $label->set_text($listpxe[$i]{label}); + my $oldlabel = $label; my $info = Gtk2::Entry->new; $info->set_text($listpxe[$i]{info}); @@ -463,26 +526,24 @@ sub edit_box_item { $listpxe[$i]{option} = $option->get_text; # update value in cells - if (test_similar_label($listpxe[$i]{label}) eq "1") { - $model->set($iter, - COLUMN_LABEL, $listpxe[$i]{label}, - COLUMN_INFO, $listpxe[$i]{info}, - COLUMN_KERNEL, $listpxe[$i]{kernel}, - COLUMN_INITRD, $listpxe[$i]{initrd}, - COLUMN_AUTOMATIC, $listpxe[$i]{automatic}, - COLUMN_INTERFACE, $listpxe[$i]{interface}, - COLUMN_NETWORK, $listpxe[$i]{network}, - COLUMN_SERVER, $listpxe[$i]{server}, - COLUMN_DIRECTORY, $listpxe[$i]{directory}, - COLUMN_RAMDISK, $listpxe[$i]{ramdisk}, - COLUMN_VGA, $listpxe[$i]{vga}, - COLUMN_DISPLAY, $listpxe[$i]{display}, - COLUMN_OPTION, $listpxe[$i]{option}, - ); - $dialog->destroy; - write_conf_pxe; - add_in_help($listpxe[$i]{label}, $listpxe[$i]{info}); - } + $model->set($iter, + COLUMN_LABEL, $listpxe[$i]{label}, + COLUMN_INFO, $listpxe[$i]{info}, + COLUMN_KERNEL, $listpxe[$i]{kernel}, + COLUMN_INITRD, $listpxe[$i]{initrd}, + COLUMN_AUTOMATIC, $listpxe[$i]{automatic}, + COLUMN_INTERFACE, $listpxe[$i]{interface}, + COLUMN_NETWORK, $listpxe[$i]{network}, + COLUMN_SERVER, $listpxe[$i]{server}, + COLUMN_DIRECTORY, $listpxe[$i]{directory}, + COLUMN_RAMDISK, $listpxe[$i]{ramdisk}, + COLUMN_VGA, $listpxe[$i]{vga}, + COLUMN_DISPLAY, $listpxe[$i]{display}, + COLUMN_OPTION, $listpxe[$i]{option}, + ); + $dialog->destroy; + write_conf_pxe; + add_in_help($listpxe[$i]{label}, $listpxe[$i]{info}); }, }, ), @@ -493,15 +554,15 @@ sub edit_box_item { # add in help.txt sub add_in_help { - my ($NAME, $DESCR) = @_; + my ($NAME, $INFO) = @_; if (!any { /$NAME/ } cat_($PXEHELP)) { append_to_file($PXEHELP, <<EOF); -$NAME : install $DESCR +$NAME : install $INFO EOF } else { substInFile { - s/$NAME.*/$NAME : $DESCR/; + s/$NAME.*/$NAME : $INFO/; } $PXEHELP; } } @@ -530,10 +591,10 @@ sub cell_edited { if ($column == COLUMN_LABEL) { my $i = ($path->get_indices)[0]; - my $oldname = $listpxe[$i]{label}; - my $newname = $new_text; - if (test_similar_label($newname) eq "1") { - change_label_in_help($oldname, $newname); + my $oldlabel = $listpxe[$i]{label}; + my $newlabel = $new_text; + if (test_similar_label($newlabel, $oldlabel) eq "1") { + change_label_in_help($oldlabel, $newlabel); $listpxe[$i]{label} = $new_text; $model->set($iter, $column, $listpxe[$i]{label}); } @@ -771,7 +832,7 @@ sub add_columns { my @j = qw/Label Info Kernel Initrd Method Interface Network Server Directory Ramdisk vga Display Extra Options/; each_index { my $renderer = Gtk2::CellRendererText->new; - $renderer->set(editable => 1); + $renderer->set(editable => 0); $renderer->signal_connect(edited => \&cell_edited, $model); $renderer->set_data(column => $::i); $treeview->insert_column_with_attributes(-1, $j[$t], $renderer, 'text' => $::i); @@ -784,6 +845,7 @@ sub add_columns { # Main # create model +$::isWizard = 0; my $model = create_model(); my $window = ugtk2->new('Drakpxe2'); @@ -840,8 +902,15 @@ $W->add(gtkpack_(Gtk2::VBox->new(0,0), ), 0, Gtk2::VSeparator->new, 0, gtksignal_connect(Gtk2::Button->new(N("Add PXE entry")), clicked => sub { - add_item($model, $treeview); } - ), + eval { wizard_add_entry($model, $treeview) }; + my $err = $@; + $::WizardWindow->destroy if defined $::WizardWindow; + undef $::WizardWindow; + if ($err && $err !~ /wizcancel/) { + err_dialog(N("Error"), N("The add PXE entry wizard had unexpectly failled:") + . "\n\n" . $err); + } + }), 0, gtksignal_connect(Gtk2::Button->new((N"Remove PXE entry")), clicked => sub { remove_item($model, $treeview); } ), |