dahdi_span_types: compare
This adds an extra subcommand: compare: shows span that have been configured (in /etc/dahdi/span_types.conf) to a different value than the one currently active on the system. Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
This commit is contained in:
parent
55679791b5
commit
9631938e90
@ -48,7 +48,7 @@ __dahdi_span_types() {
|
||||
has_cmd=0
|
||||
for (( i=0; i < COMP_CWORD; i++)); do
|
||||
case "${COMP_WORDS[$i]}" in
|
||||
dumpconfig | list | set)
|
||||
dumpconfig | list | set | compare)
|
||||
has_cmd=1
|
||||
break
|
||||
;;
|
||||
@ -69,7 +69,7 @@ __dahdi_span_types() {
|
||||
grep -l '[EJT]1' /sys/devices/pci0000:00/0000:00:10.4/usb1/1-1/xbus-00/*/spantype 2>/dev/null | sed -e 's|/spantype||') )
|
||||
else
|
||||
COMPREPLY=( ${COMPREPLY[@]} $(compgen -W \
|
||||
'dumpconfig list set' -- $cur) )
|
||||
'dumpconfig list set compare' -- $cur) )
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
@ -69,6 +69,7 @@ usage() {
|
||||
echo >&2 "Usage: $0 [options] action [devpath ...]"
|
||||
echo >&2 " action:"
|
||||
echo >&2 " set - set spans to E1/T1 according to /etc/dahdi/span-types.conf"
|
||||
echo >&2 " compare - show config values that differ from system"
|
||||
echo >&2 " list - human-readable list of all spans"
|
||||
echo >&2 " dumpconfig - dump current state in /etc/dahdi/span-types.conf format"
|
||||
echo >&2 ""
|
||||
@ -88,6 +89,8 @@ if [ $? != 0 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
compare=false
|
||||
|
||||
# Note the quotes around `$TEMP': they are essential!
|
||||
eval set -- "$TEMP"
|
||||
|
||||
@ -321,13 +324,26 @@ handle_span() {
|
||||
echo >&2 "Set $devname span $spanno = $val"
|
||||
fi
|
||||
if [ "$dry_run" != 'true' ]; then
|
||||
if [ "$compare" = 'true' ]; then
|
||||
config="$spanno:$val"
|
||||
system=`grep "$spanno:" "$attr_file"`
|
||||
if [ "$config" != "$system" ]; then
|
||||
|
||||
active_val=`echo $system | cut -d: -f2`
|
||||
echo "$devname $spanno $val $active_val" >>"$compare_results_file"
|
||||
fi
|
||||
else
|
||||
echo "$spanno:$val" > "$attr_file"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
set_all_devices() {
|
||||
span_differs='false'
|
||||
SPANS_DIFFER='false'
|
||||
|
||||
if [ ! -f "$DAHDISPANTYPESCONF" ]; then
|
||||
echo >&2 "$0: Missing configuration '$DAHDISPANTYPESCONF'"
|
||||
exit 1
|
||||
@ -348,6 +364,16 @@ set_all_devices() {
|
||||
esac
|
||||
done
|
||||
done
|
||||
if [ "$compare" = 'true' ]; then
|
||||
if [ -s "$compare_results_file" ]; then
|
||||
echo "# Device Unit Config Active"
|
||||
cat "$compare_results_file"
|
||||
rm -f "$compare_results_file"
|
||||
exit 5
|
||||
fi
|
||||
rm -f "$compare_results_file"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
case "$action" in
|
||||
@ -360,6 +386,11 @@ dumpconfig)
|
||||
set)
|
||||
set_all_devices
|
||||
;;
|
||||
compare)
|
||||
compare=true
|
||||
compare_results_file=`mktemp`
|
||||
set_all_devices
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
|
@ -4,7 +4,7 @@
|
||||
dahdi_span_types \- set line modes of DAHDI spans before assignment
|
||||
.SH SYNOPSIS
|
||||
|
||||
.B dahdi_span_types [\fIoptions\fB] <list|dumpconfig|set> \fB[\fIdevpath \fB...]
|
||||
.B dahdi_span_types [\fIoptions\fB] <list|dumpconfig|compare|set> \fB[\fIdevpath \fB...]
|
||||
|
||||
.SH DESCRIPTION
|
||||
The span type (the line mode: E1/T1/J1) must be set to a span before
|
||||
@ -58,6 +58,16 @@ device(s) specified in the command line (or all devices, if none
|
||||
specified).
|
||||
.RE
|
||||
|
||||
.B compare
|
||||
.RS
|
||||
Compare the settings on the system to those in the configuration file.
|
||||
For each line that applies to a device on the system, print it if the
|
||||
value to be set and the active value on the system differ.
|
||||
|
||||
The exit status is 0 if there is no difference and non-zero if a
|
||||
difference was detected.
|
||||
.RE
|
||||
|
||||
.B list
|
||||
.RS
|
||||
List line modes for all spans in the system which may be set with
|
||||
|
Loading…
Reference in New Issue
Block a user