~ubuntu-branches/ubuntu/quantal/zaptel/quantal

« back to all changes in this revision

Viewing changes to live_zap

  • Committer: Bazaar Package Importer
  • Author(s): Tzafrir Cohen
  • Date: 2008-08-28 22:58:23 UTC
  • mfrom: (11.1.11 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080828225823-r8bdunirm8hmc76m
Tags: 1:1.4.11~dfsg-2
* Patch xpp_fxs_power: Fixed an issue with hook detection of the Astribank
  FXS module.
* Don't fail init.d script if fxotune fails. This may happen if running it
  when Asterisk is already running.
* Bump standards version to 3.8.0.0 .
* Ignore false lintian warning ("m-a a-i" has "a a").
* Patch xpp_fxo_cid_always: do always pass PCM if that's what the user
  asked.
* Patch vzaphfc_proc_root_dir: fix vzaphfc on 2.6.26.
* Patch wcte12xp_flags: Proper time for irq save flags.
* Patch headers_2627: Fix location of semaphore.h for 2.6.27 .
* Patch xpp_fxs_dtmf_leak: Don't play DTMFs to the wrong channel.
* Patch wctdm_fix_alarm: Fix sending channel alarms.
* Patch device_class_2626: Fix building 2.6.26 (Closes: #493397).
* Using dh_lintian for lintian overrides, hence requiring debhelper 6.0.7.
* Lintian: we know we have direct changes. Too bad we're half-upstream :-(
* Fix doc-base section names. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
set -e
 
4
 
 
5
DESTDIR=$PWD/live
 
6
KVERS=${KVERS:-`uname -r`}
 
7
MODULES_DIR="$DESTDIR/lib/modules/$KVERS/misc"
 
8
XPP_SYNC=auto
 
9
AST_SCRIPT=/etc/init.d/asterisk
 
10
# Use this file to pass options to modules:
 
11
PERLLIBDIR=`perl -V:sitelib | cut -d "'" -f 2`
 
12
 
 
13
# Manual list of modules. They will be loaded by insmod.
 
14
# If reside in a subdir, add it explicitly.
 
15
 
 
16
MODULES_LOAD="zaptel"
 
17
 
 
18
# this one *is* resolved recusively. 
 
19
# the only reason to set a different value is if you use hpec / oslec,
 
20
# as Zaptel depends on them.
 
21
REMOVE_MODULES="zaptel"
 
22
 
 
23
if [ -r $DESTDIR/live.conf ]; then . $DESTDIR/live.conf; fi
 
24
 
 
25
# Give priority to our installed binaries:
 
26
PATH=$DESTDIR/sbin:$DESTDIR/usr/sbin:$PATH
 
27
export PATH
 
28
 
 
29
# TODO: If you already use PERL5DIR, please fix this part:
 
30
PERL5LIB="$DESTDIR/$PERLLIBDIR"
 
31
export PERL5LIB
 
32
 
 
33
# the same as xpp/utils/zaptel_drivers .
 
34
# With the remote mode, I can't rely on files in the source directory.
 
35
zaptel_drivers() {
 
36
        perl -MZaptel::Hardware -e '
 
37
                my $hardware = Zaptel::Hardware->scan;
 
38
                print join(" ", $hardware->drivers);
 
39
                '
 
40
}
 
41
 
 
42
# Detect the modules used in the system:
 
43
for mod in `zaptel_drivers`; do
 
44
        case "$mod" in
 
45
                xpp_usb) 
 
46
                        MODULES_LOAD="$MODULES_LOAD xpp/xpp xpp/xpd_fxs"
 
47
                        MODULES_LOAD="$MODULES_LOAD xpp/xpd_fxo xpp/xpd_pri" 
 
48
                        MODULES_LOAD="$MODULES_LOAD xpp/xpp_usb"
 
49
                        ;;
 
50
                wctdm24xxp | wct4xxp | wcte12xp | wctc4xp)
 
51
                        MODULES_LOAD="$MODULES_LOAD $mod/$mod"
 
52
                        ;;
 
53
                wanpipe)
 
54
                        : # requires different handling
 
55
                        ;;
 
56
                *)
 
57
                        MODULES_LOAD="$MODULES_LOAD $mod"
 
58
                        ;;
 
59
        esac
 
60
done
 
61
 
 
62
# Initialize the Xorcom Astribank (xpp/) using perl utiliites:
 
63
# intended to replace all the the three functions below if user has 
 
64
# installed the zaptel-perl utilities.
 
65
xpp_startup() {
 
66
        # do nothing if there are no astribank devices:
 
67
        if ! grep -q connected /proc/xpp/xbuses 2>/dev/null; then return 0; fi
 
68
 
 
69
        echo "Waiting for Astribank devices to initialize:"
 
70
        cat /proc/xpp/XBUS-[0-9]*/waitfor_xpds 2>/dev/null || true
 
71
        
 
72
        # overriding locales for the above two, as perl can be noisy
 
73
        # when locales are missing.
 
74
        # No register all the devices if they didn't auto-register:
 
75
        LC_ALL=C zt_registration on
 
76
 
 
77
        # this one could actually be run after ztcfg:
 
78
        LC_ALL=C xpp_sync "$XPP_SYNC"
 
79
}
 
