diff options
author | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2009-04-01 10:50:29 +0000 |
---|---|---|
committer | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2009-04-01 10:50:29 +0000 |
commit | 40dd2c5abcaca93975deb1517827c48f2dab4c20 (patch) | |
tree | 8bc8a22686fbba41add9a44264020612af2ae808 /xpp/perl_modules/Dahdi/Config | |
parent | 67bec8d54ca5b16edf0fb1cc6a8889aa132fe0f9 (diff) |
Implement 'dahdi_genconf modules' (generate /etc/dahdi/modules)
git-svn-id: http://svn.asterisk.org/svn/dahdi/tools/trunk@6278 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'xpp/perl_modules/Dahdi/Config')
-rw-r--r-- | xpp/perl_modules/Dahdi/Config/Gen/Modules.pm | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/xpp/perl_modules/Dahdi/Config/Gen/Modules.pm b/xpp/perl_modules/Dahdi/Config/Gen/Modules.pm new file mode 100644 index 0000000..c00e3eb --- /dev/null +++ b/xpp/perl_modules/Dahdi/Config/Gen/Modules.pm @@ -0,0 +1,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>. |