Terminology rename: "pinned" -> "assigned"
[dahdi/tools.git] / handle_device
1 #! /bin/sh
2 #
3 # /usr/share/dahdi/handle_device
4 #
5 # Called by UDEV when a dahdi device 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 # Always redirect stderr somewhere, otherwise the shell script will die
14 # when it tries to do I/O related stuff on closed file descriptor.
15 # Our default is to throw it down the bit-bucket.
16 exec 2> /dev/null
17 # If you wish to trace this script:
18 #exec 2> "/tmp/${me}.$NAME" 1>&2
19 #exec 2> /dev/console
20
21 # Our directory in the beginning, so we can use local lab setup
22 PATH="$dir:/usr/sbin:/sbin:/usr/bin:/bin"
23
24 set -e
25
26 #echo >&2 "$0($ACTION): DEBUG($# args): '$*'"
27
28 # Do we have a configuration?
29 if [ -f /etc/dahdi/init.conf ]; then
30         . /etc/dahdi/init.conf
31 fi
32
33 if [ "$DAHDI_UDEV_DISABLE_DEVICES" = 'yes' ]; then
34         echo "DAHDI_UDEV_DISABLE_DEVICES=yes. Skip $DEVPATH" | $LOGGER
35         exit 0
36 fi
37
38 # Check if we can safely do our job
39 if [ ! -f /sys/module/dahdi/parameters/auto_assign_spans ]; then
40         echo "Old driver (no auto_assign_spans parameter). Skip $DEVPATH" | $LOGGER
41         exit 0
42 fi
43 if [ `cat /sys/module/dahdi/parameters/auto_assign_spans` -eq 1 ]; then
44         echo "auto_assign_spans=1. Skip $DEVPATH" | $LOGGER
45         exit 0
46 fi
47
48 # Can we pass a different value so we can use
49 # alternate (testing) configuration?
50 # Meanwhile, make it hard-coded.
51 DAHDICONFDIR='/etc/dahdi'
52 export DAHDICONFDIR
53
54 case "$ACTION" in
55 add)
56         echo "$ACTION: $DEVPATH" | $LOGGER
57         # Can have alternate dahdi configuration directory for debugging
58         # export DAHDICONFDIR="/tmp/xortel/dahdi"
59
60         # Don't block udev for too long
61         (
62                 if [ -r "$DAHDICONFDIR/span-types.conf" ]; then
63                         span_types set "/sys$DEVPATH"
64                 fi
65                 if [ -r "$DAHDICONFDIR/assigned-spans.conf" ]; then
66                         span_assignments add "/sys$DEVPATH"
67                 else
68                         # No configuration. No order guaranteed
69                         span_assignments auto
70                 fi
71         ) 2>&1 < /dev/null | $LOGGER &
72         ;;
73 remove)
74         # Nothing to do yet...
75         echo "$ACTION: $DEVPATH" | $LOGGER
76         ;;
77 *)
78         echo "UNHANDLED: $ACTION: $DEVPATH" | $LOGGER
79         ;;
80 esac