summaryrefslogtreecommitdiff
path: root/zaptel.init
blob: a7848ac55e05fbb2186363a818030376a69eebfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/sh
#
# zaptel        This shell script takes care of loading and unloading \
#               Zapata Telephony interfaces
# chkconfig: 2345 9 92
# description: The zapata telephony drivers allow you to use your linux \
# computer to accept incoming data and voice interfaces
#
# config: /etc/sysconfig/zaptel

initdir=/etc/init.d

#
# Determine which kind of configuration we're using
#
system=redhat  # assume redhat
if [ -f /etc/debian_version ]; then
    system=debian
fi

# Source function library.
if [ $system = redhat ]; then
    . $initdir/functions || exit 0
fi

# Source zaptel configuration.
if [ $system = debian ]; then
    [ -f /etc/default/zaptel ] && . /etc/default/zaptel
elif [ $system = redhat ]; then
    [ -f /etc/sysconfig/zaptel ] && . /etc/sysconfig/zaptel
fi

if [ -z "${MODULES}" ]; then 
	# Populate defaults if not present
	MODULES="tor2 wct4xxp wct1xxp wcte11xp wcfxo wctdm" 
fi

RMODULES=""
# Reverse list for un-loading; don't change
for x in $MODULES; do 
    RMODULES="$x $RMODULES"
done

# Check that telephony is up.
[ "${TELEPHONY}" = "yes" ] || exit 0

[ -f /sbin/ztcfg ] || exit 0

[ -f /etc/zaptel.conf ] || exit 0

if [ "${DEBUG}" = "yes" ]; then
	ARGS="debug=1"
fi

RETVAL=0

# See how we were called.
case "$1" in
  start)
        # Load drivers
	rmmod wcusb >& /dev/null
	rmmod wcfxsusb >& /dev/null
	rmmod audio >& /dev/null
	if [ $system = debian ]; then
	    echo -n "Loading zaptel framework: " 
	    modprobe zaptel >& /dev/null && echo -n "done"
	    echo "."
	elif [ $system = redhat ]; then
	    action "Loading zaptel framework: " modprobe zaptel
	fi
	echo -n "Waiting for zap to come online..."
	TMOUT=10 # max secs to wait
	while [ ! -d /dev/zap ] ; do
 		sleep 1
		TMOUT=`expr $TMOUT - 1`
		if [ $TMOUT -eq 0 ] ; then
			echo "Error: missing /dev/zap!"
			exit 1
		fi
	done
	echo "OK"
	echo -n "Loading zaptel hardware modules:"
	for x in $MODULES; do 
		if modprobe ${x} ${ARGS} >& /dev/null; then
			echo -n " $x"
		fi
	done
	sleep 3
	if [ ! -e /proc/zaptel/1 ]; then
		echo "No functioning zap hardware found in /proc/zaptel, loading ztdummy"
		modprobe ztdummy >& /dev/null
	fi
	if [ $system = debian ]; then
	    echo -n "Running ztcfg: " 
	    /sbin/ztcfg >& /dev/null && echo -n "done"
	    echo "."
	elif [ $system = redhat ]; then
	    action "Running ztcfg: " /sbin/ztcfg
	fi
	RETVAL=$?

        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/zaptel
        ;;
  stop)
        # Unload drivers
        echo -n "Unloading zaptel hardware drivers:"
	for x in $RMODULES; do 
		if rmmod ${x} >& /dev/null; then
			echo -n " $x"
		fi
	done
	echo "."

	if [ $system = debian ]; then
	    echo -n "Removing zaptel module: " 
	    rmmod zaptel >& /dev/null && echo -n "done"
	    echo "."
	elif [ $system = redhat ]; then
	    action "Removing zaptel module: " rmmod zaptel
	fi
	RETVAL=$?

        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zaptel
        ;;
 restart)
	$0 stop
	$0 start
	;;
  reload)
	if [ $system = debian ]; then
	    echo -n "Reloading ztcfg: "
	    /sbin/ztcfg >& /dev/null && echo -n "done"
	    echo "."
	elif [ $system = redhat ]; then
	    action "Reloading ztcfg: " /sbin/ztcfg
	fi
	RETVAL=$?
	;;
  *)
        echo "Usage: zaptel {start|stop|restart|reload}"
        exit 1
esac

exit $RETVAL