summaryrefslogtreecommitdiffstats
path: root/drakpxelinux.pl
diff options
context:
space:
mode:
authorOlivier Blin <oblin@mandriva.org>2005-06-10 04:39:54 +0000
committerOlivier Blin <oblin@mandriva.org>2005-06-10 04:39:54 +0000
commite326e2019e918ec1cc2ab15caf0e04b7604c79b4 (patch)
treed2d73fba09f116fbff2cf7032f28f510e2430b72 /drakpxelinux.pl
parent8c1b6018026d71930d7781d57de8be77d20fd4c5 (diff)
downloaddrakpxelinux-e326e2019e918ec1cc2ab15caf0e04b7604c79b4.tar
drakpxelinux-e326e2019e918ec1cc2ab15caf0e04b7604c79b4.tar.gz
drakpxelinux-e326e2019e918ec1cc2ab15caf0e04b7604c79b4.tar.bz2
drakpxelinux-e326e2019e918ec1cc2ab15caf0e04b7604c79b4.tar.xz
drakpxelinux-e326e2019e918ec1cc2ab15caf0e04b7604c79b4.zip
- create network::pxe out of drakpxelinux (pxe configuration files management)
- get_items() -> network::pxe::read_pxelinux_conf() - don't read comments in pxelinux configuration file - store pxelinux configuration in a hash to avoid multiple cat_() - add network::pxe::list_pxelinux_labels() to get labels from a pxelinux configuration - only overwrite pxelinux settings (prompt, timeout, ...) when pxe is reconfigured - use network::network and network::tools to get hostname, domain name, IP address, net interface - move row creation code in set_pxelinux_entry_at_iter() and factorize - use ensure_is_installed to make sure pxe is installed
Diffstat (limited to 'drakpxelinux.pl')
-rw-r--r--drakpxelinux.pl670
1 files changed, 196 insertions, 474 deletions
diff --git a/drakpxelinux.pl b/drakpxelinux.pl
index 9da9ea7..9e17139 100644
--- a/drakpxelinux.pl
+++ b/drakpxelinux.pl
@@ -24,16 +24,17 @@
my $version = "1.0.2";
+# i18n: IMPORTANT: to get correct namespace (drakpxelinux instead of libDrakX)
+BEGIN { unshift @::textdomains, 'drakpxelinux' }
+
use lib qw(/usr/lib/libDrakX);
use standalone;
use strict;
use common;
use network::network;
-#use MDK::Common;
+use network::pxe;
+use network::tools;
use interactive;
-
-# i18n: IMPORTANT: to get correct namespace (drakpxelinux instead of libDrakX)
-BEGIN { unshift @::textdomains, 'drakpxelinux' }
# must come *after* definition of textdomains for proper initialisation
use ugtk2 qw(:ask :helpers :wrappers :create :dialogs);
@@ -55,33 +56,16 @@ AmIRoot();
# APPEND initrd=images/all.rdz automatic=method:http,interface:eth0,network:dhcp,server:10.0.1.33,directory:/install/ ramdisk_size=64000 root=/dev/ram3 rw vga=788 display=:0
# default VAR
-my $conf = "/var/lib/tftpboot/X86PC/linux/pxelinux.cfg/default";
-my $HOSTNAME = chomp_(`hostname`);
-my $TFTPDIR = "/var/lib/tftpboot";
-my $CLIENTPATH = '/X86PC/linux';
-my $X86 = $TFTPDIR . $CLIENTPATH;
-my $IMGPATH = $X86 . '/images';
-my $PXEHELP = $X86 . '/help.txt';
-my $PXEMESSAGE = $X86 . '/messages';
-my $pxeconf = '/etc/pxe.conf';
my $SYSLINUXPATH = '/usr/lib/syslinux/';
my $MEMDISK = $SYSLINUXPATH . '/memdisk';
my $XINETDDIR = "/etc/xinetd.d";
-#my $interface = 'eth0';
-#my ($IPSERVER) = `/sbin/ip addr show dev $interface` =~ /^\s*inet\s+(\d+\.\d+\.\d+\.\d+)/m;
-#my $IPSERVER = $wiz->{net}->itf_get("IPADDR");
-my $IPSERVER;
-my $sys_wizard_pxe = "/etc/sysconfig/drak_pxe";
-if (-f $sys_wizard_pxe) {
- our ($interface) = cat_($sys_wizard_pxe) =~ /INTERFACE=(.*)/;
- ($IPSERVER) = `/sbin/ip addr show dev $interface` =~ /^\s*inet\s+(\d+\.\d+\.\d+\.\d+)/m;
-} else {
- our $interface = "eth0";
- ($IPSERVER) = `/sbin/ip addr show dev $interface` =~ /^\s*inet\s+(\d+\.\d+\.\d+\.\d+)/m;
-}
+my $net;
+network::network::read_net_conf($net);
-my $DOMAINNAME = chomp_(`dnsdomainname`);
+my $sys_wizard_pxe = "/etc/sysconfig/drak_pxe";
+my ($interface) = cat_($sys_wizard_pxe) =~ /INTERFACE=(.*)/;
+$interface ||= $net->{net_interface};
my $help = "" .
N("PXE Label: the name to be displayed in the PXE menu (an ASCII word/number)") . "\n" .
@@ -124,36 +108,18 @@ sub set_help_tip {
gtkset_tip(new Gtk2::Tooltips, $entry, formatAlaTeX($help{$key}));
}
-if (!-f $conf) {
- err_dialog(N("Error!"), N("missing %s\n\nPlease install the pxe package.",$conf)) and !$::testing && die;
-} else {
- save_config($conf);
+
+my $in = 'interactive'->vnew('su');
+
+if (!$::testing && !$in->do_pkgs->ensure_is_installed('pxe', $network::pxe::pxe_config_file)) {
+ err_dialog(N("Error!"), N("missing %s\n\nPlease install the pxe package.", $network::pxe::pxe_config_file));
+ $in->exit(-1);
}
-my @listpxe;
+save_config($network::pxe::pxelinux_config_file);
+
my @list_method = qw(nfs http ka); push @list_method, "";
my @list_ram = qw(32000 48000 64000 96000 128000);
-my @list_vga_resolution = qw(vga text automatic 640x480 800x600 1024x768 1280x1024);
-my %list_vga_code = (
- 'vga' => "normal",
- 'text' => "text",
- '640x480' => "785",
- '800x600' => "788",
- '1024x768' => "791",
- '1280x1024' => "794",
- 'automatic' => "",
- );
-
-my %list_vga_res = (
- 'normal' => "vga",
- 'text' => "text",
- '785' => "640x480",
- '788' => "800x600",
- '791' => "1024x768",
- '794' => "1280x1024",
- '' => "automatic",
- );
-
my @list_eth = qw(eth0 eth1 eth2); push @list_eth, "";
use constant COLUMN_LABEL => 0;
@@ -171,175 +137,33 @@ use constant COLUMN_DISPLAY => 11;
use constant COLUMN_OPTION => 12;
use constant NUM_COLUMNS => 13;
-# get all values from default PXE file
-sub get_items() {
- my $info; my $label; my $kernel; my $initrd;
- foreach (cat_($conf)) {
- if (any { /^label/ } cat_($conf)) {
- if (/^label/) { ($label) = /^label\s(.*)/ }
- if (/KERNEL/) { ($kernel) = /KERNEL\s(.*)/ }
- my ($initrd, $automatic, $interface, $network, $server, $directory, $ramdisk, $vga, $devram, $display, $opts) = m!\s*APPEND\sinitrd=(.*?rdz)\s\bautomatic=method\b:(nfs|http),interface:(eth0|eth1|eth2),network:(dhcp|\d+\.\d+\.\d+\.\d+),server:(.*?),directory:(.*?)\s\bramdisk_size\b=(.*?)\sroot=(/dev/ram3\srw)\svga=(.*?)\sdisplay=(.*?)\s(.*)!;
- # in case of parameter not on this order (previous pxe default file)
- $devram or my ($devra) = m!root=(/dev/ram3\srw)!;
- $initrd or my ($init) = m!\s*APPEND\s\binitrd\b=(.*?)\s!;
- $ramdisk or my ($ramdis) = m!\bramdisk_size\b=(\d+)\s!;
- $automatic or my ($automati) = m!\bautomatic\b=method:(nfs|http)!;
- $vga or my ($vg) = m!\bvga\b=(.*?)\s!;
- $display or my ($displa) = m!\bdisplay\b=(.*?)\s!;
- $interface or my ($interfac) = m!\binterface\b:(eth0|eth1|eth2)!;
- $network or my ($networ) = m!\bnetwork\b:(dhcp|\d+\.\d+\.\d+\.\d+)!;
- $server or my ($serve) = m!\bserver\b:(.*?),!;
- $directory or my ($director) = m!\bdirectory\b:(.*?)\s!;
- my $optsall; my $initall; my $ramdiskall; my $autoall; my $vgaall; my $displayall; my $interfaceall; my $networkall; my $serverall; my $directoryall; my $devramall;
- if ($initrd) { $initall = $initrd } else { $initall = $init }
- if ($ramdisk) { $ramdiskall = $ramdisk } else { $ramdiskall = $ramdis }
- if ($automatic) { $autoall = $automatic } else { $autoall = $automati }
- if ($vga) { $vgaall = $vga } else { $vgaall = $vg }
- if ($display) { $displayall = $display } else { $displayall = $displa }
- if ($interface) { $interfaceall = $interface } else { $interfaceall = $interfac }
- if ($network) { $networkall = $network } else { $networkall = $networ }
- if ($server) { $serverall = $server } else { $serverall = $serve }
- if ($directory) { $directoryall = $directory } else { $directoryall = $director }
- if ($devram) { $devramall = $devram } else { $devramall = $devra }
- my ($allopt) = m!\s*APPEND\s(.*)!;
- my ($autocomp) = m!\bautomatic\b=(.*?)\s!;
- my $optionsall = join(' ', grep { ! /root=$devramall/ && ! /initrd=$initall/ && !/display=$displayall/ && ! /ramdisk_size=$ramdiskall/ && ! /automatic=$autocomp/ && !/vga=$vgaall/ } split(' ', $allopt));
- if ($opts) { $optsall = $opts } else { $optsall = $optionsall }
- if ($label && $kernel && $initall) {
- my $information = get_information($label);
- my $vgares = $list_vga_res{$vgaall};
- # now push data in @
- push @listpxe, {
- label => $label,
- info => get_information($label),
- kernel => $kernel,
- initrd => $initall,
- automatic => $autoall,
- interface => $interfaceall,
- network => $networkall,
- server => $serverall,
- directory => $directoryall,
- ramdisk => $ramdiskall,
-# vga => $vgaall,
- vga => $vgares,
- display => $displayall,
- option => $optsall,
- },;
- }
- }
- }
-}
-
-
-# get info from help.txt
-sub get_information {
- my ($label) = @_;
- foreach (cat_($PXEHELP)) {
- my ($information) = /^\b$label\b\s:\s(.*)/;
- print $information;
- $information and return $information;
- }
-}
+my $pxelinux_conf = network::pxe::read_pxelinux_conf();
-sub list_label_pxe() {
- my @labels;
- foreach (cat_($conf)) {
- my ($label) = /^label\s(.*)/;
- $label and push @labels, $label;
- }
- @labels;
-}
-
-# set new default boot PXE
-sub set_new_default {
- my ($default) = @_;
- substInFile {
- s/^DEFAULT.*/DEFAULT $default/;
- } $conf;
-}
-
-sub get_default_pxe {
- my ($defaultpxe) = cat_($conf) =~ /DEFAULT\s+(\S+)/;
- return $defaultpxe;
-}
-
-sub get_default_prompt() {
- my $line = cat_($conf);
- my ($prompt) = $line =~ /^PROMPT\s(\d+)/;
- $prompt and return $prompt;
-}
-
-sub get_default_timeout() {
- my ($time) = cat_($conf) =~ /^TIMEOUT\s(\d+)/;
- return $time;
+sub set_pxelinux_entry_at_iter {
+ my ($model, $iter, $entry) = @_;
+ $model->set($iter,
+ COLUMN_LABEL, $entry->{label},
+ COLUMN_INFO, $entry->{info},
+ COLUMN_KERNEL, $entry->{kernel},
+ COLUMN_INITRD, $entry->{initrd},
+ COLUMN_AUTOMATIC, $entry->{automatic},
+ COLUMN_INTERFACE, $entry->{interface},
+ COLUMN_NETWORK, $entry->{network},
+ COLUMN_SERVER, $entry->{server},
+ COLUMN_DIRECTORY, $entry->{directory},
+ COLUMN_RAMDISK, $entry->{ramdisk},
+ COLUMN_VGA, $entry->{vga},
+ COLUMN_DISPLAY, $entry->{display},
+ COLUMN_OPTION, $entry->{option},
+ );
}
-# write conf in default file
-sub write_conf_pxe {
- my $default = get_default_pxe;
- my $prompt = get_default_prompt;
- my $time = get_default_timeout;
- output($conf, <<EOF);
-# DO NOT EDIT auto_generated by drakpxelinux.pl
-PROMPT 10
-DEFAULT $default
-DISPLAY messages
-TIMEOUT 50
-F1 help.txt
-
-label local
- LOCALBOOT 0
-EOF
-
- foreach my $a (@listpxe) {
- if ($a->{interface} && !$a->{display}) {
- my $vga = $list_vga_code{$a->{vga}};
- append_to_file($conf, "
-label $a->{label}
- KERNEL $a->{kernel}
- APPEND initrd=$a->{initrd} automatic=method:$a->{automatic},interface:$a->{interface},network:$a->{network},server:$a->{server},directory:$a->{directory} ramdisk_size=$a->{ramdisk} vga=$vga $a->{option}
-");
- } elsif ($a->{interface} && $a->{display}) {
- my $vga = $list_vga_code{$a->{vga}};
- append_to_file($conf, "
-label $a->{label}
- KERNEL $a->{kernel}
- APPEND initrd=$a->{initrd} automatic=method:$a->{automatic},interface:$a->{interface},network:$a->{network},server:$a->{server},directory:$a->{directory} ramdisk_size=$a->{ramdisk} vga=$a->{vga} display=$a->{display} $a->{option}
-");
- # case of .img image
- } else {
- append_to_file($conf, "
-label $a->{label}
- KERNEL $a->{kernel}
- APPEND initrd=$a->{initrd}
-");
- }
- }
-}
sub create_model {
- get_items();
-# my $model = Gtk2::ListStore->new(("Glib::String") x13);
- my $model = Gtk2::ListStore->new("Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String");
- foreach my $a (@listpxe) {
- my $iter = $model->append;
- $model->set($iter,
- COLUMN_LABEL, $a->{label},
- COLUMN_INFO, $a->{info},
- COLUMN_KERNEL, $a->{kernel},
- COLUMN_INITRD, $a->{initrd},
- COLUMN_AUTOMATIC, $a->{automatic},
- COLUMN_INTERFACE, $a->{interface},
- COLUMN_NETWORK, $a->{network},
- COLUMN_SERVER, $a->{server},
- COLUMN_DIRECTORY, $a->{directory},
- COLUMN_RAMDISK, $a->{ramdisk},
- COLUMN_VGA, $a->{vga},
- COLUMN_DISPLAY, $a->{display},
- COLUMN_OPTION, $a->{option},
- ),
- }
- return $model;
+# my $model = Gtk2::ListStore->new(("Glib::String") x NUM_COLUMNS);
+ my $model = Gtk2::ListStore->new("Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String");
+ set_pxelinux_entry_at_iter($model, $model->append, $_) foreach @{$pxelinux_conf->{entries}};
+ return $model;
}
# wizard to add an entry in PXE menu
@@ -348,7 +172,6 @@ sub wizard_add_entry {
my $model = $treeview->get_model;
local $::isEmbedded = 0;
- my $in = 'interactive'->vnew('su');
undef $::WizardTable;
undef $::WizardWindow;
$::isWizard = 1;
@@ -368,7 +191,7 @@ sub wizard_add_entry {
next => 'addimg',
},
addimg => {
- name => N("When this wizard has finished, the all.rdz image and kernel vmlinuz will be copied into \n%s.\n\nThe PXE menu list will be updated with this new entry.", $IMGPATH),
+ name => N("When this wizard has finished, the all.rdz image and kernel vmlinuz will be copied into \n%s.\n\nThe PXE menu list will be updated with this new entry.", $network::pxe::pxelinux_images),
data => [
{ label => N("PXE label:"), val => \$WPXENAME,
help => N("name displayed in PXE menu (please provide an ASCII word or a number, without spaces)") },
@@ -380,7 +203,7 @@ sub wizard_add_entry {
help => N("Provide the full path to vmlinuz kernel location") },
],
complete => sub {
- if (any { /^$WPXENAME :/ } cat_($PXEHELP)) {
+ if (any { /^$WPXENAME :/ } cat_($network::pxe::pxelinux_help_file)) {
err_dialog(N("Error!"), N("Found a similar entry in PXE list labeled: %s.\nChoose another label please", $WPXENAME)) and return 'addimg';
}
if (($WPXENAME) !~ /^\w+$/) {
@@ -396,42 +219,22 @@ sub wizard_add_entry {
next => 'endadd',
post => sub {
my $w = $in->wait_message(N("add a PXE entry"), N("add a PXE entry in your PXE server configuration..."));
- add_in_help($WPXENAME, $WINFO);
+ network::pxe::add_in_help($WPXENAME, $WINFO);
my $vmlinuzpxe = basename($WVMLINUZ) . "-$WPXENAME";
- cp_af($WVMLINUZ, "$IMGPATH/$vmlinuzpxe");
- cp_af($WALLRDZ, "$IMGPATH/$WPXENAME.rdz");
- push @listpxe, {
- label => $WPXENAME,
- info => $WINFO,
- kernel => "images/$vmlinuzpxe",
- initrd => "images/$WPXENAME.rdz",
- automatic => "",
- interface => "",
- network => "",
- server => "",
- directory => "",
- ramdisk => "128000",
- vga => "automatic",
- display => "",
- option => "root=/dev/ram3 rw",
- };
- 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();
+ cp_af($WVMLINUZ, $network::pxe::pxelinux_images . "/$vmlinuzpxe");
+ cp_af($WALLRDZ, $network::pxe::pxelinux_images . "/$WPXENAME.rdz");
+ my $entry = {
+ label => $WPXENAME,
+ info => $WINFO,
+ kernel => "images/$vmlinuzpxe",
+ initrd => "images/$WPXENAME.rdz",
+ ramdisk => "128000",
+ vga => "automatic",
+ others => "root=/dev/ram3 rw",
+ };
+ push @{$pxelinux_conf->{entries}}, $entry;
+ set_pxelinux_entry_at_iter($model, $model->append, $entry);
+ network::pxe::write_pxelinux_conf($pxelinux_conf);
undef $w;
return;
},
@@ -440,7 +243,7 @@ sub wizard_add_entry {
endadd => {
name => N("Congratulations"),
data => [ { label => N("The wizard successfully added the PXE boot image.") } ],
- post => sub { list_label_pxe() },
+ post => sub { network::pxe::list_pxelinux_labels() },
no_back => 1,
end => 1,
next => 0,
@@ -462,11 +265,13 @@ sub remove_item {
if ($iter) {
my $path = $model->get_path($iter);
my $i = ($path->get_indices)[0];
- ask_okcancel("Remove $listpxe[$i]{label} PXE entry ?") or return;
- remove_in_help($listpxe[$i]{label});
- my $ke = "$X86/$listpxe[$i]{kernel}";
- my $initrdf = "$X86/$listpxe[$i]{initrd}";
- if (basename($listpxe[$i]{kernel} ne "$X86/memdisk")) {
+ my $entry = $pxelinux_conf->{entries}[$i];
+
+ ask_okcancel("Remove $entry->{label} PXE entry ?") or return;
+ network::pxe::remove_in_help($entry->{label});
+ my $ke = $network::pxe::pxelinux_client_root . "/$entry->{kernel}";
+ my $initrdf = $network::pxe::pxelinux_client_root . "/$entry->{initrd}";
+ if (basename($entry->{kernel} ne $network::pxe::pxelinux_client_root . "/memdisk")) {
print "k: $ke\n";
print "initrd: $initrdf\n";
system("rm -vf $ke");
@@ -476,8 +281,8 @@ sub remove_item {
system("rm -vf $initrdf");
}
$model->remove($iter);
- splice @listpxe, $i, 1;
- write_conf_pxe;
+ splice @{$pxelinux_conf->{entries}}, $i, 1;
+ network::pxe::write_pxelinux_conf($pxelinux_conf);
}
}
@@ -486,7 +291,8 @@ sub test_similar_label {
# if ($newlabel eq $oldlabel) {
# err_dialog(N("hmm.."), N("You should provide a new label name.")) and return 0;
# } els
- if (any { /^label\s$newlabel$/ } cat_($conf)) {
+
+ if (any { $_->{label} eq $newlabel } @{$pxelinux_conf->{entries}}) {
err_dialog(N("Error!"), N("Found a similar entry in PXE list labeled: %s.\nChoose another label please", $newlabel)) and return 0;
} else { return 1 };
}
@@ -502,24 +308,25 @@ sub edit_box_item {
if ($iter) {
my $path = $model->get_path($iter);
my $i = ($path->get_indices)[0];
+ my $entry = $pxelinux_conf->{entries}[$i];
my $dialog = new Gtk2::Dialog();
$dialog->set_modal(1);
$dialog->set_resizable(FALSE);
# my $label = Gtk2::Entry->new;
- my $label = Gtk2::Label->new($listpxe[$i]{label});
-# $label->set_text($listpxe[$i]{label});
+ my $label = Gtk2::Label->new($entry->{label});
+# $label->set_text($entry->{label});
# my $oldlabel = $label;
my $info = Gtk2::Entry->new;
- $info->set_text($listpxe[$i]{info});
+ $info->set_text($entry->{info});
set_help_tip($info, 'info');
# create file dialog widget, with file or directory selection
my $fdwidget = sub {
my ($data, $test, $filetotest, $label) = @_;
- chdir($X86);
+ chdir($network::pxe::pxelinux_client_root);
my $fd = new Gtk2::FileSelection(N("Selection"));
$fd->set_modal(TRUE);
$fd->signal_connect("destroy", sub { $fd->hide });
@@ -533,11 +340,11 @@ sub edit_box_item {
}
if ($filetotest eq "kernel") {
run_program::get_stdout("file $file") =~ /boot sector/ or err_dialog(N("Error!"), N("Should be a boot sector file")) and return;
- run_program::get_stdout("cp -avf $file $IMGPATH/vmlinuz-$label");
+ run_program::get_stdout("cp -avf $file " . $network::pxe::pxelinux_images . "/vmlinuz-$label");
$data->set_text("images/vmlinuz-$label");
} elsif ($filetotest eq "initrd") {
run_program::get_stdout("file $file") =~ /initrd/ or err_dialog(N("Error!"), N("Should be an initrd file")) and return;
- system("cp -avf $file $IMGPATH/$label.rdz");
+ system("cp -avf $file " . $network::pxe::pxelinux_images . "/$label.rdz");
$data->set_text("images/$label.rdz");
}
# my $d = dirname($file);
@@ -552,44 +359,44 @@ sub edit_box_item {
my $kernel = Gtk2::Entry->new;
- $kernel->set_text($listpxe[$i]{kernel});
+ $kernel->set_text($entry->{kernel});
set_help_tip($kernel, 'kernel');
- my $file_dialogk = $fdwidget->($kernel, "", "kernel", $listpxe[$i]{label});
+ my $file_dialogk = $fdwidget->($kernel, "", "kernel", $entry->{label});
# button kernel
my $buttonkernel = Gtk2::Button->new(N("Select kernel to boot"));
$buttonkernel->signal_connect(clicked => sub { $file_dialogk->show });
my $initrd = Gtk2::Entry->new;
- $initrd->set_text($listpxe[$i]{initrd});
+ $initrd->set_text($entry->{initrd});
set_help_tip($initrd, 'initrd');
- my $file_dialog = $fdwidget->($initrd, "", "initrd", $listpxe[$i]{label});
+ my $file_dialog = $fdwidget->($initrd, "", "initrd", $entry->{label});
my $buttoninitrd = Gtk2::Button->new(N("Select associated initrd"));
$buttoninitrd->signal_connect(clicked => sub { $file_dialog->show });
# combo box to pop down automatic installation
my $automatic = Gtk2::OptionMenu->new;
$automatic->set_popdown_strings(@list_method);
- $automatic->entry->set_text($listpxe[$i]{automatic});
+ $automatic->entry->set_text($entry->{automatic});
set_help_tip($automatic, 'automatic');
# combo box to pop down list of network interface
my $interface = new Gtk2::OptionMenu();
$interface->set_popdown_strings(@list_eth);
- $interface->entry->set_text($listpxe[$i]{interface});
+ $interface->entry->set_text($entry->{interface});
set_help_tip($interface, 'interface');
# my $network = Gtk2::Entry->new;
-# $network->set_text($listpxe[$i]{network});
+# $network->set_text($entry->{network});
# set_help_tip($network, 'network');
my $server = Gtk2::Entry->new;
- $server->set_text($listpxe[$i]{server});
+ $server->set_text($entry->{server});
set_help_tip($server, 'server');
my $directory = Gtk2::Entry->new;
- $directory->set_text($listpxe[$i]{directory});
+ $directory->set_text($entry->{directory});
set_help_tip($directory, 'directory');
my $file_dialogd = $fdwidget->($directory, "dir");
@@ -598,24 +405,24 @@ sub edit_box_item {
my $ramdisk = new Gtk2::OptionMenu();
$ramdisk->set_popdown_strings(@list_ram);
- if ($listpxe[$i]{ramdisk} eq "") { $listpxe[$i]{ramdisk} = "128000" }
- $ramdisk->entry->set_text($listpxe[$i]{ramdisk});
+ if ($entry->{ramdisk} eq "") { $entry->{ramdisk} = "128000" }
+ $ramdisk->entry->set_text($entry->{ramdisk});
set_help_tip($ramdisk, 'ramsize');
my $vga = new Gtk2::OptionMenu();
- $vga->set_popdown_strings(@list_vga_resolution);
-# if ($listpxe[$i]{vga} eq "automatic") { $listpxe[$i]{vga} = "" }
-# $vga->entry->set_text($list_vga_res{$listpxe[$i]{vga}});
- $vga->entry->set_text($listpxe[$i]{vga});
+ $vga->set_popdown_strings(keys %network::pxe::vga_bios_to_resolution);
+# if ($entry->{vga} eq "automatic") { $entry->{vga} = "" }
+# $vga->entry->set_text($list_vga_res{$entry->{vga}});
+ $vga->entry->set_text($entry->{vga});
set_help_tip($vga, 'vga');
my $display = Gtk2::Entry->new;
- $display->set_text($listpxe[$i]{display});
+ $display->set_text($entry->{display});
set_help_tip($display, 'display');
my $option = Gtk2::Entry->new;
- if ($listpxe[$i]{option} eq "") { $listpxe[$i]{option} = "root=/dev/ram3 rw" }
- $option->set_text($listpxe[$i]{option});
+ if ($entry->{option} eq "") { $entry->{option} = "root=/dev/ram3 rw" }
+ $option->set_text($entry->{option});
set_help_tip($option, 'option');
my %size_groups = map { $_ => Gtk2::SizeGroup->new('horizontal') } qw(label widget button);
@@ -631,12 +438,12 @@ sub edit_box_item {
# display IPADDRESS only if dhcp is not selected
my $ipaddr = Gtk2::Entry->new;
my $toggledhcp = Gtk2::CheckButton->new(N("DHCP or IP address"));
- if ($listpxe[$i]{network} eq "dhcp") { $toggledhcp->set_active(1);
+ if ($entry->{network} eq "dhcp") { $toggledhcp->set_active(1);
$ipaddr->set_sensitive(0);
} else {
$toggledhcp->set_active(0);
$ipaddr->set_sensitive(1);
- $ipaddr->set_text($listpxe[$i]{network});
+ $ipaddr->set_text($entry->{network});
}
$toggledhcp->signal_connect(clicked => sub {
@@ -655,8 +462,8 @@ sub edit_box_item {
0, $label_and_widgets->(N("Label"), $label, ""),
0, $label_and_widgets->(N("Entry description"), $info, ""),
0, Gtk2::VSeparator->new,
- 0, $label_and_widgets->(N("Kernel image: ") . $TFTPDIR . "/X86PC/linux/", $kernel, $buttonkernel),
- 0, $label_and_widgets->(N("Initrd image: ") . $TFTPDIR . "/X86PC/linux/", $initrd, $buttoninitrd),
+ 0, $label_and_widgets->(N("Kernel image: ") . $network::pxe::pxelinux_client_root . "/", $kernel, $buttonkernel),
+ 0, $label_and_widgets->(N("Initrd image: ") . $network::pxe::pxelinux_client_root . "/", $initrd, $buttoninitrd),
),
),
@@ -684,52 +491,36 @@ sub edit_box_item {
0, create_okcancel({
cancel_clicked => sub { $dialog->destroy },
ok_clicked => sub {
- my $vgacode = $list_vga_code{$vga->entry->get_text};
+ my $vgacode = $network::pxe::vga_resolution_to_bios{$vga->entry->get_text};
#ask_okcancel("are you sure you want to update all those values ?");
- $listpxe[$i]{label} = $label->get_text;
- $listpxe[$i]{info} = $info->get_text;
- $listpxe[$i]{kernel} = $kernel->get_text;
- $listpxe[$i]{initrd} = $initrd->get_text;
- $listpxe[$i]{automatic} = $automatic->entry->get_text;
- $listpxe[$i]{interface} = $interface->entry->get_text;
+ $entry->{label} = $label->get_text;
+ $entry->{info} = $info->get_text;
+ $entry->{kernel} = $kernel->get_text;
+ $entry->{initrd} = $initrd->get_text;
+ $entry->{automatic} = $automatic->entry->get_text;
+ $entry->{interface} = $interface->entry->get_text;
# check dhcp or ipaddress
my $s = $toggledhcp->get_active;
if ($toggledhcp->get_active eq "1") {
- $listpxe[$i]{network} = "dhcp";
+ $entry->{network} = "dhcp";
} else {
- $listpxe[$i]{network} = $ipaddr->get_text;
- if ($listpxe[$i]{kernel} !~ /memdisk/) {
- is_ip($listpxe[$i]{network}) or err_dialog(N("Error!"), N("Please enter a valid IP address.")) and return;
+ $entry->{network} = $ipaddr->get_text;
+ if ($entry->{kernel} !~ /memdisk/) {
+ is_ip($entry->{network}) or err_dialog(N("Error!"), N("Please enter a valid IP address.")) and return;
}
}
- $listpxe[$i]{server} = $server->get_text;
- $listpxe[$i]{directory} = $directory->get_text;
- $listpxe[$i]{ramdisk} = $ramdisk->entry->get_text;
- $listpxe[$i]{vga} = $vga->entry->get_text; #$vgacode;
- $listpxe[$i]{display} = $display->get_text;
- $listpxe[$i]{option} = $option->get_text;
+ $entry->{server} = $server->get_text;
+ $entry->{directory} = $directory->get_text;
+ $entry->{ramdisk} = $ramdisk->entry->get_text;
+ $entry->{vga} = $vga->entry->get_text; #$vgacode;
+ $entry->{display} = $display->get_text;
+ $entry->{option} = $option->get_text;
# update value in cells
-# my $getvgacode = $list_vga_code{$listpxe[$i]{vga}};
- $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_VGA, $vgacode,
- COLUMN_DISPLAY, $listpxe[$i]{display},
- COLUMN_OPTION, $listpxe[$i]{option},
- );
+ set_pxelinux_entry_at_iter($model, $iter, $entry);
$dialog->destroy;
- write_conf_pxe;
- add_in_help($listpxe[$i]{label}, $listpxe[$i]{info});
+ network::pxe::write_pxelinux_conf($pxelinux_conf);
+ network::pxe::add_in_help($entry->{label}, $entry->{info});
},
},
),
@@ -738,37 +529,6 @@ sub edit_box_item {
}
}
-# add in help.txt
-sub add_in_help {
- my ($NAME, $INFO) = @_;
- if (!any { /$NAME/ } cat_($PXEHELP)) {
- append_to_file($PXEHELP, <<EOF);
-$NAME : $INFO
-EOF
-
- } else {
- substInFile {
- s/$NAME.*/$NAME : $INFO/;
- } $PXEHELP;
- }
-}
-
-sub change_label_in_help {
- my ($NAMEOLD, $NEWNAME) = @_;
- substInFile {
- s/$NAMEOLD\s(.*)/$NEWNAME $1/;
- } $PXEHELP;
-}
-
-# remove entry in help.txt
-sub remove_in_help {
- my ($NAME) = @_;
- substInFile {
- s/^$NAME\s:.*//x;
- s/^\s*$//;
- } $PXEHELP;
-}
-
# edit cell direct on main interface
# disable due to bug in "cell edit placement" :-(
sub cell_edited {
@@ -777,87 +537,78 @@ sub cell_edited {
my $column = $cell->get_data("column");
my $iter = $model->get_iter($path);
+ my $i = ($path->get_indices)[0];
+ my $entry = $pxelinux_conf->{entries}[$i];
+
if ($column == COLUMN_LABEL) {
- my $i = ($path->get_indices)[0];
- my $oldlabel = $listpxe[$i]{label};
+ my $oldlabel = $entry->{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});
+ network::pxe::change_label_in_help($oldlabel, $newlabel);
+ $entry->{label} = $new_text;
+ $model->set($iter, $column, $entry->{label});
}
} elsif ($column == COLUMN_INFO) {
- my $i = ($path->get_indices)[0];
- $listpxe[$i]{info} = $new_text;
- $model->set($iter, $column, $listpxe[$i]{info});
+ $entry->{info} = $new_text;
+ $model->set($iter, $column, $entry->{info});
} elsif ($column == COLUMN_KERNEL) {
- my $i = ($path->get_indices)[0];
if (-f $new_text) {
- $listpxe[$i]{kernel} = $new_text;
- $model->set($iter, $column, $listpxe[$i]{kernel});
+ $entry->{kernel} = $new_text;
+ $model->set($iter, $column, $entry->{kernel});
}
} elsif ($column == COLUMN_INITRD) {
- my $i = ($path->get_indices)[0];
if (-f $new_text) {
- $listpxe[$i]{initrd} = $new_text;
- $model->set($iter, $column, $listpxe[$i]{initrd});
+ $entry->{initrd} = $new_text;
+ $model->set($iter, $column, $entry->{initrd});
}
} elsif ($column == COLUMN_AUTOMATIC) {
- my $i = ($path->get_indices)[0];
- if (!member($new_text, @list_method) || $listpxe[$i]{kernel} =~ /memdisk/) {
+ if (!member($new_text, @list_method) || $entry->{kernel} =~ /memdisk/) {
return;
} else {
- $listpxe[$i]{automatic} = $new_text;
- $model->set($iter, $column, $listpxe[$i]{automatic});
+ $entry->{automatic} = $new_text;
+ $model->set($iter, $column, $entry->{automatic});
}
} elsif ($column == COLUMN_INTERFACE) {
- my $i = ($path->get_indices)[0];
- if (member($new_text, @list_eth) || $listpxe[$i]{kernel} !~ /memdisk/) {
- $listpxe[$i]{interface} = $new_text;
- $model->set($iter, $column, $listpxe[$i]{interface});
+ if (member($new_text, @list_eth) || $entry->{kernel} !~ /memdisk/) {
+ $entry->{interface} = $new_text;
+ $model->set($iter, $column, $entry->{interface});
}
} elsif ($column == COLUMN_NETWORK) {
- my $i = ($path->get_indices)[0];
- if ($listpxe[$i]{kernel} !~ /memdisk/) {
- $listpxe[$i]{network} = $new_text;
- $model->set($iter, $column, $listpxe[$i]{network});
+ if ($entry->{kernel} !~ /memdisk/) {
+ $entry->{network} = $new_text;
+ $model->set($iter, $column, $entry->{network});
}
} elsif ($column == COLUMN_SERVER) {
- my $i = ($path->get_indices)[0];
- if ($listpxe[$i]{kernel} !~ /memdisk/) {
- $listpxe[$i]{server} = $new_text;
- $model->set($iter, $column, $listpxe[$i]{server});
+ if ($entry->{kernel} !~ /memdisk/) {
+ $entry->{server} = $new_text;
+ $model->set($iter, $column, $entry->{server});
}
} elsif ($column == COLUMN_DIRECTORY) {
- my $i = ($path->get_indices)[0];
- if (-d $new_text || $listpxe[$i]{kernel} !~ /memdisk/) {
- $listpxe[$i]{directory} = $new_text;
- $model->set($iter, $column, $listpxe[$i]{directory});
+ if (-d $new_text || $entry->{kernel} !~ /memdisk/) {
+ $entry->{directory} = $new_text;
+ $model->set($iter, $column, $entry->{directory});
}
} elsif ($column == COLUMN_RAMDISK) {
- my $i = ($path->get_indices)[0];
- if (member($new_text, @list_ram) || $listpxe[$i]{kernel} !~ /memdisk/) {
- $listpxe[$i]{ramdisk} = $new_text;
- $model->set($iter, $column, $listpxe[$i]{ramdisk});
+ if (member($new_text, @list_ram) || $entry->{kernel} !~ /memdisk/) {
+ $entry->{ramdisk} = $new_text;
+ $model->set($iter, $column, $entry->{ramdisk});
}
} elsif ($column == COLUMN_VGA) {
- my $i = ($path->get_indices)[0];
- if (member($new_text, @list_vga_resolution) || $listpxe[$i]{kernel} !~ /memdisk/) {
- $listpxe[$i]{vga} = $new_text;
- $model->set($iter, $column, $listpxe[$i]{vga});
+ if (exists $network::pxe::vga_resolution_to_bios{$new_text} || $entry->{kernel} !~ /memdisk/) {
+ $entry->{vga} = $new_text;
+ $model->set($iter, $column, $entry->{vga});
}
} elsif ($column == COLUMN_DISPLAY) {
- my $i = ($path->get_indices)[0];
- if ($listpxe[$i]{kernel} !~ /memdisk/) {
- $listpxe[$i]{display} = $new_text;
- $model->set($iter, $column, $listpxe[$i]{display});
+ if ($entry->{kernel} !~ /memdisk/) {
+ $entry->{display} = $new_text;
+ $model->set($iter, $column, $entry->{display});
}
} elsif ($column == COLUMN_OPTION) {
- my $i = ($path->get_indices)[0];
- $listpxe[$i]{option} = $new_text;
- $model->set($iter, $column, $listpxe[$i]{option});
+ $entry->{option} = $new_text;
+ $model->set($iter, $column, $entry->{option});
}
- write_conf_pxe;
+ network::pxe::write_pxelinux_conf($pxelinux_conf);
}
sub show_help { info_dialog("help",
@@ -870,20 +621,11 @@ sub show_help { info_dialog("help",
)
}
-# adjust pxe confi with good value
-sub pxe_conf {
- if (!-f "$pxeconf.orig") { cp_af($pxeconf, "$pxeconf.orig") }
- substInFile {
- s/default_address.*/default_address=$IPSERVER/;
- s/mtftp_address.*/mtftp_address=$IPSERVER/;
- s/domain.*/domain=$DOMAINNAME/;
- } $pxeconf;
-}
-
sub check_pxe_conf {
- if (! any { /default_address=$IPSERVER/ } cat_($pxeconf)) {
+ my $ip_address = network::tools::get_interface_ip_address($net, $interface);
+ if (! any { /default_address=$ip_address/ } cat_($network::pxe::pxe_config_file)) {
# pxe.conf doesnt matche system, relaunch wizard_pxe_server
- err_dialog(N("Error!"), N("Your %s doesn't match your actual IP address configuration. Relaunching the PXE server wizard to readjust it.", $pxeconf)) and launch_pxe_server();
+ err_dialog(N("Error!"), N("Your %s doesn't match your actual IP address configuration. Relaunching the PXE server wizard to readjust it.", $network::pxe::pxe_config_file)) and launch_pxe_server();
}
}
@@ -924,14 +666,13 @@ sub wizard_pxe_server {
summaryserver => {
name => N("The wizard will now prepare all default files to set up your PXE server"),
pre => sub {
- ($IPSERVER) = `/sbin/ip addr show dev $interface` =~ /^\s*inet\s+(\d+\.\d+\.\d+\.\d+)/m;
output($sys_wizard_pxe, "INTERFACE=$interface\n");
},
data => [
- { label => N("TFTP directory: %s", $TFTPDIR) },
- { label => N("Boot image path: %s", $IMGPATH) },
- { label => N("PXE config file: %s", $pxeconf) },
- { label => N("PXE help file: %s", $PXEHELP) },
+ { label => N("TFTP directory: %s", $network::pxe::tftp_root) },
+ { label => N("Boot image path: %s", $network::pxe::pxelinux_images) },
+ { label => N("PXE config file: %s", $network::pxe::pxe_config_file) },
+ { label => N("PXE help file: %s", $network::pxe::pxelinux_help_file) },
],
post => \&do_it_pxe,
no_back => 1,
@@ -960,45 +701,14 @@ sub save_config {
}
}
-# set default PXE message
-sub default_pxe_messages {
- save_config($PXEMESSAGE);
- output($PXEMESSAGE, <<EOF);
-
- Welcome to Mandrakelinux 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 default_pxe_menu {
- save_config($PXEHELP);
- output($PXEHELP, <<EOF);
-Available images are:
----------------------
-local: local boot
-EOF
-}
-
# can adjust block size in tftp server (ita64)
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";
+ substInFile { s/server_args.*/server_args = -r blksize -s $network::pxe::tftp_root/ } "$XINETDDIR/tftp";
} else {
- substInFile { s/server_args.*/server_args = -s $TFTPDIR/ } "$XINETDDIR/tftp";
+ substInFile { s/server_args.*/server_args = -s $network::pxe::tftp_root/ } "$XINETDDIR/tftp";
}
}
@@ -1008,8 +718,8 @@ sub enable_tftps {
}
sub memlinux_prep {
- if (!-f "$X86/memdisk") {
- cp_af($MEMDISK, $X86);
+ if (!-f $network::pxe::pxelinux_client_root . "/memdisk") {
+ cp_af($MEMDISK, $network::pxe::pxelinux_client_root);
}
}
@@ -1024,20 +734,35 @@ sub check_started {
# main procedure to setup PXE server
sub do_it_pxe {
return if $::testing;
- my $in = 'interactive'->vnew('su', 'PXE server');
my $w = $in->wait_message(N("PXE server"), N("Configuring a PXE server on your system..."));
- output("$X86/drakwizard_pxe", <<EOF);
+ output($network::pxe::pxelinux_client_root . "/drakwizard_pxe", <<EOF);
do not remove
use to check if drakwizard PXE set server
has been launch.
EOF
- mkdir_p($IMGPATH);
+ mkdir_p($network::pxe::pxelinux_images);
memlinux_prep();
- default_pxe_menu();
- default_pxe_messages();
+
+ #- restore default pxe settings
+ put_in_hash($pxelinux_conf, {
+ 'prompt' => 1,
+ 'default' => 'local',
+ 'display' => 'messages',
+ 'timeout' => '50',
+ 'f1' => 'help.txt',
+ });
+ network::pxe::write_pxelinux_conf($pxelinux_conf);
+
+ save_config($network::pxe::pxelinux_help_file);
+ network::pxe::write_default_pxe_help();
+
+ save_config($network::pxe::pxelinux_message_file);
+ network::pxe::write_default_pxe_messages($net);
+
+ network::pxe::write_pxe_conf($net, $interface);
+
enable_tftps();
- pxe_conf();
tftp_blksize('N');
system("service $_ restart") foreach qw(xinetd pxe);
undef $w;
@@ -1064,7 +789,7 @@ sub add_columns {
###############
# check if first launch
-if (! -f "$X86/drakwizard_pxe") {
+if (! -f $network::pxe::pxelinux_client_root . "/drakwizard_pxe") {
info_dialog(N("Please configure a PXE server"), N("It seems this is the first time you run this tool.\nA wizard will appear to configure your PXE server."));
launch_pxe_server();
}
@@ -1098,21 +823,18 @@ add_columns($treeview);
# labels that list pxe menu entry
my $labelscombo = Gtk2::OptionMenu->new;
#my @labelslist = list_label_pxe;
-my $defaultlabel = get_default_pxe;
+my $defaultlabel = $pxelinux_conf->{default};
$labelscombo->entry->set_text($defaultlabel);
-$labelscombo->entry->signal_connect("changed", sub { my $new_default = $labelscombo->entry->get_text;
- set_new_default($new_default);
- }
- );
+$labelscombo->entry->signal_connect("changed", sub { $pxelinux_conf->{default} = $labelscombo->entry->get_text });
-my @o = list_label_pxe;
+my @o = network::pxe::list_pxelinux_labels($pxelinux_conf);
$labelscombo->set_popdown_strings("", sort(@o));
$labelscombo->entry->set_text($defaultlabel);
set_help_tip($labelscombo, 'labels');
my $okcancel = create_okcancel({
cancel_clicked => sub { ugtk2->exit },
- ok_clicked => &write_conf_pxe,
+ ok_clicked => sub { network::pxe::write_pxelinux_conf($pxelinux_conf) },
},
);