Change span-type.conf generation policy

* Add '--line-mode=<E1|T1|J1>' option to dahdi_span_types:
  - Will first generate a wildcard entry (* *:<type>)
  - All later entries will be commented-out.
  - Manually uncommenting any of them will create an "override"
    (e.g: mixed system with all spans T1, but some E1)

* Now dahdi_genconf does not generate span-types.conf by default:
  - Added '--line-mode=<E1|T1|J1>' option to trigger generation
  - This parameter will be passed to "dahdi_span_types dumpconfig"
  - Also explicit specification of 'spantypes' as an argument will
    trigger a similar generation (with a default of 'E1').
  - The line-mode may also be passed to the generator directly
    with identical results. Example:
          dahdi_genconf spantypes=line-mode=T1

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
Acked-By: Russ Meyerriecks <rmeyerriecks@digium.com>
This commit is contained in:
Oron Peled 2014-01-20 20:10:56 +02:00 committed by Tzafrir Cohen
parent 451a8b4d6f
commit b621c02b7f
4 changed files with 116 additions and 10 deletions

View File

@ -77,11 +77,12 @@ usage() {
echo >&2 " -v|--verbose' - Show debugging messages (on stderr)"
echo >&2 " -n|--dry-run' - During 'set', only show what would be done"
echo >&2 " -k|--key <k> - Override prefered key during dumpconfig action"
echo >&2 " --line-mode <m> - Set default line mode to <m> (E1/T1/J1)"
exit 1
}
# Parse command line options
TEMP=`getopt -o hnvk: --long help,dry-run,verbose,key: -n "$0" -- "$@"`
TEMP=`getopt -o hnvk: --long help,dry-run,verbose,key:,line-mode: -n "$0" -- "$@"`
if [ $? != 0 ]; then
echo >&2 "Bad options"
usage
@ -108,6 +109,11 @@ while true ; do
shift
shift
;;
--line-mode)
DEFAULT_LINE_MODE="$2"
shift
shift
;;
--)
shift
break
@ -131,7 +137,17 @@ case "$SPAN_ASSIGNMENTS_KEY" in
hwid|location|devpath)
;;
*)
echo >&2 "Bad SPAN_ASSIGNMENTS_KEY='$SPAN_ASSIGNMENTS_KEY' (should be: hwid|location|devpath)"
echo >&2 "Bad --key='$SPAN_ASSIGNMENTS_KEY' (should be: hwid|location|devpath)"
usage
;;
esac
# Validate DEFAULT_LINE_MODE
case "$DEFAULT_LINE_MODE" in
E1|T1|J1|'')
;;
*)
echo >&2 "Bad --line-mode='$DEFAULT_LINE_MODE' (should be: E1|T1|J1)"
usage
;;
esac
@ -176,9 +192,24 @@ dump_config() {
echo '#'
echo "# Autogenerated by $0 on `date`"
echo "# Map PRI DAHDI devices to span types for E1/T1/J1"
if [ "$DEFAULT_LINE_MODE" != '' ]; then
echo "# Was run with '--line-mode=$DEFAULT_LINE_MODE' -- so will:"
echo "# * Generate default wildcard entry"
echo "# * Generate commented-out device list (for overrides)"
fi
echo ''
fmt="%-65s %s\n"
printf "$fmt" '# @location/hardware_id' 'span_type'
if [ "$DEFAULT_LINE_MODE" != '' ]; then
echo ""
echo "# Wildcard line-mode $DEFAULT_LINE_MODE".
printf "$fmt" "*" "*:$DEFAULT_LINE_MODE"
echo ""
echo "# A list of commented out configurations for spans."
echo "# Each item may be un-commented to provide an override."
echo ""
fi
for device in $DEVICES
do
devpath=`cd "$device" && pwd -P`
@ -195,7 +226,11 @@ dump_config() {
cat "$device/spantype" | while read st; do
case "$st" in
*:[ETJ]1)
printf "$fmt" "$id" "$st"
if [ "$DEFAULT_LINE_MODE" != '' ]; then
printf "#$fmt" "$id" "$st"
else
printf "$fmt" "$id" "$st"
fi
;;
*)
#echo "# Skipped local span `echo $st | sed 's/:/ -- /'`"

View File

