summaryrefslogtreecommitdiffstats
path: root/rescue
diff options
context:
space:
mode:
Diffstat (limited to 'rescue')
0 files changed, 0 insertions, 0 deletions
f='#n41'>41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
package network::ethernet;

use network::network;
use modules;
use any;
use detect_devices;
use common;
use run_program;
use network::tools;
use vars qw(@ISA @EXPORT);
use MDK::Common::Globals "network", qw($in $prefix);

@ISA = qw(Exporter);
@EXPORT = qw(configureNetwork conf_network_card conf_network_card_backend go_ethernet);

sub configure_cable {
    my ($netcnx, $netc, $intf, $first_time) = @_;
    $::isInstall and $in->set_help('configureNetworkCable');
    $netcnx->{type}='cable';
    #  		     $netcnx->{cable}={};
    #  		     $in->ask_from_entries_ref(_("Cable connection"),
    #  _("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:")], [ \$netcnx->{cable}{hostname} ]);
    if ($::expert) {
	my @m = (
	       { description => "dhcpcd",
		 c => 1},
	       { description => "dhcpxd",
		 c => 3},
	       { description => "dhcp-client",
		 c => 4},
	      );
	if (my $f = $in->ask_from_listf(_("Connect to the Internet"),
					_("Which dhcp client do you want to use?
Default is dhcpcd"),
					sub { $_[0]{description} },
					\@m)) {
	    $f->{c}==1 and $netcnx->{dhcp_client}="dhcpcd" and $in->do_pkgs->install(qw(dhcpcd));
	    $f->{c}==3 and $netcnx->{dhcp_client}="dhcpxd" and $in->do_pkgs->install(qw(dhcpxd));
	    $f->{c}==4 and $netcnx->{dhcp_client}="dhcp-client" and $in->do_pkgs->install(qw(dhcp-client));
	}
    } else {
	$in->do_pkgs->install(qw(dhcpcd));
    }
    go_ethernet($netc, $intf, 'dhcp', '', '', $first_time);
    write_cnx_script($netc, "cable",
qq(
/sbin/ifup $netc->{NET_DEVICE}
),
qq(
/sbin/ifdown $netc->{NET_DEVICE}
), $netcnx->{type});
    1;
}

sub configure_lan {
    my ($netcnx, $netc, $intf, $first_time) = @_;
    $::isInstall and $in->set_help('configureNetworkIP');
    configureNetwork($netc, $intf, $first_time) or return;
    configureNetwork2($in, $prefix, $netc, $intf);
    $netc->{NETWORKING} = "yes";
    if ($netc->{GATEWAY} || grep { $_->{BOOTPROTO} eq 'dhcp' } values %$intf) {
	$netcnx->{type}='lan';
	$netcnx->{NET_DEVICE} = $netc->{NET_DEVICE} = '';
	$netcnx->{NET_INTERFACE} = 'lan'; #$netc->{NET_INTERFACE};
        write_cnx_script($netc, "local network",
qq(
/etc/rc.d/init.d/network restart
),
qq(
/etc/rc.d/init.d/network stop
/sbin/ifup lo
), $netcnx->{type});
    }
    $::isStandalone and modules::write_conf($prefix);
    1;
}

sub conf_network_card {
    my ($netc, $intf, $type, $ipadr, $netadr) = @_;
    #-type =static or dhcp
    any::load_category($in, 'network/main|usb', !$::expert, 1);
    my @all_cards = conf_network_card_backend($netc, $intf, $type, undef, $ipadr, $netadr);
    my $interface;
    @all_cards == () and $in->ask_warn('', _("No ethernet network adapter has been detected on your system.
I cannot set up this connection type.")) and return;
    @all_cards == 1 and $interface = $all_cards[0][0] and goto l1;
    again :
	$interface = $in->ask_from_list(_("Choose the network interface"),
					_("Please choose which network adapter you want to use to connect to Internet"),
					[ map { $_->[0] . ($_->[1] ? " (using module $_->[1])" : "") } @all_cards ]
				       ) or return;
    defined $interface or goto again;
  l1:
    $::isStandalone and modules::write_conf($prefix);

    my $device = conf_network_card_backend($netc, $intf, $type, $interface, $ipadr, $netadr, $interface);
#      if ( $::isStandalone and !($type eq "dhcp")) {
#  	$in->ask_yesorno(_("Network interface"),
#  			  _("I'm about to restart the network device:\n") . $device . _("\nDo you agree?"), 1) and configureNetwork2($in, $prefix, $netc, $intf) and system("$prefix/sbin/ifdown $device;$prefix/sbin/ifup $device");
#      }
    1;
}

#- conf_network_card_backend : configure the network cards and return the list of them, or configure one specified interface : WARNING, you have to setup the ethernet cards, by calling load_category($in, 'network/main|usb', !$::expert, 1) or load_category_backend before calling this function. Basically, you call this function in 2 times.
#- input
#-  $prefix
#-  $netc
#-  $intf
#-  $type : type of interface, must be given if $interface is : string : "static" or "dhcp"
#-  $interface : facultative, if given, set this interface and return it in a proper form. If not, return @all_cards
#-  $ipadr : facultative, ip address of the interface : string
#-  $netadr : facultative, netaddress of the interface : string
#- when $interface is given, informations are written in $intf and $netc. If not, @all_cards is returned.
#- $intf output: $device is the result of
#-  $intf->{$device}->{DEVICE} : which device is concerned : $device is the result of $interface =~ /(eth[0-9]+)/; my $device = $1;;
#-  $intf->{$device}->{BOOTPROTO} : $type
#-  $intf->{$device}->{NETMASK} : '255.255.255.0'
#-  $intf->{$device}->{NETWORK} : $netadr
#-  $intf->{$device}->{ONBOOT} : "yes"
#- $netc output:
#-  $netc->{nb_cards} : nb of ethernet cards
#-  $netc->{NET_DEVICE} : this is used to indicate that this eth card is used to connect to internet : $device
#- output:
#-  $all_cards : a list of a list ( [eth1, module1], ... , [ethn, modulen]). Pass the ethx as $interface in further call.
#-  $device : only returned in case $interface was given it's $interface, but filtered by /eth[0-9+]/ : string : /eth[0-9+]/
sub conf_network_card_backend {
    my ($netc, $intf, $type, $interface, $ipadr, $netadr) = @_;
    #-type =static or dhcp
    if (!$interface) {
	my @all_cards = detect_devices::getNet();
	$netc->{nb_cards} = @all_cards;

	my @devs = detect_devices::pcmcia_probe();
	modules::mergein_conf("$prefix/etc/modules.conf");
	my $saved_driver;
	return map {
	    my $interface = $_;
	    my $a = modules::get_alias($interface);
	    my $b;
	    foreach (@devs) {