~vibhavp/ubuntu/raring/dahdi-tools/merge-from-debian

« back to all changes in this revision

Viewing changes to .pc/init_unload_oslec/dahdi.init

  • Committer: Vibhav Pant
  • Date: 2012-12-26 17:23:16 UTC
  • mfrom: (2.1.6 sid)
  • Revision ID: vibhavp@gmail.com-20121226172316-o2jojsfcnr0aqrme
* Merge from Debian unstable. Remaining changes:
  - Bug Fix: If linux-headers are not installed, don't block, and print
    information for the user.
  - added debian/dahdi.postinst
  - added --error-handler=init_failed to debian/rules
  - debian/control: Added gawk as dependency for dkms build (LP: #493304)
  - Changes from Debian:
    - debian/control: Change Maintainer
    - debian/control: Removed Uploaders field.
    - debian/control: Removed Debian Vcs-Svn entry and replaced with
      ubuntu-voip Vcs-Bzr, to reflect divergence in packages.
    - debian/control: Package dahdi Depends on dahdi-dkms | dahdi-source 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
#
3
 
# dahdi         This shell script takes care of loading and unloading \
4
 
#               DAHDI Telephony interfaces
5
 
# chkconfig: 2345 9 92
6
 
# description: The DAHDI drivers allow you to use your linux \
7
 
# computer to accept incoming data and voice interfaces
8
 
#
9
 
# config: /etc/dahdi/init.conf
10
 
 
11
 
### BEGIN INIT INFO
12
 
# Provides:        dahdi
13
 
# Required-Start:  $local_fs $remote_fs
14
 
# Required-Stop:   $local_fs $remote_fs
15
 
# Should-Start:    $network $syslog
16
 
# Should-Stop:     $network $syslog
17
 
# Default-Start:   2 3 4 5
18
 
# Default-Stop:    0 1 6
19
 
# Description:     dahdi - load and configure DAHDI modules
20
 
### END INIT INFO
21
 
 
22
 
initdir=/etc/init.d
23
 
 
24
 
# Don't edit the following values. Edit /etc/dahdi/init.conf instead.
25
 
 
26
 
DAHDI_CFG=/usr/sbin/dahdi_cfg
27
 
DAHDI_CFG_CMD=${DAHDI_CFG_CMD:-"$DAHDI_CFG"} # e.g: for a custom system.conf location
28
 
 
29
 
FXOTUNE=/usr/sbin/fxotune
30
 
 
31
 
# The default syncer Astribank. Usually set automatically to a sane
32
 
# value by xpp_sync(1) if you have an Astribank. You can set this to an
33
 
# explicit Astribank (e.g: 01).
34
 
XPP_SYNC=auto
35
 
 
36
 
# The maximal timeout (seconds) to wait for udevd to finish generating
37
 
# device nodes after the modules have loaded and before running dahdi_cfg.
38
 
DAHDI_DEV_TIMEOUT=20
39
 
 
40
 
# A list of modules to unload when stopping.
41
 
# All of their dependencies will be unloaded as well.
42
 
DAHDI_UNLOAD_MODULES="dahdi"
43
 
 
44
 
#
45
 
# Determine which kind of configuration we're using
46
 
#
47
 
system=redhat  # assume redhat
48
 
if [ -f /etc/debian_version ]; then
49
 
    system=debian
50
 
fi
51
 
 
52
 
if [ -f /etc/gentoo-release ]; then
53
 
    system=debian
54
 
fi
55
 
 
56
 
if [ -f /etc/SuSE-release -o -f /etc/novell-release ]
57
 
then
58
 
    system=debian
59
 
fi
60
 
 
61
 
# Source function library.
62
 
if [ $system = redhat ]; then
63
 
    . $initdir/functions || exit 0
64
 
fi
65
 
 
66
 
DAHDI_MODULES_FILE="/etc/dahdi/modules"
67
 
 
68
 
[ -r /etc/dahdi/init.conf ] && . /etc/dahdi/init.conf
69
 
 
70
 
if [ $system = redhat ]; then
71
 
        LOCKFILE=/var/lock/subsys/dahdi
72
 
fi
73
 
 
74
 
# recursively unload a module and its dependencies, if possible.
75
 
# where's modprobe -r when you need it?
76
 
# inputs: module to unload.
77
 
# returns: the result from
78
 
unload_module() {
79
 
        module="$1"
80
 
        line=`lsmod 2>/dev/null | grep "^$1 "`
81
 
        if [ "$line" = '' ]; then return; fi # module was not loaded
82
 
 
83
 
        set -- $line
84
 
        # $1: the original module, $2: size, $3: refcount, $4: deps list
85
 
        mods=`echo $4 | tr , ' '`
86
 
        ec_modules=""
87
 
        # xpp_usb keeps the xpds below busy if an xpp hardware is
88
 
        # connected. Hence must be removed before them:
89
 
        case "$module" in xpd_*) mods="xpp_usb $mods";; esac
90
 
 
91
 
        for mod in $mods; do
92
 
                case "$mod" in
93
 
                dahdi_echocan_*)
