summaryrefslogtreecommitdiffstats
path: root/perl-install/modules/any_conf.pm
blob: 10d21e712e2d134509c4e1a8302ccf788b4c26c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
package modules::any_conf;

use log;
use common;


sub vnew {
    if (0 && c::kernel_version() =~ /^\Q2.6/) {
	require modules::modprobe_conf;
	modules::modprobe_conf->new;
    } else {
	require modules::modules_conf;
	modules::modules_conf->new;
    }    
}


sub new {
    my ($type) = @_;
    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;
}

sub get_alias {
    my ($conf, $alias) = @_;
    $conf->{$alias}{alias};
}
sub get_options {
    my ($conf, $name) = @_;
    $conf->{$name}{options};
}
sub set_options {
    my ($conf, $name, $new_option) = @_;
    log::l(qq(set option "$new_option" for module "$name"));
    $conf->{$name}{options} = $new_option;
}
sub get_parameters {
    my ($conf, $name) = @_;
    map { if_(/(.*)=(.*)/, $1 => $2) } split(' ', $conf->get_options($name));
}


sub set_alias { 
    my ($conf, $alias, $module) = @_;
    $module =~ /ignore/ and return;
    /\Q$alias/ && $conf->{$_}{alias} && $conf->{$_}{alias} eq $module and return $_ foreach keys %$conf;
    log::l("adding alias $alias to $module");
    $conf->{$alias}{alias} = $module;
    $alias;
}


sub remove_alias {
    my ($conf, $name) = @_;
    log::l(qq(removing alias "$name"));
    $conf->remove_alias_regexp("^$name\$");
}

sub remove_alias_regexp {
    my ($conf, $aliased) = @_;
    log::l(qq(removing all aliases that match "$aliased"));
    foreach (keys %$conf) {
        delete $conf->{$_}{alias} if /$aliased/;
    }
}

sub remove_alias_regexp_byname {
    my ($conf, $name) = @_;
    log::l(qq(removing all aliases which names match "$name"));
    foreach (keys %$conf) {
        delete $conf->{$_} if /$name/;
    }
}

sub remove_module {
    my ($conf, $name) = @_;
    $conf->remove_alias($name);
    log::l("removing module $name");
    delete $conf->{$name};
    0;
}

sub set_sound_slot {
    my ($conf, $alias, $module) = @_;
    if (my $old = $conf->get_alias($alias)) {
	$conf->remove_above($old);
    }
    $conf->set_alias($alias, $module);
    $conf->set_above($module, 'snd-pcm-oss') if $module =~ /^snd-/;
}

1;