| 1 |
#! /bin/sh |
| 2 |
# |
| 3 |
# /usr/share/dahdi/dahdi_span_config |
| 4 |
# |
| 5 |
# Called by UDEV when a dahdi span is added/removed |
| 6 |
# |
| 7 |
|
| 8 |
me=`basename $0` |
| 9 |
dir=`dirname $0` |
| 10 |
LOGGER="logger -i -t '$me'" |
| 11 |
NAME=`basename "$DEVPATH" | tr -c 'A-Za-z0-9-' '_'` |
| 12 |
|
| 13 |
exec 2> /dev/null |
| 14 |
# Always redirect stderr somewhere, otherwise the shell script will die |
| 15 |
# when it tries to do I/O related stuff on closed file descriptor. |
| 16 |
# Our default is to throw it down the bit-bucket. |
| 17 |
#exec 2> /dev/console |
| 18 |
## If you wish to trace this script: |
| 19 |
#exec 2> "/tmp/${me}.$NAME" 1>&2 |
| 20 |
|
| 21 |
# Our directory in the beginning, so we can use local lab setup |
| 22 |
PATH="$dir:/usr/sbin:/sbin:/usr/bin:/bin" |
| 23 |
export PATH |
| 24 |
|
| 25 |
set -e |
| 26 |
|
| 27 |
#echo >&2 "$0($ACTION): DEBUG($# args): '$*'" |
| 28 |
|
| 29 |
# Do we have a configuration? |
| 30 |
if [ -f /etc/dahdi/init.conf ]; then |
| 31 |
. /etc/dahdi/init.conf |
| 32 |
fi |
| 33 |
|
| 34 |
if [ "$DAHDI_UDEV_DISABLE_SPANS" = 'yes' ]; then |
| 35 |
echo "DAHDI_UDEV_DISABLE_SPANS=yes. Skip $DEVPATH" | $LOGGER |
| 36 |
exit 0 |
| 37 |
fi |
| 38 |
|
| 39 |
# Can we pass a different value so we can use |
| 40 |
# alternate (testing) configuration? |
| 41 |
# Meanwhile, make it hard-coded. |
| 42 |
DAHDICONFDIR='/etc/dahdi' |
| 43 |
export DAHDICONFDIR |
| 44 |
|
| 45 |
run_parts() { |
| 46 |
# Have our internal "run-parts" (adapted from Fedora), |
| 47 |
# as implementations differ |
| 48 |
for i in `LC_ALL=C; ls -d $dir/span_config.d/*[!~,] 2>/dev/null` ; do |
| 49 |
[ -d "$i" ] && continue |
| 50 |
[ ! -x "$i" ] && continue |
| 51 |
# Don't run *.{rpmsave,rpmorig,rpmnew,swp,cfsaved} files |
| 52 |
case "$i" in |
| 53 |
*.cfsaved|*.rpmsave|*.rpmorig|*.rpmnew|*.swp|*,v) |
| 54 |
continue |
| 55 |
;; |
| 56 |
esac |
| 57 |
#echo "D: Running '$i'" |
| 58 |
"$i" |
| 59 |
done |
| 60 |
} |
| 61 |
|
| 62 |
case "$ACTION" in |
| 63 |
add) |
| 64 |
echo "$ACTION: $DEVPATH" | $LOGGER |
| 65 |
|
| 66 |
# Old driver. These scripts probably won't work anyway. |
| 67 |
if [ ! -f /sys/module/dahdi/parameters/auto_assign_spans ]; then |
| 68 |
if [ -f /sys/module/dahdi ]; then |
| 69 |
$LOGGER "Old driver (no auto_assign_spans parameter). Skip $DEVPATH" |
| 70 |
exit 0 |
| 71 |
fi |
| 72 |
fi |
| 73 |
|
| 74 |
if [ $(cat /sys/module/dahdi/parameters/auto_assign_spans) -ne 0 ]; then |
| 75 |
$LOGGER "auto_assign_spans=1. Skip $DEVPATH" |
| 76 |
exit 0 |
| 77 |
fi |
| 78 |
|
| 79 |
# Set variables |
| 80 |
span_devpath="/sys$DEVPATH" |
| 81 |
SPANNO=`echo "$span_devpath" | sed 's,.*/span-,,'` |
| 82 |
BASECHAN=`cat "$span_devpath/basechan"` |
| 83 |
CHANNELS=`cat "$span_devpath/channels"` |
| 84 |
ENDCHAN=`expr "$BASECHAN" + "$CHANNELS" - 1` |
| 85 |
export SPANNO BASECHAN CHANNELS ENDCHAN |
| 86 |
# Background run -- don't block udev |
| 87 |
run_parts 2>&1 < /dev/null | $LOGGER & |
| 88 |
;; |
| 89 |
remove|online|offline) |
| 90 |
# Nothing to do yet... |
| 91 |
echo "$ACTION: $DEVPATH" | $LOGGER |
| 92 |
;; |
| 93 |
*) |
| 94 |
echo "UNHANDLED: $ACTION: $DEVPATH" | $LOGGER |
| 95 |
;; |
| 96 |
esac |
| 97 |
|