File: RcConfig.pm

package info (click to toggle)
systemconfigurator 2.0.10-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 724 kB
  • ctags: 313
  • sloc: perl: 7,423; makefile: 48
file content (134 lines) | stat: -rw-r--r-- 3,290 bytes parent folder | download | duplicates (3)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package Modules::RcConfig;

#   $Id: RcConfig.pm,v 1.6 2003/06/27 21:08:03 sdague Exp $

#   Copyright (c) 2001-2002 International Business Machines

#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
 
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
 
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#   Sean Dague <sean@dague.net>

=head1 NAME

Modules::RcConfig - setup for /etc/rc.config for kernel modules

=head1 SYNOPSIS

 my $aliases = new Modules::RcConfig(%vars);

 if ($aliases->footprint()) {
      $aliases->setup();
 }

 my @fileschanged = $aliases->files();

=head1 DESCRIPTION

=cut

use strict;
use Carp;
use base qw(Modules::Generic);
use Modules::Root;
use Util::FileMod;
use vars qw($VERSION);

$VERSION = sprintf("%d.%02d", q$Revision: 1.6 $ =~ /(\d+)\.(\d+)/);

push @Hardware::conftypes, qw(Modules::RcConfig);

sub new {
    my $class = shift;

    my %vars = @_;

    my %this = (
                _root => $vars{root},
                _postcommand => "/sbin/SuSEconfig",
                _otherfiles => ["$vars{root}/etc/modules.conf"],
                _filesmod => [],
                _configfile => "/etc/rc.config",
               );
    bless \%this, $class;
}

=head1 METHODS

The following methods exist in this module:

=over 4

=item footprint()

This method returns 1 if both B</etc/modutils/aliases> and 
B</sbin/update-modules> exist on the machine.
Otherwise, it returns undef.

=cut

sub footprint {
    my $this = shift;
    my $file = $this->chroot("/etc/rc.config");
    my $file2 = $this->chroot("/sbin/SuSEconfig");
    my $file3 = $this->chroot("/etc/sysconfig/kernel");
    if(-e $file && -e $file2 && !-e $file3) {
        return 1;
    }
    return undef;
}

sub setup {
    my $this = shift;
    my @aliases = @_;
    my @modules = ();
    my $verbose = ($::VERBOSE) ? "" : " 1>/dev/null 2>/dev/null ";
    # first, get all the aliases as per before
    
    foreach my $alias (@aliases) {
        if($alias->[0] =~ /scsi/) {
            push @modules, $alias->[1];
        }
    }
  
    # second get the root fs modules
    
    push @modules, get_root_fs_modules($this->chroot('/etc/fstab'));
 
    if(scalar(@modules)) {
        my $rc = new Util::FileMod(Seperator => '=', Quotes => '"', Comment => '#');
        $rc->add_vars("INITRD_MODULES" => join(' ',@modules));
        $rc->update_file($this->chroot("/etc/rc.config"));
        
        if ($this->root) {
            system("chroot " . $this->root . " " . $this->postcommand . $verbose);
        } else {
            system($this->postcommand . $verbose);
        }
    }
}

=back

=head1 AUTHOR

  Sean Dague <sean@dague.net>

=head1 SEE ALSO

L<SystemConifg::Hardware>, L<Util::FileMod>, L<perl>

=cut

1;