| 1 |
package Dahdi::Config::Gen::Assignedspans; |
| 2 |
use strict; |
| 3 |
|
| 4 |
use Dahdi::Config::Gen qw(is_true); |
| 5 |
|
| 6 |
sub new($$$) { |
| 7 |
my $pack = shift || die; |
| 8 |
my $gconfig = shift || die; |
| 9 |
my $genopts = shift || die; |
| 10 |
my $file = $ENV{ASSIGNED_SPANS_CONF_FILE} || "/etc/dahdi/assigned-spans.conf"; |
| 11 |
my $self = { |
| 12 |
FILE => $file, |
| 13 |
GCONFIG => $gconfig, |
| 14 |
GENOPTS => $genopts, |
| 15 |
}; |
| 16 |
bless $self, $pack; |
| 17 |
return $self; |
| 18 |
} |
| 19 |
|
| 20 |
sub generate($$$) { |
| 21 |
my $self = shift || die; |
| 22 |
my $file = $self->{FILE}; |
| 23 |
my $gconfig = $self->{GCONFIG}; |
| 24 |
my $genopts = $self->{GENOPTS}; |
| 25 |
my @spans = @_; |
| 26 |
|
| 27 |
# If the span_types utilities were not installed we do not want to run |
| 28 |
# this generator or report any errors. |
| 29 |
system "which dahdi_span_assignments > /dev/null 2>&1"; |
| 30 |
return if $?; |
| 31 |
|
| 32 |
warn "Empty configuration -- no spans\n" unless @spans; |
| 33 |
rename "$file", "$file.bak" |
| 34 |
or $! == 2 # ENOENT (No dependency on Errno.pm) |
| 35 |
or die "Failed to backup old config: $!\n"; |
| 36 |
#$gconfig->dump; |
| 37 |
print "Generating $file\n" if $genopts->{verbose}; |
| 38 |
my $cmd = "dahdi_span_assignments dumpconfig > $file"; |
| 39 |
system $cmd; |
| 40 |
die "Command failed (status=$?): '$cmd'" if $?; |
| 41 |
} |
| 42 |
|
| 43 |
1; |
| 44 |
|
| 45 |
__END__ |
| 46 |
|
| 47 |
=head1 NAME |
| 48 |
|
| 49 |
dahdi - Generate configuration for dahdi drivers. |
| 50 |
|
| 51 |
=head1 SYNOPSIS |
| 52 |
|
| 53 |
use Dahdi::Config::Gen::Dahdi; |
| 54 |
|
| 55 |
my $cfg = new Dahdi::Config::Gen::Dahdi(\%global_config, \%genopts); |
| 56 |
$cfg->generate(@span_list); |
| 57 |
|
| 58 |
=head1 DESCRIPTION |
| 59 |
|
| 60 |
Generate the F</etc/dahdi/assigned-spans.conf>. |
| 61 |
This is the configuration for dahdi_span_assignments. |
| 62 |
|
| 63 |
Its location may be overriden via the environment variable F<ASSIGNED_SPANS_CONF_FILE>. |