diff --git a/dahdi_span_types b/dahdi_span_types index 85204d8..4154772 100755 --- a/dahdi_span_types +++ b/dahdi_span_types @@ -188,28 +188,57 @@ show_spantypes() { done } +list_pri_spantypes() { + find $DEVICES -follow -maxdepth 1 -name spantype | \ + xargs cat | \ + sed -n '/:[ETJ]1$/s/^.*://p' | \ + sort -u | \ + tr '\n' ' ' | \ + sed -e 's/^ *//' -e 's/ *$//' +} + dump_config() { + pri_spantypes=`list_pri_spantypes` + num_spantypes=`echo "$pri_spantypes" | wc -w` + gen_default='' 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' + echo "#" + echo "# Summary:" 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." + gen_default="$DEFAULT_LINE_MODE" + echo "# * Generating wildcard match of $gen_default." + echo "# - Was run with '--line-mode=$DEFAULT_LINE_MODE'" + elif [ "$num_spantypes" -eq 1 ]; then + gen_default="$pri_spantypes" + echo "# * Generating wildcard match of $gen_default." + echo "# - Spans were $pri_spantypes" + else + echo "# * Not generating wildcard match." + echo "# - Was run without '--line-mode' option and span were of mixed types [$pri_spantypes]" + fi + echo "#" + if [ "$num_spantypes" -eq 1 ]; then + echo "# * Generating a list of commented out configurations for spans." + echo "# - Spans were $pri_spantypes" + echo "# - Uncomment for specific overrides" + else + echo "# * Generating a list of specific span configurations." + echo "# - Spans were of mixed types: $pri_spantypes" + fi + echo "#" + echo '' + + fmt="%-65s %s" + printf "$fmt\n" '# @location/hardware_id' 'span_type' + + if [ "$gen_default" != '' ]; then + printf "$fmt\t\t# Wildcard line-mode" "*" "*:$gen_default" echo "" fi + echo "" for device in $DEVICES do devpath=`cd "$device" && pwd -P` @@ -226,10 +255,10 @@ dump_config() { cat "$device/spantype" | while read st; do case "$st" in *:[ETJ]1) - if [ "$DEFAULT_LINE_MODE" != '' ]; then - printf "#$fmt" "$id" "$st" + if [ "$num_spantypes" -eq 1 ]; then + printf "#$fmt\n" "$id" "$st" else - printf "$fmt" "$id" "$st" + printf "$fmt\n" "$id" "$st" fi ;; *) @@ -237,7 +266,7 @@ dump_config() { ;; esac done | sort -n - #echo '' + echo '' done }