improved dahdi_span_types dumpconfig
* Better defaults: - A wildcard match: - If '--line-mode' option is given, generate a wildcard entry. (existing behavior). - Otherwise, if *all spans* are of the same type (E1/T1), generate a wildcard entry for this type. This is the most common use-case and now it work without any command line flags. - Otherwise (mixed E1/T1 spans), do not generate a wildcard entry. This isn't common case (except from our labs), but regardless without '--line-mode' any guess could be wrong. - Specific device matches: - If all spans are of the same type, generate commented out specific entries (for manual overrides). - If spans have mixed E1/T1 types, generate specific entries In this case, specific entries MUST NOT be commented out otherwise, the configuration file is wrong! * Generated header with better organization: - Shows what is generated: - Generating wildcard / Not generating wildcard - Generating specific lines / Generating *commented-out* specific lines - For each decision, show *why* it was taken. Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com> Acked-by: Russ Meyerriecks <rmeyerriecks@digium.com>
This commit is contained in:
parent
1292ea9078
commit
f2628eeedd
|
@ -188,28 +188,57 @@ show_spantypes() {
|
||||||
done
|
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() {
|
dump_config() {
|
||||||
|
pri_spantypes=`list_pri_spantypes`
|
||||||
|
num_spantypes=`echo "$pri_spantypes" | wc -w`
|
||||||
|
gen_default=''
|
||||||
echo '#'
|
echo '#'
|
||||||
echo "# Autogenerated by $0 on `date`"
|
echo "# Autogenerated by $0 on `date`"
|
||||||
echo "# Map PRI DAHDI devices to span types for E1/T1/J1"
|
echo "# Map PRI DAHDI devices to span types for E1/T1/J1"
|
||||||
if [ "$DEFAULT_LINE_MODE" != '' ]; then
|
echo "#"
|
||||||
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 "# Summary:"
|
||||||
if [ "$DEFAULT_LINE_MODE" != '' ]; then
|
if [ "$DEFAULT_LINE_MODE" != '' ]; then
|
||||||
echo ""
|
gen_default="$DEFAULT_LINE_MODE"
|
||||||
echo "# Wildcard line-mode $DEFAULT_LINE_MODE".
|
echo "# * Generating wildcard match of $gen_default."
|
||||||
printf "$fmt" "*" "*:$DEFAULT_LINE_MODE"
|
echo "# - Was run with '--line-mode=$DEFAULT_LINE_MODE'"
|
||||||
echo ""
|
elif [ "$num_spantypes" -eq 1 ]; then
|
||||||
echo "# A list of commented out configurations for spans."
|
gen_default="$pri_spantypes"
|
||||||
echo "# Each item may be un-commented to provide an override."
|
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 ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
|
echo ""
|
||||||
for device in $DEVICES
|
for device in $DEVICES
|
||||||
do
|
do
|
||||||
devpath=`cd "$device" && pwd -P`
|
devpath=`cd "$device" && pwd -P`
|
||||||
|
@ -226,10 +255,10 @@ dump_config() {
|
||||||
cat "$device/spantype" | while read st; do
|
cat "$device/spantype" | while read st; do
|
||||||
case "$st" in
|
case "$st" in
|
||||||
*:[ETJ]1)
|
*:[ETJ]1)
|
||||||
if [ "$DEFAULT_LINE_MODE" != '' ]; then
|
if [ "$num_spantypes" -eq 1 ]; then
|
||||||
printf "#$fmt" "$id" "$st"
|
printf "#$fmt\n" "$id" "$st"
|
||||||
else
|
else
|
||||||
printf "$fmt" "$id" "$st"
|
printf "$fmt\n" "$id" "$st"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
@ -237,7 +266,7 @@ dump_config() {
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done | sort -n
|
done | sort -n
|
||||||
#echo ''
|
echo ''
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue