2011-10-07 03:03:00 +08:00
|
|
|
#! /bin/sh
|
|
|
|
#
|
2013-11-26 23:15:13 +08:00
|
|
|
# /usr/share/dahdi/dahdi_handle_device
|
2011-10-07 03:03:00 +08:00
|
|
|
#
|
2013-09-23 19:59:14 +08:00
|
|
|
# Called by UDEV when a dahdi device is added/removed
|
|
|
|
#
|
2011-10-07 03:03:00 +08:00
|
|
|
|
|
|
|
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"
|
2014-01-16 18:31:17 +08:00
|
|
|
export PATH
|
2011-10-07 03:03:00 +08:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2013-09-23 19:59:14 +08:00
|
|
|
#echo >&2 "$0($ACTION): DEBUG($# args): '$*'"
|
|
|
|
|
2013-10-16 01:09:30 +08:00
|
|
|
# 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
|
|
|
|
|
2013-09-23 19:59:14 +08:00
|
|
|
# Can we pass a different value so we can use
|
|
|
|
# alternate (testing) configuration?
|
|
|
|
# Meanwhile, make it hard-coded.
|
|
|
|
DAHDICONFDIR='/etc/dahdi'
|
|
|
|
export DAHDICONFDIR
|
2011-10-07 03:03:00 +08:00
|
|
|
|
2014-01-16 18:31:17 +08:00
|
|
|
run_parts() {
|
|
|
|
# Have our internal "run-parts" (adapted from Fedora),
|
|
|
|
# as implementations differ
|
|
|
|
for i in `LC_ALL=C; ls -d $dir/handle_device.d/*[!~,] 2>/dev/null` ; do
|
|
|
|
[ -d "$i" ] && continue
|
|
|
|
[ ! -x "$i" ] && continue
|
|
|
|
# Don't run *.{rpmsave,rpmorig,rpmnew,swp,cfsaved} files
|
|
|
|
case "$i" in
|
|
|
|
*.cfsaved|*.rpmsave|*.rpmorig|*.rpmnew|*.swp|*,v)
|
|
|
|
continue
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
echo "D: Running '$i'"
|
|
|
|
"$i"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2011-10-07 03:03:00 +08:00
|
|
|
case "$ACTION" in
|
|
|
|
add)
|
|
|
|
echo "$ACTION: $DEVPATH" | $LOGGER
|
2013-12-21 14:17:01 +08:00
|
|
|
|
|
|
|
# Check if we can safely do our job
|
|
|
|
if [ ! -f /sys/module/dahdi/parameters/auto_assign_spans ]; then
|
|
|
|
echo "Old driver (no auto_assign_spans parameter). Skip $DEVPATH" | $LOGGER
|
|
|
|
exit 0
|
|
|
|
fi
|
2014-02-07 00:46:00 +08:00
|
|
|
if [ `cat /sys/module/dahdi/parameters/auto_assign_spans` -ne 0 ]; then
|
2013-12-21 14:17:01 +08:00
|
|
|
echo "auto_assign_spans=1. Skip $DEVPATH" | $LOGGER
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2014-01-16 18:31:17 +08:00
|
|
|
# Background run -- don't block udev
|
|
|
|
run_parts 2>&1 < /dev/null | $LOGGER &
|
2011-10-07 03:03:00 +08:00
|
|
|
;;
|
|
|
|
remove)
|
2013-09-23 19:59:14 +08:00
|
|
|
# Nothing to do yet...
|
2011-10-07 03:03:00 +08:00
|
|
|
echo "$ACTION: $DEVPATH" | $LOGGER
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "UNHANDLED: $ACTION: $DEVPATH" | $LOGGER
|
|
|
|
;;
|
|
|
|
esac
|