Avoid a race between /etc/init.d/dahdi and hotplug scripts:
[dahdi/tools.git] / hotplug / dahdi_auto_assign_compat
1 #! /bin/sh
2
3 devdir='/sys/bus/dahdi_devices/devices'
4
5 # DAHDI is loaded?
6 if [ ! -d "$devdir" ]; then
7         exit 0
8 fi
9
10 devices_by_registration_time() {
11         grep -H '' $devdir/*/registration_time 2>/dev/null | \
12                 sed 's,/registration_time:,\t,' | \
13                 sort -k 2,2
14 }
15
16 # First assign non-Astribank devices
17 devices_by_registration_time | \
18         grep -v '/astribanks:' | \
19         while read devpath time; do
20                 echo >&2 "D: auto '$devpath'"
21                 dahdi_span_assignments auto "$devpath"
22         done
23
24 # Now handle Astribanks
25 unmatched="`dahdi_span_assignments unmatched`"
26 if [ -n "$unmatched" ]; then
27         # Only if astribanks are not matched in span-assignments.conf
28         # TODO: have dahdi_registration run only on "$unmatched"
29         LC_ALL=C dahdi_registration -Rv on
30 fi