Debian Codegraph @

build_tools/live_dahdi

raw
1 #!/bin/sh
2
3 LINUX_DIR=${LINUX_DIR:=.}
4 TOOLS_DIR=${TOOLS_DIR:=../dahdi-tools}
5 DYNAMIC_LOC="${DYNAMIC_LOC:-no}"
6 DESTDIR=$PWD/live
7 LIVE_DAHDI_RSYNC_DIR=${LIVE_DAHDI_RSYNC_DIR:-/tmp/dahdi}
8 KVERS=${KVERS:-`uname -r`}
9 XPP_SYNC=${XPP_SYNC:-auto}
10 AST_SCRIPT=${AST_SCRIPT:-/etc/init.d/asterisk}
11 # Use this file to pass options to modules:
12 PERLLIBDIR=`perl -V:sitelib | cut -d "'" -f 2`
13 EXTRA_MODS="crc_ccitt"
14
15 # Manual list of modules. They will be loaded by insmod.
16 # If reside in a subdir, add it explicitly.
17
18 MODULES_LOAD="${MODULES_LOAD:-dahdi dahdi_echocan_mg2}"
19
20 # this one *is* resolved recusively.
21 # the only reason to set a different value is if you use hpec / oslec,
22 # as Zaptel depends on them.
23 REMOVE_MODULES="${REMOVE_MODULES:-dahdi}" # "dahdi oslec"?
24
25 if [ -r $DESTDIR/live.conf ]; then . $DESTDIR/live.conf; fi
26
27 MODULES_DIR="$DESTDIR/lib/modules/$KVERS/dahdi"
28 if [ ! -d "$LINUX_DIR" ]; then
29 echo >&2 "$0:dahdi-linux dir '$LINUX_DIR' does not exits. Aborting".
30 exit 1
31 fi
32
33 set -e
34 LINUX_DIR_FULL=`(cd $LINUX_DIR; pwd)`
35
36 set_tools_dir() {
37 if [ ! -d "$TOOLS_DIR" ]; then
38 echo >&2 "$0:dahdi-tools dir '$TOOLS_DIR' does not exits. Aborting".
39 exit 1
40 fi
41 TOOLS_DIR_FULL=`(cd $TOOLS_DIR; pwd)`
42 }
43
44 # Give priority to our installed binaries:
45 PATH=$DESTDIR/sbin:$DESTDIR/usr/sbin:$PATH
46 export PATH
47
48 # TODO: If you already use PERL5DIR, please fix this part:
49 PERL5LIB="$DESTDIR/$PERLLIBDIR"
50 export PERL5LIB
51
52 # used in xpp_fxloader:
53 FIRMWARE_DIR="$DESTDIR/usr/share/dahdi"
54 export FIRMWARE_DIR
55
56 ASTRIBANK_TOOL="$DESTDIR/usr/sbin/astribank_tool"
57 export ASTRIBANK_TOOL
58
59 ASTRIBANK_HEXLOAD="$DESTDIR/usr/sbin/astribank_hexload"
60 export ASTRIBANK_HEXLOAD
61
62 # make sure Astribank initialization scripts are from our tree.
63 xpp_ARGS="$xpp_ARGS initdir=$FIRMWARE_DIR"
64 dahdi_ARGS="$dahdi_ARGS tools_rootdir=$DESTDIR"
65
66 if [ "$DYNAMIC_LOC" = 'yes' ]; then
67 MODULES_LOAD="$MODULES_LOAD dahdi_dynamic dahdi_dynamic_loc"
68 fi
69
70 # the same as xpp/utils/dahdi_drivers .
71 # With the remote mode, I can't rely on files in the source directory.
72 dahdi_drivers() {
73 perl -MDahdi::Hardware -e '
74 my @drivers = Dahdi::Hardware->drivers;
75 print join(" ", @drivers);
76 '
77 }
78
79 # Add modules for existing hardware on the system for the list of
80 # modules to load.
81 #
82 # As module loading is manual with insmod, some manual fixes are needed.
83 set_modules_to_load() {
84 for mod in `dahdi_drivers`; do
85 case "$mod" in
86 xpp_usb)
87 MODULES_LOAD="$MODULES_LOAD xpp/xpp xpp/xpd_fxs"
88 MODULES_LOAD="$MODULES_LOAD xpp/xpd_fxo xpp/xpd_pri"
89 if [ -r "$MODULES_DIR/xpp/xpd_bri.ko" ]; then
90 MODULES_LOAD="$MODULES_LOAD xpp/xpd_bri"
91 fi
92 if [ -r "$MODULES_DIR/xpp/xpd_echo.ko" ]; then
93 MODULES_LOAD="$MODULES_LOAD xpp/xpd_echo"
94 fi
95 MODULES_LOAD="$MODULES_LOAD xpp/xpp_usb"
96 ;;
97 wctdm24xxp | wcte12xp)
98 # FIXME: better automation of the voicebus
99 # dependency:
100 MODULES_LOAD="$MODULES_LOAD voicebus/dahdi_voicebus $mod/$mod"
101 EXTRA_MODS="$EXTRA_MODS firmware_class"
102 ;;
103 wct4xxp | wcte12xp | wctc4xp | wcb4xxp)
104 MODULES_LOAD="$MODULES_LOAD $mod/$mod"
105 ;;
106 wanpipe)
107 : # requires different handling
108 ;;
109 *)
110 MODULES_LOAD="$MODULES_LOAD $mod"
111 ;;
112 esac
113 done
114 }
115
116 # Initialize the Xorcom Astribank (xpp/) using perl utiliites:
117 # intended to replace all the the three functions below if user has
118 # installed the dahdi-perl utilities.
119 xpp_startup() {
120 # do nothing if there are no astribank devices:
121 if ! grep -q connected /proc/xpp/xbuses 2>/dev/null; then return 0; fi
122
123 echo "Waiting for Astribank devices to initialize:"
124 "$FIRMWARE_DIR/waitfor_xpds" # Asusmes a recent dahdi-tools
125
126 # overriding locales for the above two, as perl can be noisy
127 # when locales are missing.
128 # No register all the devices if they didn't auto-register:
129 LC_ALL=C dahdi_registration on
130
131 # this one could actually be run after dahdi_cfg:
132 LC_ALL=C xpp_sync "$XPP_SYNC"
133 }
134
135 # recursively unload a module and its dependencies, if possible.
136 # where's modprobe -r when you need it?
137 # inputs: module to unload.
138 # returns: the result from
139 unload_module() {
140 module="$1"
141 line=`lsmod 2>/dev/null | grep "^$1 " || :`
142 if [ "$line" = '' ]; then return; fi # module was not loaded
143
144 set -- $line
145 # $1: the original module, $2: size, $3: refcount, $4: deps list
146 mods=`echo $4 | tr , ' '`
147 ec_modules=""
148 # xpp_usb keeps the xpds below busy if an xpp hardware is
149 # connected. Hence must be removed before them:
150 case "$module" in xpd_*) mods="xpp_usb $mods";; esac
151
152 for mod in $mods; do
153 case "$mod" in
154 dahdi_echocan_*)
155 ec_modules="$mod $ec_modules"
156 ;;
157 *)
158 # run in a subshell, so it won't step over our vars:
159 (unload_module $mod)
160 ;;
161 esac
162 done
163 # Now that all the other dependencies are unloaded, we can unload the
164 # dahdi_echocan modules. The drivers that register spans may keep
165 # references on the echocan modules before they are unloaded.
166 for mod in $ec_modules; do
167 (unload_module $mod)
168 done
169 rmmod $module
170 }
171
172 load_dynamic() {
173 if [ "$DYNAMIC_LOC" != yes ]; then return; fi
174
175 local conf_file="$DESTDIR/etc/dahdi/dynamic.conf"
176 if [ ! -r "$conf_file" ]; then
177 cat <<EOF >"$conf_file"
178 dynamic=loc,1:0,5,0
179 dynamic=loc,1:1,5,0
180 EOF
181 fi
182
183 dahdi_cfg -c "$conf_file"
184 }
185
186 unload_dynamic() {
187 if [ "$DYNAMIC_LOC" != yes ]; then return; fi
188
189 local conf_file="$DESTDIR/etc/dahdi/dynamic.conf"
190 if [ ! -r "$conf_file" ]; then return; fi
191
192 dahdi_cfg -c "$conf_file" -s || :
193 }
194
195 genconf() {
196 GENCONF_PARAMETERS=$DESTDIR/etc/dahdi/genconf_parameters \
197 DAHDI_CONF_FILE=$DESTDIR/etc/dahdi/system.conf \
198 DAHDI_MODS_FILE=$DESTDIR/etc/dahdi/modules \
199 CHAN_DAHDI_CHANNELS_FILE=$DESTDIR/etc/asterisk/dahdi-channels.conf \
200 dahdi_genconf
201 if [ "$DYNAMIC_LOC" = yes ]; then
202 cat "$DESTDIR/etc/dahdi/dynamic.conf" >>"$DESTDIR/etc/dahdi/system.conf"
203 fi
204 dahdi_cfg -c $DESTDIR/etc/dahdi/system.conf
205 # TODO: fxotune, hpec
206 }
207
208 run_asterisk() {
209 $AST_SCRIPT start
210 }
211
212 usage() {
213 me=`basename $0`
214 echo "$me: Run DAHDI in a test environment"
215 echo 'Version: $Id$'
216 echo ''
217 echo "Usage: equivalent of:"
218 echo "$me configure ./configure"
219 echo "$me install make install"
220 echo "$me config make config"
221 echo "$me unload /etc/init.d/dahdi stop"
222 echo "$me load /etc/init.d/dahdi start"
223 echo "$me reload /etc/init.d/dahdi restart"
224 echo "$me xpp-firm (Reset and load xpp firmware)"
225 echo "$me genconf dahdi_genconf; dahdi_cfg"
226 echo "$me asterisk /etc/init.d/asterisk start"
227 echo "$me symlink_ast symlink dahdi-channels.conf"
228 echo "$me rsync TARGET (copy filea to /tmp/live in host TARGET)"
229 echo "$me exec COMMAND (Run COMMAND in 'live' environment)"
230 echo ""
231 echo "dahdi-linux: $LINUX_DIR"
232 echo "dahdi-tools: $TOOLS_DIR"
233 }
234
235 case "$1" in
236 configure)
237 shift
238 set_tools_dir
239 cd "$TOOLS_DIR"; ./configure --with-dahdi="$LINUX_DIR_FULL" "$@"
240 ;;
241 install)
242 shift
243 set_tools_dir
244 cd "$LINUX_DIR"; make install DESTDIR=$DESTDIR "$@"
245 cd "$TOOLS_DIR_FULL"; make install DESTDIR=$DESTDIR DYNFS=yes "$@"
246 ;;
247 config)
248 shift
249 set_tools_dir
250 cd "$TOOLS_DIR"; make config DESTDIR=$DESTDIR "$@"
251 mkdir -p $DESTDIR/etc/asterisk
252 cat >"$FIRMWARE_DIR/live-init.conf" <<EOF
253 PATH="$PATH" # FIXME: add to existing \$PATH?
254 export PATH
255 dahdiconfdir="${DESTDIR}/etc/dahdi"
256 export dahdiconfdir
257 EOF
258 ln -s ../../../etc/dahdi/xpp.conf "$DESTDIR/usr/share/dahdi/"
259 ;;
260 rsync)
261 if [ $# -ne 2 ]; then
262 echo >&2 "$0: Error: rsync requires a target parameter".
263 exit 1
264 fi
265 # copy the script itself and the installed directory to the
266 # target host:
267 rsync -ai "$0" $DESTDIR "$2:$LIVE_DAHDI_RSYNC_DIR"
268 ;;
269 unload)
270 # OK for Asterisk not to be running. TODO: a better test?
271 $AST_SCRIPT stop || :
272 unload_dynamic
273 for mod in $REMOVE_MODULES; do
274 unload_module $mod
275 done
276 ;;
277 load)
278 # TODO: Find a way to use modprobe.
279 # Or implement a way to pass arguments to modules here (yuck)
280 set_modules_to_load
281 for mod in $EXTRA_MODS; do
282 modprobe $mod || : # FIXME: Make this optional?
283 done
284 for module in $MODULES_LOAD; do
285 eval module_args="\$`basename ${module}`_ARGS"
286 insmod $MODULES_DIR/$module.ko $module_args
287 done
288 xpp_startup
289 load_dynamic
290 genconf
291 # or find a way to reuse init.d start sequence.
292
293 # TODO: A local copy of Asterisk, configured with dahdi_gnconf.
294 # doable, but trickier.
295 run_asterisk
296 if [ "$LIVE_DAHDI_FREEPBXDB" = 'yes' ]; then
297 GENCONF_PARAMETERS=$DESTDIR/etc/dahdi/genconf_parameters \
298 dahdi_genconf freepbxdb
299 fi
300 ;;
301 genconf)
302 genconf
303 ;;
304 asterisk)
305 run_asterisk
306 ;;
307 symlink_ast)
308 ln -sf "$DESTDIR/etc/asterisk/dahdi-channels.conf" /etc/asterisk/
309 ;;
310 reload)
311 $0 unload
312 $0 load
313 ;;
314 exec)
315 if [ $# -lt 2 ]; then
316 # No command given: start a subshell in the environemnt
317 # of the "live" system:
318 echo >&2 "$0: Error: exec requires a command to run"
319 exit 1
320 fi
321
322 # Command given: run it:
323 shift
324 "$@"
325 ;;
326 xpp-firm)
327 # Still broken. Needs to be run several times.
328 # set XPP_HOTPLUG_DISABLED=yes in /etc/dahdi/init.conf
329 XPP_FIRMWARE_DIR=$FIRMWARE_DIR \
330 "$FIRMWARE_DIR/xpp_fxloader" reset
331 sleep 5
332 XPP_FIRMWARE_DIR=$FIRMWARE_DIR \
333 XPP_CONFIG="$DESTDIR/etc/dahdi/xpp.conf" \
334 "$FIRMWARE_DIR/xpp_fxloader" load
335 ;;
336 help|'')
337 usage
338 ;;
339 *)
340 echo >&2 "$0: Error: incorrect command \"$1\". Aborting"
341 usage
342 exit 1
343 esac