@ -40,6 +40,16 @@ changing anything.
During \fB"set"\fR operation, show the actions that are being performed.
.RE
.BI \-\-line\-mode= <E1|T1|J1>
.RS
During \fB"dumpconfig"\fR operation, force special generation mode:
.IP \(bu 3
First, generates a "wildcard" entry with the fiven \fBline\-mode\fR.
.IP \(bu 3
Comment out all span entries. Each of them may be manually un-commented
to override the "wildcard".
.RE
.SH SUB-COMMANDS
.B set
.RS

View File

@ -11,17 +11,30 @@ use strict;
use File::Basename;
BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/perl_modules"); }
use Getopt::Std;
use Getopt::Long;
use Dahdi;
use Dahdi::Xpp;
use Dahdi::Config::Gen;
use Dahdi::Config::Params;
Getopt::Long::Configure ("bundling");
my $version = '1'; # Functionality version (integer)
my $revision = '$Revision$';
my %opts;
sub usage {
warn "Usage: $0 [options] <generators>\n";
warn " Options:\n";
warn " --line-mode=<E1|T1|J1> - Also generate span-types.conf with default line mode\n";
warn " -F|--freepbx - Modify configuration for Freepbx (skip FXS channels)\n";
warn " -v|--verbose - Be versbose, show generated files\n";
warn " -V|--version - Show version and exit\n";
warn " -h|--help - Show this message\n";
exit 1;
}
sub set_defaults {
my $default_file = $ENV{GENCONF_PARAMETERS} || "/etc/dahdi/genconf_parameters";
my $params = Dahdi::Config::Params->new($default_file);
@ -44,12 +57,24 @@ sub spans_prep($@) {
}
}
sub munge_spantypes {
if ($opts{'line-mode'}) {
print "Will generate span-types.conf with line-mode=$opts{'line-mode'}\n"
if $opts{'verbose'};
return "spantypes=line-mode=$opts{'line-mode'}";
} else {
print "Will generate span-types.conf\n" if $opts{'verbose'};
return "spantypes";
}
}
sub generator_list($) {
my $gconfig = shift || die;
my @genlist;
if (@ARGV) {
for my $gen (@ARGV) {
$gen = munge_spantypes() if $gen eq 'spantypes';
push @genlist, $gen;
}
} else {
@ -58,6 +83,7 @@ sub generator_list($) {
if($gconfig->{'pri_connection_type'} eq 'R2') {
push @genlist, 'unicall';
}
push(@genlist, munge_spantypes()) if $opts{'line-mode'};
}
return @genlist;
}
@ -93,7 +119,16 @@ sub generate_files($@) {
}
}
getopts('vVF', \%opts) || die "$0: Bad option\n";
GetOptions(\%opts,
"line-mode=s",
"h|help",
"v|verbose",
"V|version",
"F|freepbx",
) or usage;
usage if $opts{h};
if($opts{'V'}) {
my $revstr = $revision;
$revstr =~ s/[^$]*\$[^:]+:\s*//;
@ -156,19 +191,27 @@ a comma separated list of options to the generator name. E.g:
=over 4
=item -V
=item -V --version
Version -- print version string and exit.
=item -v
=item -v --verbose
Verbose -- sets the C<'verbose'> option for all generators.
=item -F
=item -F --freepbx
Freepbx -- sets the C<'freepbx'> option for all generators.
Currently, chandahdi is affected.
=item --line-mode=I<mode>
I<mode> may be E1, J1 or T1.
Enables the generator B<spantypes> and the option B<line-mode> to it.
(Equivalent to the option C<--line-mode> to C<dahdi_span_types>). This
will generate a C<span-types.conf> file with a single wildcard line
setting the line mode to I<mode>.
=back

View File

@ -29,13 +29,17 @@ sub generate($$$) {
system "which dahdi_span_types > /dev/null 2>&1";
return if $?;
my $line_mode = $genopts->{'line-mode'};
$line_mode = 'E1' unless defined $line_mode;
$line_mode =~ /^[ETJ]1$/ or die "Bad line-mode='$line_mode'\n";
warn "Empty configuration -- no spans\n" unless @spans;
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};
my $cmd = "dahdi_span_types dumpconfig > $file";
printf("Generating $file (with default line-mode %s)\n", $line_mode)
if $genopts->{verbose};
my $cmd = "dahdi_span_types --line-mode=$line_mode dumpconfig > $file";
system $cmd;
die "Command failed (status=$?): '$cmd'" if $?;
}
@ -61,3 +65,17 @@ Generate the F</etc/dahdi/span-types.conf>.
This is the configuration for dahdi_span_types.
Its location may be overriden via the environment variable F<SPAN_TYPES_CONF_FILE>.
You would normally run:
dahdi_genconf --line-mode=<line_mode>
which is a short for:
dahdi_genconf spantypes=line-mode=<line_mode>
This is done by running:
dahdi_span_types dumpconfig --line-mode=line_mode>
where I<line_mode> is the module parameter, and defaults to B<E1> if not
given (running C<dahdi_genconf spantypes>).