diff --git a/dahdi_span_types b/dahdi_span_types index 9fa3ff1..38dc347 100755 --- a/dahdi_span_types +++ b/dahdi_span_types @@ -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 - Override prefered key during dumpconfig action" + echo >&2 " --line-mode - Set default line mode to (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/:/ -- /'`" diff --git a/doc/dahdi_span_types.8 b/doc/dahdi_span_types.8 index 4f39bf5..f11054a 100644 --- a/doc/dahdi_span_types.8 +++ b/doc/dahdi_span_types.8 @@ -40,6 +40,16 @@ changing anything. During \fB"set"\fR operation, show the actions that are being performed. .RE +.BI \-\-line\-mode= +.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 diff --git a/xpp/dahdi_genconf b/xpp/dahdi_genconf index a4acfa8..842084d 100755 --- a/xpp/dahdi_genconf +++ b/xpp/dahdi_genconf @@ -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] \n"; + warn " Options:\n"; + warn " --line-mode= - 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 + +I may be E1, J1 or T1. + +Enables the generator B and the option B to it. +(Equivalent to the option C<--line-mode> to C). This +will generate a C file with a single wildcard line +setting the line mode to I. =back diff --git a/xpp/perl_modules/Dahdi/Config/Gen/Spantypes.pm b/xpp/perl_modules/Dahdi/Config/Gen/Spantypes.pm index 6579685..dfa0608 100644 --- a/xpp/perl_modules/Dahdi/Config/Gen/Spantypes.pm +++ b/xpp/perl_modules/Dahdi/Config/Gen/Spantypes.pm @@ -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. This is the configuration for dahdi_span_types. Its location may be overriden via the environment variable F. + +You would normally run: + + dahdi_genconf --line-mode= + +which is a short for: + + dahdi_genconf spantypes=line-mode= + +This is done by running: + dahdi_span_types dumpconfig --line-mode=line_mode> + +where I is the module parameter, and defaults to B if not +given (running C).