diff options
Diffstat (limited to 'perl-install/standalone/service_harddrake')
| -rwxr-xr-x | perl-install/standalone/service_harddrake | 103 |
1 files changed, 74 insertions, 29 deletions
diff --git a/perl-install/standalone/service_harddrake b/perl-install/standalone/service_harddrake index 1cd03cc43..4069551b6 100755 --- a/perl-install/standalone/service_harddrake +++ b/perl-install/standalone/service_harddrake @@ -10,17 +10,28 @@ use common; use interactive; use detect_devices; use harddrake::data; +use harddrake::autoconf; use harddrake::sound; use modules; use Storable qw(store retrieve); + +my $force = any { $_ eq '--force' } @ARGV; + +my $mode = 'stop' if $ARGV[0] eq 'stop'; + +if ($mode eq 'stop') { + append_to_file('/etc/hotplug/blacklist', "\nsnd-usb-audio\n"); + c::_exit(0); +} + my $invert_do_it = $ARGV[0] eq 'X11' ? 1 : 0; my ($hw_sysconfdir, $timeout) = ("/etc/sysconfig/harddrake2", $invert_do_it ? 600 : 25); -my $last_boot_config = $hw_sysconfdir."/previous_hw"; +my $last_boot_config = "$hw_sysconfdir/previous_hw"; $last_boot_config .= '_X11' if $invert_do_it; -modules::mergein_conf(); +my $modules_conf = modules::any_conf->read; # autoreconfigure the mouse on major kernel change: my $prev_kernel = { getVarsFromSh("$hw_sysconfdir/kernel") }->{KERNEL}; @@ -29,13 +40,14 @@ $curr_kernel =~ s/(^\d+\.\d+).*/$1/; setVarsInSh("$hw_sysconfdir/kernel", { KERNEL => $curr_kernel }); if ($curr_kernel ne $prev_kernel) { log::explanations("Autoconfiguring mouse since we switched between 2.4.x and 2.6.x kernels"); - require class_discard; - require mouse; - mouse::write_conf(class_discard->new, mouse::detect(), 1); + harddrake::autoconf::mouse_conf($modules_conf); } if (find { $_->{driver} =~ /Card:NVIDIA/ } detect_devices::probeall()) { - if (find { -e join('', "/lib/modules/", c::kernel_version(), "/kernel/drivers/$_") } map { ("video/$_", "char/$_") } qw(NVdriver nvidia.o nvidia.o.gz nvidia.ko nvidia.ko.gz)) { + if (find { -e join('', "/lib/modules/", c::kernel_version(), "/kernel/drivers/$_") } map { ("video/$_", "char/$_", "char/drm/$_") } qw(NVdriver nvidia.o nvidia.o.gz nvidia.ko nvidia.ko.gz)) { + # do not automatically switch from nv to nvidia (in order to handle + # cases where nvidia module crashes the system): + # # substInFile { # log::explanations("switch XFree86 driver from nv to nvidia") if /Driver "nv"/; # s!Driver "nv.*"!Driver "nvidia"!g; @@ -45,22 +57,31 @@ if (find { $_->{driver} =~ /Card:NVIDIA/ } detect_devices::probeall()) { substInFile { log::explanations("switch XFree86 driver from nvidia to nv") if /Driver "nv.+"/; s!Driver "nv.*"!Driver "nv"!g; - s!([^#]Load.*glx)!#$1!g; - } $_ foreach "/etc/X11/XF86Config-4", "/etc/X11/XF86Config"; + } $_ foreach grep { -e $_ } "/etc/X11/XF86Config-4", "/etc/X11/XF86Config"; } } my $is_globetrotter = -f '/usr/sbin/mdkmove'; # first run ? if not read old hw config -my $previous_config = -f $last_boot_config && -s $last_boot_config ? Storable::retrieve($last_boot_config) : {}; +my $previous_config; + +if (-f $last_boot_config && -s $last_boot_config) { + eval { $previous_config = Storable::retrieve($last_boot_config) }; + log::explanations("resetting previous harware file ($@)") if $@; +} + +$previous_config ||= {}; + $previous_config = $$previous_config if ref($previous_config) !~ /HASH/; my (%config, $wait); my $in; my $splash = -f '/proc/splash'; +my $splash_was_silent = cat_('/proc/splash') =~ /, silent : on/; + # For each hw, class, detect device, compare and offer to reconfigure if needed foreach my $hw_class (@harddrake::data::tree) { - my ($Ident, $item, $configurator, $detector, $do_it) = @$hw_class{qw(class string configurator_auto detector checked_on_boot)}; + my ($Ident, $item, $configurator, $detector, $do_it) = @$hw_class{qw(class string configurator detector checked_on_boot)}; $configurator ||= $hw_class->{configurator}; next unless $do_it ^ $invert_do_it; @@ -73,7 +94,7 @@ foreach my $hw_class (@harddrake::data::tree) { $id => $i; } eval { &$detector }; $config{$Ident} = \%ID; - next if !$is_globetrotter && is_empty_hash_ref $previous_config; # don't fsck on first run + next if !$is_globetrotter && !$force && is_empty_hash_ref($previous_config); # don't fsck on first run but if --force my $oldconfig = $previous_config->{$Ident}; @@ -89,12 +110,19 @@ foreach my $hw_class (@harddrake::data::tree) { log::explanations("removed $Ident: " . harddrake::data::custom_id($oldconfig->{$_}, $item)) foreach @was_removed; log::explanations("added $Ident: " . harddrake::data::custom_id($ID{$_}, $item)) foreach @added; - modules::load('ohci1394') if $Ident eq 'FIREWIRE_CONTROLLER' && any { $_->{driver} eq 'ohci1394' } @added; + modules::load_and_configure($modules_conf, 'ohci1394') if $Ident eq 'FIREWIRE_CONTROLLER' && any { $_->{driver} eq 'ohci1394' } @added; @added || @was_removed or next; + + if (harddrake::data::is_removable($Ident)) { + modules::load_category('floppy') if $Ident eq 'FLOPPY'; + } + + next if $Ident eq 'MOUSE' && $curr_kernel ne $prev_kernel; + my @configurator_pool; if (harddrake::data::is_removable($Ident)) { foreach my $device (@ID{@added}) { - push @configurator_pool, harddrake::data::set_removable_configurator($Ident, $device); + push @configurator_pool, harddrake::data::set_removable_auto_configurator($Ident, $device); }; foreach my $device (@$oldconfig{@was_removed}) { push @configurator_pool, harddrake::data::set_removable_remover($Ident, $device); @@ -105,30 +133,40 @@ foreach my $hw_class (@harddrake::data::tree) { if ($Ident eq "AUDIO") { # automatic sound slots configuration rm_rf("/etc/asound.state"); - harddrake::sound::configure_sound_slots(); + harddrake::sound::configure_sound_slots($modules_conf); next; } elsif ($Ident eq "ETHERNET") { - modules::remove_alias_regexp('^(wlan|eth)[0-9]*$'); - modules::load_category('network/main|gigabit|usb|wireless'); + $modules_conf->remove_alias_regexp('^(wlan|eth)[0-9]*$'); + modules::load_category($modules_conf, 'network/main|gigabit|usb|wireless|firewire|pcmcia'); require network::ethernet; - network::ethernet::configure_eth_aliases(); - modules::write_conf(); - } elsif ($Ident eq "AGP") { - # add agpgart modules to modprobe.preload if needed: - modules::write_conf(); + network::ethernet::update_iftab(); + network::ethernet::configure_eth_aliases($modules_conf); + $modules_conf->write; + next; + } elsif (member($Ident, qw(AGP ATA_STORAGE SATA_STORAGE SCSI_CONTROLLER TV))) { + # add agpgart and the like modules to modprobe.preload if needed: + $modules_conf->write; + next; + } elsif ($Ident eq "USB_CONTROLLER") { + modules::load_category($modules_conf, 'bus/usb'); + $modules_conf->write; } elsif ($Ident eq "VIDEO") { - require harddrake::autoconf; - harddrake::autoconf::xconf(); + harddrake::autoconf::xconf($modules_conf, {}); + next; + } elsif ($Ident eq "MOUSE") { + harddrake::autoconf::mouse_conf($modules_conf); next; } next if $is_globetrotter && !$hw_class->{automatic}; next unless $configurator_pool[0]; - if (!-x first(split /\s+/, $configurator_pool[0])) { - log::explanations(qw(skip $Ident configuration sincecannot "$configurator" isn't executable)); + if (ref($configurator) ne 'CODE' && !-x first(split /\s+/, $configurator_pool[0])) { + log::explanations(qw(skip $Ident configuration since "$configurator" isn't executable)); next; } my ($pid, $no, $res); + $hw_class->{automatic} ||= ref($configurator) eq 'CODE'; + if (!$hw_class->{automatic}) { $SIG{ALRM} = sub { $no = 1; kill 15, $pid }; unless ($pid = fork()) { @@ -142,13 +180,17 @@ foreach my $hw_class (@harddrake::data::tree) { } else { $res = 1; } - if (!$no && $res) { - foreach my $configurator (@configurator_pool) { + if (ref($configurator) eq 'CODE') { + eval { $configurator->() }; + log::explanations(qw(cannot run "$configurator": $@)) if $@; + } elsif (!$no && $res) { + foreach my $program (@configurator_pool) { if (fork()) { wait(); } else { - exec("$configurator 2>/dev/null") or do { - log::explanations(qw(cannot run "$configurator")); + log::explanations(qq(run "$program")); + exec("$program 2>/dev/null") or do { + log::explanations(qq(cannot run "$program")); require POSIX; POSIX::_exit(); }; @@ -168,5 +210,8 @@ foreach my $hw_class (@harddrake::data::tree) { log::explanations("created file $last_boot_config"); Storable::store(\%config, $last_boot_config); +# restore bootsplash mode +$splash_was_silent and eval { output('/proc/splash', 'silent') }; + $in->exit(0) if $in; |
