diff options
Diffstat (limited to 'perl-install/modules/any_conf.pm')
-rw-r--r-- | perl-install/modules/any_conf.pm | 122 |
1 files changed, 99 insertions, 23 deletions
diff --git a/perl-install/modules/any_conf.pm b/perl-install/modules/any_conf.pm index 10d21e712..21c8c3eec 100644 --- a/perl-install/modules/any_conf.pm +++ b/perl-install/modules/any_conf.pm @@ -5,7 +5,7 @@ use common; sub vnew { - if (0 && c::kernel_version() =~ /^\Q2.6/) { + if (c::kernel_version() =~ /^\Q2.6/) { require modules::modprobe_conf; modules::modprobe_conf->new; } else { @@ -20,27 +20,6 @@ sub new { bless {}, ref($type) || $type; } -sub read { - my ($_type, $o_file) = @_; - - my $conf = vnew(); - my $raw_conf = modules::read_conf($o_file || "$::prefix/etc/modules.conf"); - foreach my $key (keys %$raw_conf) { - my $raw = $raw_conf->{$key}; - my $keep = $conf->{$key} = {}; - $keep->{alias} ||= $raw->{alias}; - $keep->{above} ||= $raw->{above}; - $keep->{options} = $raw->{options} if $raw->{options}; - push @{$keep->{probeall} ||= []}, deref($raw->{probeall}) if $raw->{probeall}; - } - $conf; -} - -sub write { - my ($conf) = @_; - modules::write_conf($conf); -} - sub modules { my ($conf) = @_; keys %$conf; @@ -64,6 +43,25 @@ sub get_parameters { map { if_(/(.*)=(.*)/, $1 => $2) } split(' ', $conf->get_options($name)); } +sub get_probeall { + my ($conf, $alias) = @_; + $conf->{$alias}{probeall}; +} +sub set_probeall { + my ($conf, $alias, $modules) = @_; + $conf->{$alias}{probeall} = $modules; + log::l("setting probeall $alias to $modules"); +} +sub add_probeall { + my ($conf, $alias, $module) = @_; + my $modules = join(' ', uniq(split(' ', $conf->{$alias}{probeall}), $module)); + set_probeall($conf, $alias, $modules); +} +sub remove_probeall { + my ($conf, $alias, $module) = @_; + my $modules = join(' ', grep { $_ ne $module } split(' ', $conf->{$alias}{probeall})); + set_probeall($conf, $alias, $modules); +} sub set_alias { my ($conf, $alias, $module) = @_; @@ -108,10 +106,88 @@ sub remove_module { sub set_sound_slot { my ($conf, $alias, $module) = @_; if (my $old = $conf->get_alias($alias)) { - $conf->remove_above($old); + $conf->set_above($old, undef); } $conf->set_alias($alias, $module); $conf->set_above($module, 'snd-pcm-oss') if $module =~ /^snd-/; } + +sub read { + my ($type, $o_file) = @_; + + my $conf = modules::any_conf::vnew(); + my $raw_conf = modules::any_conf::read_raw($o_file || $::prefix . $conf->file); + + foreach my $module (keys %$raw_conf) { + my $raw = $raw_conf->{$module}; + my $keep = $conf->{$module} = {}; + foreach ($conf->handled_fields) { + $keep->{$_} = $raw->{$_} if $raw->{$_}; + } + } + + $conf; +} + +sub write { + my ($conf, $o_file) = @_; + my $file = $o_file || $::prefix . $conf->file; + + my %written; + + #- Substitute new config (if config has changed) + substInFile { + my ($type, $module, $val) = split(' ', chomp_($_), 3); + if ($type eq 'post-install' && $module eq 'supermount') { + #- remove the post-install supermount stuff. + $_ = ''; + } elsif (member($type, $conf->handled_fields)) { + my $new_val = $conf->{$module}{$type}; + if (!$new_val) { + $_ = ''; + } elsif ($new_val ne $val) { + $_ = "$type $module $new_val\n"; + } + } + $written{$module}{$type} = 1; + } $file; + + my $to_add; + while (my ($module, $h) = each %$conf) { + while (my ($type, $v) = each %$h) { + $to_add .= "$type $module $v\n" if $v && !$written{$module}{$type}; + } + } + append_to_file($file, $to_add); + + modules::write_preload_conf($conf); +} + + + + +################################################################################ +sub read_raw { + my ($file) = @_; + my %c; + + foreach (cat_($file)) { + next if /^\s*#/; + s/#.*$//; + s/\s+$//; + + s/\b(snd-card-)/snd-/g; + s/\b(snd-via686|snd-via8233)\b/snd-via82xx/g; + + my ($type, $module, $val) = split(' ', $_, 3) or next; + + $c{$module}{$type} = $val; + } + + #- NB: not copying alias options to the module anymore, hopefully not useful :) + + \%c; +} + 1; |