Do the Right Thing when there's no config

Do the "right thing" (hopefully. At least for a system with a single
device) if there is are no configuration files:

* No span-types.conf: just ignore it as before. It is optional.
* No pinned-spans.conf: use span_assignments auto (same as having
  dahdi.auto_assign_spans=1).
* No system.conf: generate a temporary one with dahdi_genconf.

This will hopefully allow having a partially-working system, and help
making ut usable with 'span_assignments dumpconfig'. Or maybe just work
as-is.

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
This commit is contained in:
Tzafrir Cohen 2013-10-01 22:13:43 +03:00
parent dc5c7de9fc
commit c1e016fa33
2 changed files with 25 additions and 8 deletions

View File

@ -54,6 +54,9 @@ add)
fi fi
if [ -r "$DAHDICONFDIR/pinned-spans.conf" ]; then if [ -r "$DAHDICONFDIR/pinned-spans.conf" ]; then
span_assignments add "/sys$DEVPATH" span_assignments add "/sys$DEVPATH"
else
# No configuration. No order guaranteed
span_assignments auto
fi fi
) 2>&1 < /dev/null | $LOGGER & ) 2>&1 < /dev/null | $LOGGER &
;; ;;

View File

@ -32,22 +32,36 @@ DAHDICONFDIR='/etc/dahdi'
export DAHDICONFDIR export DAHDICONFDIR
run_dahdi_cfg() { run_dahdi_cfg() {
echo "dahdi_cfg: span $spanno <$basechan-$endchan>"
dahdi_cfg -c "$cfg_file" -S "$spanno" -C "$basechan-$endchan"
}
configure_span() {
span_devpath="$1" span_devpath="$1"
# Sanity check # Sanity check
checkit=`"dahdi_cfg" --help 2>&1 | grep -- '-S' | wc -l` checkit=`"dahdi_cfg" --help 2>&1 | grep -- '-S' | wc -l`
if [ "$checkit" != 1 ]; then if [ "$checkit" != 1 ]; then
$LOGGER "Bad dahdi_cfg (no -S support). Skipping" echo "Bad dahdi_cfg (no -S support). Skipping"
exit 0 exit 0
fi fi
# Set variables
spanno=`echo "$span_devpath" | sed 's,.*/span-,,'` spanno=`echo "$span_devpath" | sed 's,.*/span-,,'`
basechan=`cat "$span_devpath/basechan"` basechan=`cat "$span_devpath/basechan"`
channels=`cat "$span_devpath/channels"` channels=`cat "$span_devpath/channels"`
endchan=`expr "$basechan" + "$channels" - 1` endchan=`expr "$basechan" + "$channels" - 1`
echo "dahdi_cfg: span $spanno <$basechan-$endchan>"
dahdi_cfg \ # Configure DAHDI
-c "$DAHDICONFDIR/system.conf" \ cfg_file="$DAHDICONFDIR/system.conf"
-S "$spanno" \ if [ -r "$cfg_file" ]; then
-C "$basechan-$endchan" run_dahdi_cfg
else
echo "Using auto-generated config for dahdi_cfg"
cfg_file='-'
DAHDI_CONF_FILE="$cfg_file" dahdi_genconf system | run_dahdi_cfg
fi
# Add to asterisk
asterisk -rx "dahdi create channels $basechan $endchan" asterisk -rx "dahdi create channels $basechan $endchan"
} }
@ -57,9 +71,9 @@ add)
# Can have alternate dahdi configuration directory for debugging # Can have alternate dahdi configuration directory for debugging
# export DAHDICONFDIR="/tmp/xortel/dahdi" # export DAHDICONFDIR="/tmp/xortel/dahdi"
run_dahdi_cfg "/sys$DEVPATH" 2>&1 | $LOGGER configure_span "/sys$DEVPATH" 2>&1 | $LOGGER
;; ;;
remove) remove|online|offline)
# Nothing to do yet... # Nothing to do yet...
echo "$ACTION: $DEVPATH" | $LOGGER echo "$ACTION: $DEVPATH" | $LOGGER
;; ;;