80
 
 
81
# recursively unload a module and its dependencies, if possible.
 
82
# where's modprobe -r when you need it?
 
83
# inputs: module to unload.
 
84
# returns: the result from 
 
85
unload_module() {
 
86
        module="$1"
 
87
        line=`lsmod 2>/dev/null | grep "^$1 "`
 
88
        if [ "$line" = '' ]; then return; fi # module was not loaded
 
89
 
 
90
        set -- $line
 
91
        # $1: the original module, $2: size, $3: refcount, $4: deps list
 
92
        mods=`echo $4 | tr , ' '`
 
93
        # xpp_usb keeps the xpds below busy if an xpp hardware is
 
94
        # connected. Hence must be removed before them:
 
95
        case "$module" in xpd_*) mods="xpp_usb $mods";; esac
 
96
        for mod in $mods; do
 
97
                # run in a subshell, so it won't step over our vars:
 
98
                (unload_module $mod) 
 
99
                # TODO: the following is probably the error handling we want:
 
100
                # if [ $? != 0 ]; then return 1; fi
 
101
        done
 
102
        rmmod $module
 
103
}
 
104
 
 
105
usage() {
 
106
        me=`basename $0`
 
107
        echo "$me: Run Zaptel in a test environment"
 
108
        echo 'Version: $Id: live_zap 4257 2008-05-12 22:19:00Z tzafrir $'
 
109
        echo ''
 
110
        echo "Usage:           equivalent of:"
 
111
        echo "$me install    make install"
 
112
        echo "$me config     make config"
 
113
        echo "$me unload     /etc/init.d/zaptel stop"
 
114
        echo "$me load       /etc/init.d/zaptel start"
 
115
        echo "$me reload     /etc/init.d/zaptel restart"
 
116
        echo "$me rsync TARGET   (copies file to /tmp/live in TARGET)"
 
117
        echo "$me exec  COMMAND  (Runs COMMAND in 'live' environment)"
 
118
}
 
119
 
 
120
case "$1" in
 
121
install)
 
122
        shift
 
123
        make install DESTDIR=$DESTDIR DYNFS=yes "$@"
 
124
        ;;
 
125
config)
 
126
        shift
 
127
        make config DESTDIR=$DESTDIR "$@"
 
128
        mkdir -p $DESTDIR/etc/asterisk
 
129
        ;;
 
130
rsync)
 
131
        if [ $# -ne 2 ]; then
 
132
                echo >&2 "$0: Error: rsync requires a target parameter".
 
133
                exit 1
 
134
        fi
 
135
        # copy the script itself and the installed directory to the
 
136
        # target host:
 
137
        rsync -ai "$0" $DESTDIR "$2:/tmp/"
 
138
        ;;
 
139
unload)
 
140
        $AST_SCRIPT stop
 
141
        for mod in $REMOVE_MODULES; do
 
142
                unload_module $mod
 
143
        done
 
144
        ;;
 
145
load)
 
146
        # TODO: Find a way to use modprobe.
 
147
        # Or implement a way to pass arguments to modules here (yuck)
 
148
        for module in $MODULES_LOAD; do
 
149
                eval module_args="\$`basename ${module}`_ARGS"
 
150
                insmod $MODULES_DIR/$module.ko $module_args
 
151
        done
 
152
        xpp_startup
 
153
        ZAPTEL_DEFAULTS=$DESTDIR/live.conf \
 
154
        ZAPTEL_BOOT_DEBIAN=$DESTDIR/live.conf \
 
155
        ZAPTEL_BOOT_FEDORA=$DESTDIR/live.conf \
 
156
        ZAPCONF_FILE=$DESTDIR/etc/zaptel.conf \
 
157
        ZAPATA_FILE=$DESTDIR/etc/asterisk/zapata-channels.conf \
 
158
                zapconf
 
159
        ztcfg -c $DESTDIR/etc/zaptel.conf
 
160
        # TODO: fxotune, hpec
 
161
        # or find a way to reuse init.d start sequence.
 
162
 
 
163
        # TODO: A local copy of Asterisk, configured with zapconf. 
 
164
        # doable, but trickier.
 
165
        $AST_SCRIPT start
 
166
        ;;
 
167
reload)
 
168
        $0 unload
 
169
        $0 load
 
170
        ;;
 
171
exec)
 
172
        if [ $# -lt 2 ]; then
 
173
                # No command given: start a subshell in the environemnt
 
174
                # of the "live" system:
 
175
                echo >&2 "$0: Error: exec requires a command to run"
 
176
                exit 1
 
177
        fi
 
178
 
 
179
        # Command given: run it:
 
180
        shift
 
181
        "$@"
 
182
        ;;
 
183
help)
 
184
        usage
 
185
        ;;
 
186
*)
 
187
        echo >&2 "$0: Error: incorrect command \"$1\". Aborting"
 
188
        usage
 
189
        exit 1
 
190
esac