diff options
author | damien <damien@mandriva.com> | 2000-09-01 04:29:05 +0000 |
---|---|---|
committer | damien <damien@mandriva.com> | 2000-09-01 04:29:05 +0000 |
commit | 9e6f0a8dc550dcbb0025b6c78e9938dade9831af (patch) | |
tree | 2c493e8cafe1ec92892e819e0d6134fc0a272b15 | |
parent | e02218b14f952753aa6ddc3b6cfb9a067732919e (diff) | |
download | drakx-backup-do-not-use-9e6f0a8dc550dcbb0025b6c78e9938dade9831af.tar drakx-backup-do-not-use-9e6f0a8dc550dcbb0025b6c78e9938dade9831af.tar.gz drakx-backup-do-not-use-9e6f0a8dc550dcbb0025b6c78e9938dade9831af.tar.bz2 drakx-backup-do-not-use-9e6f0a8dc550dcbb0025b6c78e9938dade9831af.tar.xz drakx-backup-do-not-use-9e6f0a8dc550dcbb0025b6c78e9938dade9831af.zip |
see changelog. Big changes.
-rw-r--r-- | perl-install/ChangeLog | 5 | ||||
-rw-r--r-- | perl-install/any.pm | 141 | ||||
-rw-r--r-- | perl-install/install_interactive.pm | 107 | ||||
-rw-r--r-- | perl-install/install_steps.pm | 20 | ||||
-rw-r--r-- | perl-install/install_steps_auto_install.pm | 5 | ||||
-rw-r--r-- | perl-install/install_steps_interactive.pm | 132 | ||||
-rw-r--r-- | perl-install/network.pm | 145 |
7 files changed, 289 insertions, 266 deletions
diff --git a/perl-install/ChangeLog b/perl-install/ChangeLog index cf692c2fe..2cd256f53 100644 --- a/perl-install/ChangeLog +++ b/perl-install/ChangeLog @@ -1,3 +1,8 @@ +2000-08-31 dam's <damien@mandrakesoft.com> + + * moved many things to network.pm and any.pm + * everything should be broken now. + 2000-08-31 François Pons <fpons@mandrakesoft.com> * install2.pm: removed printer default config (now obsoleted). diff --git a/perl-install/any.pm b/perl-install/any.pm index 3edfc176d..1878ed0c7 100644 --- a/perl-install/any.pm +++ b/perl-install/any.pm @@ -14,6 +14,7 @@ use partition_table qw(:types); use fsedit; use fs; use run_program; +use modules; use log; #-PO: names (tie, curly...) have corresponding icons for kdm @@ -288,17 +289,17 @@ sub inspect { #-----modem conf sub pppConfig { - my ($o) = @_; - $o->{modem} or return; + my ($in, $modem, $prefix) = @_; + $modem or return; - symlinkf($o->{modem}{device}, "$o->{prefix}/dev/modem") or log::l("creation of $o->{prefix}/dev/modem failed"); - $::isStandalone ? `urpmi --auto ppp` : $o->pkg_install("ppp") unless $::testing; + symlinkf($modem->{device}, "$prefix/dev/modem") or log::l("creation of $prefix/dev/modem failed"); + $::isStandalone ? `urpmi --auto ppp` : $in->pkg_install("ppp") unless $::testing; my %toreplace; - $toreplace{$_} = $o->{modem}{$_} foreach qw(connection phone login passwd auth domain dns1 dns2); - $toreplace{kpppauth} = ${{ 'Script-based' => 0, 'PAP' => 1, 'Terminal-based' => 2, 'CHAP' => 3, }}{$o->{modem}{auth}}; + $toreplace{$_} = $modem->{$_} foreach qw(connection phone login passwd auth domain dns1 dns2); + $toreplace{kpppauth} = ${{ 'Script-based' => 0, 'PAP' => 1, 'Terminal-based' => 2, 'CHAP' => 3, }}{$modem->{auth}}; $toreplace{phone} =~ s/\D//g; - $toreplace{dnsserver} = join ',', map { $o->{modem}{$_} } "dns1", "dns2"; + $toreplace{dnsserver} = join ',', map { $modem->{$_} } "dns1", "dns2"; $toreplace{dnsserver} .= $toreplace{dnsserver} && ','; #- using peerdns or dns1,dns2 avoid writing a /etc/resolv.conf file. @@ -307,10 +308,10 @@ sub pppConfig { $toreplace{connection} ||= 'DialupConnection'; $toreplace{domain} ||= 'localdomain'; $toreplace{intf} ||= 'ppp0'; - $toreplace{papname} = $o->{modem}{auth} eq 'PAP' && $toreplace{login}; + $toreplace{papname} = $modem->{auth} eq 'PAP' && $toreplace{login}; #- build ifcfg-ppp0. - my $ifcfg = "$o->{prefix}/etc/sysconfig/network-scripts/ifcfg-ppp0"; + my $ifcfg = "$prefix/etc/sysconfig/network-scripts/ifcfg-ppp0"; local *IFCFG; open IFCFG, ">$ifcfg" or die "Can't open $ifcfg"; print IFCFG <<END; DEVICE="$toreplace{intf}" @@ -347,7 +348,7 @@ END close IFCFG; #- build chat-ppp0. - my $chat = "$o->{prefix}/etc/sysconfig/network-scripts/chat-ppp0"; + my $chat = "$prefix/etc/sysconfig/network-scripts/chat-ppp0"; local *CHAT; open CHAT, ">$chat" or die "Can't open $chat"; print CHAT <<END; 'ABORT' 'BUSY' @@ -358,11 +359,11 @@ END 'ABORT' 'Login incorrect' '' 'ATZ' 'OK' -'ATDT$o->{netcnx}{special_command}' +'ATDT$modem->{special_command}' 'ATDT$toreplace{phone}' 'CONNECT' '' END - if ($o->{modem}{auth} eq 'Terminal-based' || $o->{modem}{auth} eq 'Script-based') { + if ($modem->{auth} eq 'Terminal-based' || $modem->{auth} eq 'Script-based') { print CHAT <<END; 'ogin:' '$toreplace{login}' 'ord:' '$toreplace{passwd}' @@ -374,9 +375,9 @@ END END close CHAT; - if ($o->{modem}{auth} eq 'PAP') { + if ($modem->{auth} eq 'PAP') { #- need to create a secrets file for the connection. - my $secrets = "$o->{prefix}/etc/ppp/" . lc($o->{modem}{auth}) . "-secrets"; + my $secrets = "$prefix/etc/ppp/" . lc($modem->{auth}) . "-secrets"; my @l = cat_($secrets); my $replaced = 0; do { $replaced ||= 1 @@ -395,16 +396,116 @@ END } #- CHAP is not supported by initscripts, need patching before doing more on that here! #-install_any::template2userfile($o->{prefix}, "$ENV{SHARE_PATH}/kppprc.in", ".kde/share/config/kppprc", 1, %toreplace); - commands::mkdir_("-p", "$o->{prefix}/usr/share/config"); - template2file("$ENV{SHARE_PATH}/kppprc.in", "$o->{prefix}/usr/share/config/kppprc", %toreplace); + commands::mkdir_("-p", "$prefix/usr/share/config"); + template2file("$ENV{SHARE_PATH}/kppprc.in", "$prefix/usr/share/config/kppprc", %toreplace); - miscellaneousNetwork($o); + miscellaneousNetwork($in, $prefix); } sub miscellaneousNetwork { - my ($o) = @_; - setVarsInSh ("$o->{prefix}/etc/profile.d/proxy.sh", $o->{miscellaneous}, qw(http_proxy ftp_proxy)); - setVarsInCsh("$o->{prefix}/etc/profile.d/proxy.csh", $o->{miscellaneous}, qw(http_proxy ftp_proxy)); + my ($in, $prefix) = @_; + setVarsInSh ("$prefix/etc/profile.d/proxy.sh", $::o->{miscellaneous}, qw(http_proxy ftp_proxy)); + setVarsInCsh("$prefix/etc/profile.d/proxy.csh", $::o->{miscellaneous}, qw(http_proxy ftp_proxy)); +} + +sub load_thiskind { + my ($in, $type, $pcmcia) = @_; + my $pcmcia2 = $pcmcia if modules::pcmcia_need_config($pcmcia) && !$::noauto; + my $w; $w = $in->wait_message(_("PCMCIA"), _("Configuring PCMCIA cards...")) if $pcmcia2; + modules::load_thiskind($type, $pcmcia2, sub { $w = wait_load_module($in, $type, @_) }); +} + +sub setup_thiskind { + my ($in, $type, $auto, $at_least_one, $pcmcia) = @_; + + return if arch() eq "ppc"; + + my @l; + if (!$::noauto) { + @l = load_thiskind($in, $type, $pcmcia); + if (my @err = grep { $_ } map { $_->{error} } @l) { + $in->ask_warn('', join("\n", @err)); + } + return @l if $auto && (@l || !$at_least_one); + } + @l = map { $_->{description} } @l; + while (1) { + my ($msg_type) = $type =~ s/\|.*//; + my $msg = @l ? + [ _("Found %s %s interfaces", join(", ", @l), $msg_type), + _("Do you have another one?") ] : + _("Do you have any %s interfaces?", $msg_type); + + my $opt = [ __("Yes"), __("No") ]; + push @$opt, __("See hardware info") if $::expert; + my $r = "Yes"; + $r = $in->ask_from_list_('', $msg, $opt, "No") unless $at_least_one && @l == 0; + if ($r eq "No") { return @l } + if ($r eq "Yes") { + push @l, load_module($in, $type) || next; + } else { + $in->ask_warn('', [ detect_devices::stringlist() ]); + } + } +} + +sub wait_load_module { + my ($in, $type, $text, $module) = @_; +#-PO: the first %s is the card type (scsi, network, sound,...) +#-PO: the second is the vendor+model name + $in->wait_message('', + [ _("Installing driver for %s card %s", $type, $text), + $::beginner ? () : _("(module %s)", $module) + ]); +} + +sub load_module { + my ($in, $type) = @_; + my @options; + + my $m = $in->ask_from_listf('', +#-PO: the %s is the driver type (scsi, network, sound,...) + _("Which %s driver should I try?", $type), + \&modules::module2text, + [ modules::module_of_type($type) ]) or return; + my $l = modules::module2text($m); + require modparm; + my @names = modparm::get_options_name($m); + + if ((@names != 0) && $in->ask_from_list_('', +_("In some cases, the %s driver needs to have extra information to work +properly, although it normally works fine without. Would you like to specify +extra options for it or allow the driver to probe your machine for the +information it needs? Occasionally, probing will hang a computer, but it should +not cause any damage.", $l), + [ __("Autoprobe"), __("Specify options") ], "Autoprobe") ne "Autoprobe") { + ASK: + if (@names >= 0) { + my @l = $in->ask_from_entries('', +_("You may now provide its options to module %s.", $l), + \@names) or return; + @options = modparm::get_options_result($m, @l); + } else { + @options = split ' ', + $in->ask_from_entry('', +_("You may now provide its options to module %s. +Options are in format ``name=value name2=value2 ...''. +For instance, ``io=0x300 irq=7''", $l), + _("Module options:"), + ); + } + } + eval { + my $w = wait_load_module($in, $type, $l, $m); + modules::load($m, $type, @options); + }; + if ($@) { + $in->ask_yesorno('', +_("Loading module %s failed. +Do you want to try again with other parameters?", $l), 1) or return; + goto ASK; + } + $l; } diff --git a/perl-install/install_interactive.pm b/perl-install/install_interactive.pm index d60e922cb..d27fdd1f4 100644 --- a/perl-install/install_interactive.pm +++ b/perl-install/install_interactive.pm @@ -188,111 +188,14 @@ sub partitionWizard { } #-------------------------------------------------------------------------------- -sub wait_load_module { - my ($o, $type, $text, $module) = @_; -#-PO: the first %s is the card type (scsi, network, sound,...) -#-PO: the second is the vendor+model name - $o->wait_message('', - [ _("Installing driver for %s card %s", $type, $text), - $::beginner ? () : _("(module %s)", $module) - ]); -} - - -sub load_module { - my ($o, $type) = @_; - my @options; - - my $m = $o->ask_from_listf('', -#-PO: the %s is the driver type (scsi, network, sound,...) - _("Which %s driver should I try?", $type), - \&modules::module2text, - [ modules::module_of_type($type) ]) or return; - my $l = modules::module2text($m); - require modparm; - my @names = modparm::get_options_name($m); - - if ((@names != 0) && $o->ask_from_list_('', -_("In some cases, the %s driver needs to have extra information to work -properly, although it normally works fine without. Would you like to specify -extra options for it or allow the driver to probe your machine for the -information it needs? Occasionally, probing will hang a computer, but it should -not cause any damage.", $l), - [ __("Autoprobe"), __("Specify options") ], "Autoprobe") ne "Autoprobe") { - ASK: - if (@names >= 0) { - my @l = $o->ask_from_entries('', -_("You may now provide its options to module %s.", $l), - \@names) or return; - @options = modparm::get_options_result($m, @l); - } else { - @options = split ' ', - $o->ask_from_entry('', -_("You may now provide its options to module %s. -Options are in format ``name=value name2=value2 ...''. -For instance, ``io=0x300 irq=7''", $l), - _("Module options:"), - ); - } - } - eval { - my $w = wait_load_module($o, $type, $l, $m); - modules::load($m, $type, @options); - }; - if ($@) { - $o->ask_yesorno('', -_("Loading module %s failed. -Do you want to try again with other parameters?", $l), 1) or return; - goto ASK; - } - $l; -} - +#- wait_load_module moved to any.pm +#- load_module moved to any.pm #------------------------------------------------------------------------------ -sub load_thiskind { - my ($o, $type) = @_; - my $pcmcia = $o->{pcmcia} if modules::pcmcia_need_config($o->{pcmcia}) && !$::noauto; - my $w; $w = $o->wait_message(_("PCMCIA"), _("Configuring PCMCIA cards...")) if $pcmcia; - modules::load_thiskind($type, $pcmcia, sub { $w = wait_load_module($o, $type, @_) }); -} - - +#-load_thiskind moved to any.pm #------------------------------------------------------------------------------ -sub setup_thiskind { - my ($o, $type, $auto, $at_least_one) = @_; - - return if arch() eq "ppc"; - - my @l; - if (!$::noauto) { - @l = load_thiskind($o, $type); - if (my @err = grep { $_ } map { $_->{error} } @l) { - $o->ask_warn('', join("\n", @err)); - } - return @l if $auto && (@l || !$at_least_one); - } - @l = map { $_->{description} } @l; - while (1) { - (my $msg_type = $type) =~ s/\|.*//; - my $msg = @l ? - [ _("Found %s %s interfaces", join(", ", @l), $msg_type), - _("Do you have another one?") ] : - _("Do you have any %s interfaces?", $msg_type); - - my $opt = [ __("Yes"), __("No") ]; - push @$opt, __("See hardware info") if $::expert; - my $r = "Yes"; - $r = $o->ask_from_list_('', $msg, $opt, "No") unless $at_least_one && @l == 0; - if ($r eq "No") { return @l } - if ($r eq "Yes") { - push @l, load_module($o, $type) || next; - } else { - $o->ask_warn('', [ detect_devices::stringlist() ]); - } - } -} - +#-setup_thiskind moved to any.pm #------------------------------------------------------------------------------ + sub upNetwork { my ($o, $pppAvoided) = @_; my $w = $o->wait_message('', _("Bringing up the network")); diff --git a/perl-install/install_steps.pm b/perl-install/install_steps.pm index d0a5b2b21..e21957845 100644 --- a/perl-install/install_steps.pm +++ b/perl-install/install_steps.pm @@ -477,25 +477,7 @@ sub selectMouse($) { } #------------------------------------------------------------------------------ -sub configureNetwork($) { - my ($o) = @_; - my $etc = "$o->{prefix}/etc"; - - network::write_conf("$etc/sysconfig/network", $o->{netc}); - network::write_resolv_conf("$etc/resolv.conf", $o->{netc}); - network::write_interface_conf("$etc/sysconfig/network-scripts/ifcfg-$_->{DEVICE}", $_) foreach @{$o->{intf}}; - network::add2hosts("$etc/hosts", $o->{netc}{HOSTNAME}, map { $_->{IPADDR} } @{$o->{intf}}); - network::sethostname($o->{netc}) unless $::testing; - network::addDefaultRoute($o->{netc}) unless $::testing; - - $o->pkg_install("dhcpcd") if grep { $_->{BOOTPROTO} =~ /^(dhcp)$/ } @{$o->{intf}}; - # Handle also pump (this is still in initscripts no?) - $o->pkg_install("pump") if grep { $_->{BOOTPROTO} =~ /^(pump|bootp)$/ } @{$o->{intf}}; - #-res_init(); #- reinit the resolver so DNS changes take affect - - any::miscellaneousNetwork($o); -} - +#- configureNetwork moved to network and is renamed. #------------------------------------------------------------------------------ #------------------------------------------------------------------------------ diff --git a/perl-install/install_steps_auto_install.pm b/perl-install/install_steps_auto_install.pm index e7025e64f..7b20db611 100644 --- a/perl-install/install_steps_auto_install.pm +++ b/perl-install/install_steps_auto_install.pm @@ -2,6 +2,7 @@ package install_steps_auto_install; use diagnostics; use strict; +use netconnect; use vars qw(@ISA); @ISA = qw(install_steps); @@ -34,7 +35,9 @@ sub new { sub configureNetwork { my ($o) = @_; modules::load_thiskind('net', $o->{pcmcia}); - install_steps::configureNetwork($o); +#- install_steps::configureNetwork($o); + $o->{netcnx}||={}; + netconnect::net_connect($o->{prefix}, $o->{netcnx}, $o->{netc}, $o->{modem}, $o->{mouse}, $o, $o->{pcmcia}, $o->{intf}, 1); } sub enteringStep($$$) { diff --git a/perl-install/install_steps_interactive.pm b/perl-install/install_steps_interactive.pm index 712fc5584..09ed55085 100644 --- a/perl-install/install_steps_interactive.pm +++ b/perl-install/install_steps_interactive.pm @@ -168,7 +168,7 @@ sub selectMouse { [ mouse::serial_ports ]); } - install_interactive::setup_thiskind($o, 'usb', !$::expert, 0) if $o->{mouse}{device} eq "usbmouse"; + any::setup_thiskind($o, 'usb', !$::expert, 0, $o->{pcmcia}) if $o->{mouse}{device} eq "usbmouse"; eval { devices::make("usbmouse"); modules::load("usbmouse"); @@ -184,7 +184,7 @@ sub setupSCSI { my $w = $o->wait_message(_("IDE"), _("Configuring IDE")); modules::load_ide(); } - install_interactive::setup_thiskind($o, 'scsi|disk', $_[1], $_[2]); + any::setup_thiskind($o, 'scsi|disk', $_[1], $_[2], $o->{pcmcia}); } sub ask_mntpoint_s { @@ -458,111 +458,15 @@ sub afterInstallPackages($) { } #------------------------------------------------------------------------------ -sub configureNetwork($) { +sub configureNetwork { my ($o, $first_time) = @_; - local $_; - if (@{$o->{intf}} > 0 && $first_time) { - my @l = ( - __("Keep the current IP configuration"), - __("Reconfigure network now"), - __("Do not set up networking"), - ); - $_ = $::beginner ? "Keep" : - $o->ask_from_list_([ _("Network Configuration") ], - _("Local networking has already been configured. Do you want to:"), - [ @l ]) || "Do not"; - } else { - $_ = (!$::beginner || install_interactive::setup_thiskind($o, 'net', 1, 0)) && - $o->ask_yesorno([ _("Network Configuration") ], - _("Do you want to configure a local network for your system?"), 0) ? "Local LAN" : "Do not"; - } - if (/^Do not/) { - $o->{netc}{NETWORKING} = "false"; - } elsif (!/^Keep/) { - install_interactive::setup_thiskind($o, 'net', !$::expert, 1); - my @l = detect_devices::getNet() or die _("no network card found"); - - my $last; foreach ($::beginner ? $l[0] : @l) { - my $intf = network::findIntf($o->{intf} ||= [], $_); - add2hash($intf, $last); - add2hash($intf, { NETMASK => '255.255.255.0' }); - $o->configureNetworkIntf($intf) or last; - - $o->{netc} ||= {}; - delete $o->{netc}{dnsServer}; - delete $o->{netc}{GATEWAY}; - $last = $intf; - } - #- { - #- my $wait = $o->wait_message(_("Hostname"), _("Determining host name and domain...")); - #- network::guessHostname($o->{prefix}, $o->{netc}, $o->{intf}); - #- } - if ($last->{BOOTPROTO} =~ /^(dhcp|bootp)$/) { - $o->ask_from_entries_ref(_("Configuring network"), -_("Please enter your host name if you know it. -Some DHCP servers require the hostname to work. -Your host name should be a fully-qualified host name, -such as ``mybox.mylab.myco.com''."), - [_("Host name:")], [ \$o->{netc}{HOSTNAME} ]); - } else { - $o->configureNetworkNet($o->{netc}, $last ||= {}, @l); - } - $o->miscellaneousNetwork(); - } - install_steps::configureNetwork($o); - - #- added internet configuration after ethernet one. - netconnect::net_connect($o->{prefix}, $o->{netcnx}, $o, bool($o->{pcmcia})); #-dam's + $o->{netcnx}||={}; + netconnect::net_connect($o->{prefix}, $o->{netcnx}, $o->{netc}, $o->{modem}, $o->{mouse}, $o, $o->{pcmcia}, $o->{intf}, $first_time); } -sub configureNetworkIntf { - my ($o, $intf) = @_; - my $pump = $intf->{BOOTPROTO} =~ /^(dhcp|bootp)$/; - delete $intf->{NETWORK}; - delete $intf->{BROADCAST}; - my @fields = qw(IPADDR NETMASK); - $o->set_help('configureNetworkIP'); - $o->ask_from_entries_ref(_("Configuring network device %s", $intf->{DEVICE}), -($::isStandalone ? '' : _("Configuring network device %s", $intf->{DEVICE}) . "\n\n") . -_("Please enter the IP configuration for this machine. -Each item should be entered as an IP address in dotted-decimal -notation (for example, 1.2.3.4)."), - [ _("IP address:"), _("Netmask:"), _("Automatic IP") ], - [ \$intf->{IPADDR}, \$intf->{NETMASK}, { val => \$pump, type => "bool", text => _("(bootp/dhcp)") } ], - complete => sub { - $intf->{BOOTPROTO} = $pump ? "dhcp" : "static"; - return 0 if $pump; - for (my $i = 0; $i < @fields; $i++) { - unless (network::is_ip($intf->{$fields[$i]})) { - $o->ask_warn('', _("IP address should be in format 1.2.3.4")); - return (1,$i); - } - return 0; - } - }, - focus_out => sub { - $intf->{NETMASK} ||= network::netmask($intf->{IPADDR}) unless $_[0] - } - ); -} - -sub configureNetworkNet { - my ($o, $netc, $intf, @devices) = @_; - - $netc->{dnsServer} ||= network::dns($intf->{IPADDR}); - $netc->{GATEWAY} ||= network::gateway($intf->{IPADDR}); - - $o->ask_from_entries_ref(_("Configuring network"), -_("Please enter your host name. -Your host name should be a fully-qualified host name, -such as ``mybox.mylab.myco.com''. -You may also enter the IP address of the gateway if you have one"), - [_("Host name:"), _("DNS server:"), _("Gateway:"), $::expert ? _("Gateway device:") : ()], - [(map { \$netc->{$_} } qw(HOSTNAME dnsServer GATEWAY)), - {val => \$netc->{GATEWAYDEV}, list => \@devices}] - ); -} +#-configureNetworkIntf moved to network +#-configureNetworkNet moved to network #------------------------------------------------------------------------------ #-pppConfig moved to any.pm #------------------------------------------------------------------------------ @@ -865,27 +769,7 @@ try to force installation even if that destroys the first partition?")); } #------------------------------------------------------------------------------ -sub miscellaneousNetwork { - my ($o, $clicked) = @_; - my $u = $o->{miscellaneous} ||= {}; - - $o->set_help('configureNetworkProxy'); - !$::beginner || $clicked and $o->ask_from_entries_ref('', - _("Proxies configuration"), - [ _("HTTP proxy"), - _("FTP proxy"), - ], - [ \$u->{http_proxy}, - \$u->{ftp_proxy}, - ], - complete => sub { - $u->{http_proxy} =~ m,^($|http://), or $o->ask_warn('', _("Proxy should be http://...")), return 1,3; - $u->{ftp_proxy} =~ m,^($|ftp://), or $o->ask_warn('', _("Proxy should be ftp://...")), return 1,4; - 0; - } - ) || return; -} - +#- miscellaneousNetwork moved to network.pm #------------------------------------------------------------------------------ sub miscellaneous { my ($o, $clicked) = @_; diff --git a/perl-install/network.pm b/perl-install/network.pm index 2c118222a..8aea39a12 100644 --- a/perl-install/network.pm +++ b/perl-install/network.pm @@ -11,6 +11,7 @@ use Socket; use common qw(:common :file :system :functional); use detect_devices; use run_program; +use any; use log; #-###################################################################################### @@ -233,6 +234,150 @@ sub gateway { } +sub configureNetwork { + my ($prefix, $netc, $in, $pcmcia, $intf, $first_time) = @_; + local $_; + if (@{$intf} > 0 && $first_time) { + my @l = ( + __("Keep the current IP configuration"), + __("Reconfigure network now"), + __("Do not set up networking"), + ); + $_ = $::beginner ? "Keep" : + $in->ask_from_list_([ _("Network Configuration") ], + _("Local networking has already been configured. Do you want to:"), + [ @l ]) || "Do not"; + } else { + $_ = (!$::beginner || any::setup_thiskind($in, 'net', 1, 0, $pcmcia)) && + $in->ask_yesorno([ _("Network Configuration") ], + _("Do you want to configure a local network for your system?"), 0) ? "Local LAN" : "Do not"; + } + if (/^Do not/) { + $netc->{NETWORKING} = "false"; + } elsif (!/^Keep/) { + any::setup_thiskind($in, 'net', !$::expert, 1, $pcmcia); + my @l = detect_devices::getNet() or die _("no network card found"); + + my $last; foreach ($::beginner ? $l[0] : @l) { + my $intf2 = findIntf($intf ||= [], $_); + add2hash($intf2, $last); + add2hash($intf2, { NETMASK => '255.255.255.0' }); + configureNetworkIntf($in, $intf2) or last; + + $netc ||= {}; + delete $netc->{dnsServer}; + delete $netc->{GATEWAY}; + $last = $intf2; + } + #- { + #- my $wait = $o->wait_message(_("Hostname"), _("Determining host name and domain...")); + #- network::guessHostname($o->{prefix}, $o->{netc}, $o->{intf}); + #- } + if ($last->{BOOTPROTO} =~ /^(dhcp|bootp)$/) { + $in->ask_from_entries_ref(_("Configuring network"), +_("Please enter your host name if you know it. +Some DHCP servers require the hostname to work. +Your host name should be a fully-qualified host name, +such as ``mybox.mylab.myco.com''."), + [_("Host name:")], [ \$netc->{HOSTNAME} ]); + } else { + configureNetworkNet($in, $netc, $last ||= {}, @l); + } + miscellaneousNetwork($in); + } + configureNetwork2($in, $prefix, $netc, $intf); +} + +sub miscellaneousNetwork { + my ($in, $clicked) = @_; + my $u = $::o->{miscellaneous} ||= {}; + $::isStandalone or $in->set_help('configureNetworkProxy'); + !$::beginner || $clicked and $in->ask_from_entries_ref('', + _("Proxies configuration"), + [ _("HTTP proxy"), + _("FTP proxy"), + ], + [ \$u->{http_proxy}, + \$u->{ftp_proxy}, + ], + complete => sub { + $u->{http_proxy} =~ m,^($|http://), or $in->ask_warn('', _("Proxy should be http://...")), return 1,3; + $u->{ftp_proxy} =~ m,^($|ftp://), or $in->ask_warn('', _("Proxy should be ftp://...")), return 1,4; + 0; + } + ) || return; +} + +sub configureNetworkNet { + my ($in, $netc, $intf, @devices) = @_; + + $netc->{dnsServer} ||= dns($intf->{IPADDR}); + $netc->{GATEWAY} ||= gateway($intf->{IPADDR}); + + $in->ask_from_entries_ref(_("Configuring network"), +_("Please enter your host name. +Your host name should be a fully-qualified host name, +such as ``mybox.mylab.myco.com''. +You may also enter the IP address of the gateway if you have one"), + [_("Host name:"), _("DNS server:"), _("Gateway:"), $::expert ? _("Gateway device:") : ()], + [(map { \$netc->{$_} } qw(HOSTNAME dnsServer GATEWAY)), + {val => \$netc->{GATEWAYDEV}, list => \@devices}] + ); +} + + +sub configureNetwork2 { + my ($in, $prefix, $netc, $intf) = @_; + my $etc = "$prefix/etc"; + + write_conf("$etc/sysconfig/network", $netc); + write_resolv_conf("$etc/resolv.conf", $netc); + write_interface_conf("$etc/sysconfig/network-scripts/ifcfg-$_->{DEVICE}", $_) foreach @{$intf}; + add2hosts("$etc/hosts", $netc->{HOSTNAME}, map { $_->{IPADDR} } @{$intf}); + sethostname($netc) unless $::testing; + addDefaultRoute($netc) unless $::testing; + + $in->pkg_install("dhcpcd") if grep { $_->{BOOTPROTO} =~ /^(dhcp)$/ } @{$intf}; + # Handle also pump (this is still in initscripts no?) + $in->pkg_install("pump") if grep { $_->{BOOTPROTO} =~ /^(pump|bootp)$/ } @{$intf}; + #-res_init(); #- reinit the resolver so DNS changes take affect + + any::miscellaneousNetwork($in, $prefix); +} + + +sub configureNetworkIntf { + my ($in, $intf) = @_; + my $pump = $intf->{BOOTPROTO} =~ /^(dhcp|bootp)$/; + delete $intf->{NETWORK}; + delete $intf->{BROADCAST}; + my @fields = qw(IPADDR NETMASK); + $in->set_help('configureNetworkIP'); + $in->ask_from_entries_ref(_("Configuring network device %s", $intf->{DEVICE}), +($::isStandalone ? '' : _("Configuring network device %s", $intf->{DEVICE}) . "\n\n") . +_("Please enter the IP configuration for this machine. +Each item should be entered as an IP address in dotted-decimal +notation (for example, 1.2.3.4)."), + [ _("IP address:"), _("Netmask:"), _("Automatic IP") ], + [ \$intf->{IPADDR}, \$intf->{NETMASK}, { val => \$pump, type => "bool", text => _("(bootp/dhcp)") } ], + complete => sub { + $intf->{BOOTPROTO} = $pump ? "dhcp" : "static"; + return 0 if $pump; + for (my $i = 0; $i < @fields; $i++) { + unless (is_ip($intf->{$fields[$i]})) { + $in->ask_warn('', _("IP address should be in format 1.2.3.4")); + return (1,$i); + } + return 0; + } + }, + focus_out => sub { + $intf->{NETMASK} ||= netmask($intf->{IPADDR}) unless $_[0] + } + ); +} + + #-###################################################################################### #- Wonderful perl :( #-###################################################################################### |