build: remove autoconf generated files
[dahdi/tools.git] / dahdi_span_types
index 9fa3ff1..4154772 100755 (executable)
@@ -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
@@ -150,7 +166,7 @@ fi
 
 # Beware of special characters in attributes
 attr_clean() {
-       cat "$1" | tr -d '\n' | tr '!' '/' | tr -c 'a-zA-Z0-9/:.-' '_'
+       cat "$1" 2>/dev/null | tr -d '\n' | tr '!' '/' | tr -c 'a-zA-Z0-9/:.-' '_'
 }
 
 show_spantypes() {
@@ -172,13 +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"
+       echo "#"
+
+       echo "# Summary:"
+       if [ "$DEFAULT_LINE_MODE" != '' ]; then
+               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\n"
-       printf "$fmt" '# @location/hardware_id' 'span_type'
+
+       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`
@@ -195,14 +255,18 @@ dump_config() {
                cat "$device/spantype" | while read st; do
                        case "$st" in
                        *:[ETJ]1)
-                               printf "$fmt" "$id" "$st"
+                               if [ "$num_spantypes" -eq 1 ]; then
+                                       printf "#$fmt\n" "$id" "$st"
+                               else
+                                       printf "$fmt\n" "$id" "$st"
+                               fi
                                ;;
                        *)
                                #echo "#    Skipped local span `echo $st | sed 's/:/ -- /'`"
                                ;;
                        esac
                done | sort -n
-               #echo ''
+               echo ''
        done
 }