Convert alternate dialplan switch list to use read/write locks.
[asterisk/asterisk.git] / contrib / init.d / rc.mandrake.zaptel
1 #!/bin/sh
2 #
3 # zaptel:       Loads Asterisk modules
4 #
5 # Version:      @(#) /etc/rc.d/init.d/zaptel 1.0
6 #
7 # chkconfig: 2345 90 10
8 # description: Loads and unloads zaptel modules at boot time and shutdown.
9 #
10 # hide: true
11
12 # Source function library.
13 . /etc/rc.d/init.d/functions
14
15 # Default modules - override in /etc/sysconfig/zaptel
16 ######################################
17 MODULES="usb-uhci zaptel wcfxo wcusb"
18 ######################################
19
20 # Resolve back to the basename (i.e. zaptel, not S90zaptel)
21 if [ 0`readlink $0` = "0" ]; then
22         CONFIGFILE=/etc/sysconfig/`basename $0`
23 else
24         CONFIG0=`readlink $0`
25         CONFIGFILE=/etc/sysconfig/`basename $CONFIG0`
26 fi
27
28 [ -f $CONFIGFILE ] && . $CONFIGFILE
29
30 function probe() {
31         gprintf "                           $1"
32         modprobe -i $1
33         # It has to be in the module list, otherwise something is wrong
34         if lsmod | grep -c ^$1 >/dev/null; then
35                 success
36         else
37                 failure
38         fi
39         echo
40 }
41
42 function unprobe() {
43         gprintf "                           $1"
44         rmmod $1 >/dev/null 2>&1
45         # If it's still in the module list after removing it, there's something wrong.
46         if lsmod | grep -c ^$1 >/dev/null; then
47                 failure
48         else
49                 success
50         fi
51         echo
52 }
53
54 function reverse_modules() {
55         tmp=$MODULES
56         MODULES=''
57         for i in $tmp; do
58                 MODULES="$i $MODULES" ;
59         done
60 }
61
62 # See how we were called.
63 case "$1" in
64   start)
65         gprintf "Loading Asterisk modules:\n"
66         for i in $MODULES; do
67                 probe $i
68                 usleep 100000 ;
69         done
70         ztcfg
71         ;;
72   stop)
73         gprintf "Unloading Asterisk modules:\n"
74         reverse_modules
75         for i in $MODULES; do
76                 unprobe $i
77                 usleep 100000 ;
78         done
79         ;;
80   status)
81         #ztcfg -vv
82         OK=1
83         gprintf "Checking Asterisk modules"
84         for i in $MODULES; do
85                 if [ `lsmod | grep -c $i` -eq 0 ]; then
86                         OK=0
87                 fi
88         done
89         if [ $OK -gt 0 ]; then
90                 success
91         else
92                 failure
93         fi
94         echo
95         ;;
96   restart)
97         $0 stop
98         $0 start
99         ;;
100   *)
101         gprintf "*** Usage: $0 {start|stop|status|restart}\n"
102         exit 1
103 esac
104
105 exit 0
106