94
 
                        ec_modules="$mod $ec_modules"
95
 
                        ;;
96
 
                *)
97
 
                        # run in a subshell, so it won't step over our vars:
98
 
                        (unload_module $mod)
99
 
                        ;;
100
 
                esac
101
 
        done
102
 
        # Now that all the other dependencies are unloaded, we can unload the
103
 
        # dahdi_echocan modules.  The drivers that register spans may keep
104
 
        # references on the echocan modules before they are unloaded.
105
 
        for mod in $ec_modules; do
106
 
                (unload_module $mod)
107
 
        done
108
 
        rmmod $module
109
 
}
110
 
 
111
 
unload_modules() {
112
 
        for module in $DAHDI_UNLOAD_MODULES; do
113
 
                unload_module $module
114
 
        done
115
 
}
116
 
 
117
 
# In (xpp) hotplug mode, the init script is also executed from the
118
 
# hotplug hook. In that case it should not attempt to loade modules.
119
 
#
120
 
# This function only retunrs false (1) if we're in hotplug mode and
121
 
# coming from the hotplug hook script.
122
 
hotplug_should_load_modules() {
123
 
        if [ "$XPP_HOTPLUG_DAHDI" = yes -a "$CALLED_FROM_ATRIBANK_HOOK" != '' ]
124
 
        then
125
 
                return 1
126
 
        fi
127
 
        return 0
128
 
}
129
 
 
130
 
# In (xpp) hotplug mode: quit after we loaded modules.
131
 
#
132
 
# In hotplug mode, the main run should end here, whereas the rest of the
133
 
# script should be finished by the instance running from the hook.
134
 
# Note that we only get here if there are actually Astribanks on the
135
 
# system (otherwise noone will trigger the run of the hotplug hook
136
 
# script).
137
 
hotplug_exit_after_load() {
138
 
        if [ "$XPP_HOTPLUG_DAHDI" = yes -a "$CALLED_FROM_ATRIBANK_HOOK" = '' ]
139
 
        then
140
 
                exit 0
141
 
        fi
142
 
}
143
 
 
144
 
# Initialize the Xorcom Astribank (xpp/) using perl utiliites:
145
 
xpp_startup() {
146
 
        # do nothing if there are no astribank devices:
147
 
        if ! /usr/share/dahdi/waitfor_xpds; then return 0; fi
148
 
 
149
 
        hotplug_exit_after_load
150
 
 
151
 
        # overriding locales for the above two, as perl can be noisy
152
 
        # when locales are missing.
153
 
        # No register all the devices if they didn't auto-register:
154
 
        LC_ALL=C dahdi_registration on
155
 
}
156
 
 
157
 
 
158
 
hpec_start() {
159
 
        # HPEC license found
160
 
        if ! echo /var/lib/digium/licenses/HPEC-*.lic | grep -v '\*' | grep -q .; then
161
 
                return
162
 
        fi
163
 
 
164
 
        # dahdihpec_enable not installed in /usr/sbin
165
 
        if [ ! -f /usr/sbin/dahdihpec_enable ]; then
166
 
                echo -n "Running dahdihpec_enable: Failed"
167
 
                echo -n "."
168
 
                echo "  The dahdihpec_enable binary is not installed in /usr/sbin."
169
 
                return
170
 
        fi
171
 
 
172
 
        # dahdihpec_enable not set executable
173
 
        if [ ! -x /usr/sbin/dahdihpec_enable ]; then
174
 
                echo -n "Running dahdihpec_enable: Failed"
175
 
                echo -n "."
176
 
                echo "  /usr/sbin/dahdihpec_enable is not set as executable."
177
 
                return
178
 
        fi
179
 
 
180
 
        # dahdihpec_enable properly installed
181
 
        if [ $system = debian ]; then
182
 
                echo -n "Running dahdihpec_enable: "
183
 
                /usr/sbin/dahdihpec_enable 2> /dev/null
184
 
        elif [ $system = redhat ]; then
185
 
                action "Running dahdihpec_enable: " /usr/sbin/dahdihpec_enable
186
 
        fi
187
 
        if [ $? = 0 ]; then
188
 
                echo -n "done"
189
 
                echo "."
190
 
        else
191
 
                echo -n "Failed"
192
 
                echo -n "."
193
 
                echo "  This can be caused if you had already run dahdihpec_enable, or if your HPEC license is no longer valid."
194
 
        fi
195
 
}
196
 
 
197
 
