hotplug modularization: move sources to a subdir
Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com> Acked-by: Russ Meyerriecks <rmeyerriecks@digium.com>
This commit is contained in:
committed by
Tzafrir Cohen
parent
a6203e151f
commit
cdedf024ae
83
hotplug/dahdi_handle_device
Executable file
83
hotplug/dahdi_handle_device
Executable file
@@ -0,0 +1,83 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# /usr/share/dahdi/dahdi_handle_device
|
||||
#
|
||||
# Called by UDEV when a dahdi device is added/removed
|
||||
#
|
||||
|
||||
me=`basename $0`
|
||||
dir=`dirname $0`
|
||||
LOGGER="logger -i -t '$me'"
|
||||
NAME=`basename "$DEVPATH" | tr -c 'A-Za-z0-9-' '_'`
|
||||
|
||||
# Always redirect stderr somewhere, otherwise the shell script will die
|
||||
# when it tries to do I/O related stuff on closed file descriptor.
|
||||
# Our default is to throw it down the bit-bucket.
|
||||
exec 2> /dev/null
|
||||
# If you wish to trace this script:
|
||||
#exec 2> "/tmp/${me}.$NAME" 1>&2
|
||||
#exec 2> /dev/console
|
||||
|
||||
# Our directory in the beginning, so we can use local lab setup
|
||||
PATH="$dir:/usr/sbin:/sbin:/usr/bin:/bin"
|
||||
|
||||
set -e
|
||||
|
||||
#echo >&2 "$0($ACTION): DEBUG($# args): '$*'"
|
||||
|
||||
# Do we have a configuration?
|
||||
if [ -f /etc/dahdi/init.conf ]; then
|
||||
. /etc/dahdi/init.conf
|
||||
fi
|
||||
|
||||
if [ "$DAHDI_UDEV_DISABLE_DEVICES" = 'yes' ]; then
|
||||
echo "DAHDI_UDEV_DISABLE_DEVICES=yes. Skip $DEVPATH" | $LOGGER
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Can we pass a different value so we can use
|
||||
# alternate (testing) configuration?
|
||||
# Meanwhile, make it hard-coded.
|
||||
DAHDICONFDIR='/etc/dahdi'
|
||||
export DAHDICONFDIR
|
||||
|
||||
case "$ACTION" in
|
||||
add)
|
||||
echo "$ACTION: $DEVPATH" | $LOGGER
|
||||
|
||||
# Check if we can safely do our job
|
||||
if [ ! -f /sys/module/dahdi/parameters/auto_assign_spans ]; then
|
||||
if [ -f /sys/module/dahdi ]; then
|
||||
$LOGGER "Old driver (no auto_assign_spans parameter). Skip $DEVPATH"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
if [ `cat /sys/module/dahdi/parameters/auto_assign_spans` -eq 1 ]; then
|
||||
echo "auto_assign_spans=1. Skip $DEVPATH" | $LOGGER
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Can have alternate dahdi configuration directory for debugging
|
||||
# export DAHDICONFDIR="/tmp/xortel/dahdi"
|
||||
|
||||
# Don't block udev for too long
|
||||
(
|
||||
if [ -r "$DAHDICONFDIR/span-types.conf" ]; then
|
||||
dahdi_span_types set "/sys$DEVPATH"
|
||||
fi
|
||||
if [ -r "$DAHDICONFDIR/assigned-spans.conf" ]; then
|
||||
dahdi_span_assignments add "/sys$DEVPATH"
|
||||
else
|
||||
# No configuration. No order guaranteed
|
||||
dahdi_span_assignments auto "/sys$DEVPATH"
|
||||
fi
|
||||
) 2>&1 < /dev/null | $LOGGER &
|
||||
;;
|
||||
remove)
|
||||
# Nothing to do yet...
|
||||
echo "$ACTION: $DEVPATH" | $LOGGER
|
||||
;;
|
||||
*)
|
||||
echo "UNHANDLED: $ACTION: $DEVPATH" | $LOGGER
|
||||
;;
|
||||
esac
|
||||
113
hotplug/dahdi_span_config
Executable file
113
hotplug/dahdi_span_config
Executable file
@@ -0,0 +1,113 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# /usr/share/dahdi/dahdi_span_config
|
||||
#
|
||||
# Called by UDEV when a dahdi span is added/removed
|
||||
#
|
||||
|
||||
me=`basename $0`
|
||||
dir=`dirname $0`
|
||||
LOGGER="logger -i -t '$me'"
|
||||
NAME=`basename "$DEVPATH" | tr -c 'A-Za-z0-9-' '_'`
|
||||
|
||||
exec 2> /dev/null
|
||||
# Always redirect stderr somewhere, otherwise the shell script will die
|
||||
# when it tries to do I/O related stuff on closed file descriptor.
|
||||
# Our default is to throw it down the bit-bucket.
|
||||
#exec 2> /dev/console
|
||||
## If you wish to trace this script:
|
||||
#exec 2> "/tmp/${me}.$NAME" 1>&2
|
||||
|
||||
# Our directory in the beginning, so we can use local lab setup
|
||||
PATH="$dir:/usr/sbin:/sbin:/usr/bin:/bin"
|
||||
|
||||
set -e
|
||||
|
||||
#echo >&2 "$0($ACTION): DEBUG($# args): '$*'"
|
||||
|
||||
# Do we have a configuration?
|
||||
if [ -f /etc/dahdi/init.conf ]; then
|
||||
. /etc/dahdi/init.conf
|
||||
fi
|
||||
|
||||
if [ "$DAHDI_UDEV_DISABLE_SPANS" = 'yes' ]; then
|
||||
echo "DAHDI_UDEV_DISABLE_SPANS=yes. Skip $DEVPATH" | $LOGGER
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Can we pass a different value so we can use
|
||||
# alternate (testing) configuration?
|
||||
# Meanwhile, make it hard-coded.
|
||||
DAHDICONFDIR='/etc/dahdi'
|
||||
export DAHDICONFDIR
|
||||
|
||||
run_dahdi_cfg() {
|
||||
echo "dahdi_cfg: span $spanno <$basechan-$endchan> ($DEVPATH)"
|
||||
dahdi_cfg -c "$cfg_file" -S "$spanno" -C "$basechan-$endchan"
|
||||
}
|
||||
|
||||
configure_span() {
|
||||
span_devpath="$1"
|
||||
# Sanity check
|
||||
checkit=`"dahdi_cfg" --help 2>&1 | grep -- '-S' | wc -l`
|
||||
if [ "$checkit" != 1 ]; then
|
||||
echo "Bad dahdi_cfg (no -S support). Skipping"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Set variables
|
||||
spanno=`echo "$span_devpath" | sed 's,.*/span-,,'`
|
||||
basechan=`cat "$span_devpath/basechan"`
|
||||
channels=`cat "$span_devpath/channels"`
|
||||
endchan=`expr "$basechan" + "$channels" - 1`
|
||||
|
||||
# Configure DAHDI
|
||||
cfg_file="$DAHDICONFDIR/system.conf"
|
||||
if [ -r "$cfg_file" ]; then
|
||||
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
|
||||
fxotune_cfg='/etc/fxotune.conf'
|
||||
if [ -r "$fxotune_cfg" ]; then
|
||||
echo "fxotune: span $spanno <$basechan-$endchan> ($DEVPATH)"
|
||||
fxotune -s -b "$basechan" -e "$endchan"
|
||||
fi
|
||||
|
||||
# Add to asterisk
|
||||
asterisk -rx "dahdi create channels $basechan $endchan"
|
||||
}
|
||||
|
||||
case "$ACTION" in
|
||||
add)
|
||||
echo "$ACTION: $DEVPATH" | $LOGGER
|
||||
|
||||
# Old driver. These scripts probably won't work anyway.
|
||||
if [ ! -f /sys/module/dahdi/parameters/auto_assign_spans ]; then
|
||||
if [ -f /sys/module/dahdi ]; then
|
||||
$LOGGER "Old driver (no auto_assign_spans parameter). Skip $DEVPATH"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $(cat /sys/module/dahdi/parameters/auto_assign_spans) -eq 1 ]; then
|
||||
$LOGGER "auto_assign_spans=1. Skip $DEVPATH"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Can have alternate dahdi configuration directory for debugging
|
||||
# export DAHDICONFDIR="/tmp/xortel/dahdi"
|
||||
|
||||
configure_span "/sys$DEVPATH" 2>&1 | $LOGGER
|
||||
;;
|
||||
remove|online|offline)
|
||||
# Nothing to do yet...
|
||||
echo "$ACTION: $DEVPATH" | $LOGGER
|
||||
;;
|
||||
*)
|
||||
echo "UNHANDLED: $ACTION: $DEVPATH" | $LOGGER
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user