summaryrefslogtreecommitdiff
path: root/xpp/perl_modules/Dahdi/Config/Gen/Modules.pm
blob: c00e3ebc8fd286460d63bb0829231596a0ce221e (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
package Dahdi::Config::Gen::Modules;
use strict;

use Dahdi::Config::Gen qw(is_true);

sub new($$$) {
	my $pack = shift || die;
	my $gconfig = shift || die;
	my $genopts = shift || die;
	my $file = $ENV{DAHDI_MODULES_FILE} || "/etc/dahdi/modules";
	my $self = {
			FILE	=> $file,
			GCONFIG	=> $gconfig,
			GENOPTS	=> $genopts,
		};
	bless $self, $pack;
	return $self;
}

sub generate($$$) {
	my $self = shift || die;
	my $file = $self->{FILE};
	my $gconfig = $self->{GCONFIG};
	my $genopts = $self->{GENOPTS};
	rename "$file", "$file.bak"
		or $! == 2	# ENOENT (No dependency on Errno.pm)
		or die "Failed to backup old config: $!\n";
	#$gconfig->dump;
	print "Generating $file\n" if $genopts->{verbose};
	open(F, ">$file") || die "$0: Failed to open $file: $!\n";
	my $old = select F;
	printf "# Autogenerated by $0 (%s) on %s\n", __PACKAGE__, scalar(localtime);
	print  "# If you edit this file and execute $0 again,\n";
	print  "# your manual changes will be LOST.\n";
	my @drivers = Dahdi::Hardware->drivers;
	print join("\n", @drivers),"\n";
	close F;
	select $old;
}

1;

__END__

=head1 NAME

modules - Generate list of dahdi drivers to load at startup

=head1 SYNOPSIS

 use Dahdi::Config::Gen::Dahdi;

 my $cfg = new Dahdi::Config::Gen::Modules(\%global_config, \%genopts);
 $cfg->generate(@span_list);

=head1 DESCRIPTION

Generate the F</etc/dahdi/modules>. This is a list of modules, one per
line. This list is normally used by F</etc/init.d/dahdi>.

Its location may be overriden via the environment variable
F<DAHDI_MODULES_FILE>.