shutdown_dynamic() {
198
 
        if ! grep -q ' DYN/' /proc/dahdi/* 2>/dev/null; then return; fi
199
 
 
200
 
        # we should only get here if we have dynamic spans. Right?
201
 
        $DAHDI_CFG_CMD -s
202
 
}
203
 
 
204
 
load_modules() {
205
 
        # Some systems, e.g. Debian Lenny, add here -b, which will break
206
 
        # loading of modules blacklisted in modprobe.d/*
207
 
        unset MODPROBE_OPTIONS
208
 
        modules=`sed -e 's/#.*$//' $DAHDI_MODULES_FILE 2>/dev/null`
209
 
        #if [ "$modules" = '' ]; then
210
 
                # what?
211
 
        #fi
212
 
        echo "Loading DAHDI hardware modules:"
213
 
        modprobe dahdi
214
 
        for line in $modules; do
215
 
                if [ $system = debian ]; then
216
 
                        echo -n "   ${line}: "
217
 
                        if modprobe $line 2> /dev/null; then
218
 
                                echo -n "done"
219
 
                        else
220
 
                                echo -n "error"
221
 
                        fi
222
 
                elif [ $system = redhat ]; then
223
 
                        action "  ${line}: " modprobe $line
224
 
                fi
225
 
        done
226
 
        echo ""
227
 
}
228
 
 
229
 
if [ ! -x "$DAHDI_CFG" ]; then
230
 
       echo "dahdi_cfg not executable"
231
 
       exit 0
232
 
fi
233
 
 
234
 
if [ ! -f /etc/dahdi/system.conf ]; then
235
 
        echo "/etc/dahdi/system.conf not found. Nothing to do."
236
 
       exit 0
237
 
fi
238
 
 
239
 
RETVAL=0
240
 
 
241
 
# See how we were called.
242
 
case "$1" in
243
 
  start)
244
 
        if hotplug_should_load_modules; then
245
 
                load_modules
246
 
        fi
247
 
 
248
 
        TMOUT=$DAHDI_DEV_TIMEOUT # max secs to wait
249
 
 
250
 
        while [ ! -d /dev/dahdi ] ; do
251
 
                sleep 1
252
 
                TMOUT=`expr $TMOUT - 1`
253
 
                if [ $TMOUT -eq 0 ] ; then
254
 
                        echo "Error: missing /dev/dahdi!"
255
 
                        exit 1
256
 
                fi
257
 
        done
258
 
 
259
 
        xpp_startup
260
 
 
261
 
        if [ ! -e /proc/dahdi/1 ]; then
262
 
                echo "No hardware timing source found in /proc/dahdi, loading dahdi_dummy"
263
 
                modprobe dahdi_dummy 2> /dev/null
264
 
        fi
265
 
 
266
 
        if [ $system = debian ]; then
267
 
            echo -n "Running dahdi_cfg: "
268
 
            $DAHDI_CFG_CMD 2> /dev/null && echo -n "done"
269
 
            echo "."
270
 
        elif [ $system = redhat ]; then
271
 
            action "Running dahdi_cfg: " $DAHDI_CFG_CMD
272
 
        fi
273
 
        RETVAL=$?
274
 
 
275
 
        if [ "$LOCKFILE" != '' ]; then
276
 
                [ $RETVAL -eq 0 ] && touch $LOCKFILE
277
 
        fi
278
 
 
279
 
        if [ -x "$FXOTUNE" ] && [ -r /etc/fxotune.conf ]; then
280
 
                # Allowed to fail if e.g. Asterisk already uses channels:
281
 
                $FXOTUNE -s || :
282
 
        fi
283
 
 
284
 
        # Set the right Astribanks ticker:
285
 
        LC_ALL=C xpp_sync "$XPP_SYNC"
286
 
 
287
 
        hpec_start
288
 
        ;;
289
 
  stop)
290
 
        # Unload drivers
291
 
        #shutdown_dynamic # FIXME: needs test from someone with dynamic spans
292
 
        echo -n "Unloading DAHDI hardware modules: "
293
 
        if unload_modules; then
294
 
                echo "done"
295
 
        else
296
 
                echo "error"
297
 
        fi
298
 
        if [ "$LOCKFILE" != '' ]; then
299
 
                [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
300
 
        fi
301
 
        ;;
302
 
  unload)
303
 
        unload_modules
304
 
        ;;
305
 
  restart|force-reload)
306
 
        $0 stop
307
 
        $0 start
308
 
        ;;
309
 
  reload)
310
 
        if [ $system = debian ]; then
311
 
            echo -n "Rerunning dahdi_cfg: "
312
 
            $DAHDI_CFG_CMD 2> /dev/null && echo -n "done"
313
 
            echo "."
314
 
        elif [ $system = redhat ]; then
315
 
            action "Rerunning dahdi_cfg: " $DAHDI_CFG_CMD
316
 
        fi
317
 
        RETVAL=$?
318
 
        ;;
319
 
  status)
320
 
        if [ -d /proc/dahdi ]; then
321
 
                /usr/sbin/lsdahdi
322
 
                RETVAL=0
323
 
        else
324
 
                RETVAL=3
325
 
        fi
326
 
        ;;
327
 
  *)
328
 
        echo "Usage: dahdi {start|stop|restart|status|reload|unload}"
329
 
        exit 1
330
 
esac
331
 
 
332
 
exit $RETVAL
333