Debian Codegraph @

contrib/scripts/live_ast

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/bin/sh
2
3 # live_ast: run asterisk from a newly-built copy with minimal changes.
4
5 # Copyright (C) 2007 Tzafrir Cohen <[email protected]>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 # USA
21
22 # This script allows you to install Asterisk into a subdirectory of
23 # your source distribution and run it from there.
24 #
25 # Example usage:
26 #
27 # contrib/scripts/live_ast conf-file # optionally. and now edit live/live.conf
28 # # edit live/live.conf
29 # contrib/scripts/live_ast configure
30 # make
31 # contrib/scripts/live_ast install
32 # contrib/scripts/live_ast samples
33 # contrib/scripts/live_ast run
34 # contrib/scripts/live_ast run -r
35 # ./live/asterisk -r # Same as run -r
36 #
37 # A standard debugging cycle of a code in a module:
38 #
39 # # edit apps/app_skel.c
40 # contrib/scripts/live_ast install
41 # contrib/scripts/live_ast run -r
42 # # and in the CLI:
43 # module unload app_skel.so
44 # module load app_skel.so
45 #
46 # If you have external scripts that run asterisk, use the script
47 # live/asterisk that is generated by the 'samples' command. In this case you
48 # should probably also rem-out the line 'astvarrundir' and maybe also
49 # 'astetcdir' in live/etc/asterisk.conf .
50 #
51 ####################### Begin Samples
52 # optional environment variables. Set those in live/live.conf or in
53 # your envirnment.
54 #
55 # LIVE_AST_LIBPRI_PATH:
56 # To use a libpri SVN directory (without running 'make install': make include
57 # a symlink to the current directory:
58 # ln -s . /path/to/checkout/of/libpri/include
59 # Be sure to run there 'make'. Then set in live.conf:
60 #LIVE_AST_LIBPRI_PATH="/path/to/checkout/of/libpri"
61 #
62 # LIVE_AST_ZAPTEL_PATH:
63 # Likewise, the same trick can be used to build vs. a local copy of zaptel:
64 # ln -s /path/to/checkout/of/zaptel/include .
65 # ln -s /path/to/checkout/of/zaptel/zaptel .
66 #LIVE_AST_ZAPTEL_PATH="/path/to/checkout/of/zaptel"
67 #
68 #LIVE_AST_DAHDI_PATH="/path/to/dahdi-linux/dir"
69 #LIVE_AST_DAHDITOOLS_PATH="/path/to/dahdi-tools/dir"
70 #
71 # Another alternative for Zaptel is to use the live_zap script included
72 # with the Zaptel distribution. The following should work after you used
73 # './live_zap install' or even with a copy generated with
74 # './live_zap rsync' . '/apth/to/zaptel' is the directory containing the
75 # live/ subdirectory:
76 #
77 #LIVE_AST_ZAPLIVE_PATH="/path/to/zaptel"
78 #
79 # LIVE_AST_LD_PATH_EXTRA:
80 # space-separated or colon-separated directories to add to
81 # LD_LIBRARY_PATH. It is added before any existing components of
82 # LD_LIBRARY_PATH.
83 #LIVE_AST_LD_PATH_EXTRA="$HOME/lib:$HOME/libtest /opt/testapp"
84 #
85 # LIVE_AST_CONFIGURE_PARAMS:
86 # Extra parameters to pass to ./configure.
87 #LIVE_AST_CONFIGURE_PARAMS="--enable-dev-mode"
88 #
89 # LIVE_AST_FORCE_DEF_CONF:
90 # If set to a non-empty value, always regenerate menuselect config.
91 # This avoids emenselect's nag about "configuration has changed" that
92 # happens occasionally after an svn update.
93 #LIVE_AST_FORCE_DEF_CONF=yes
94 #
95 # LIVE_AST_BRISTUFFED_LIBPRI
96 # A hack to use the second, "bristuffed" copy of libpri that exists
97 # e.g. in the Debian libpri-dev package. If set to a non-empty value,
98 # live_ast will edit makeopts to use that second copy after ./configure
99 # is run.
100 #LIVE_AST_BRISTUFFED_LIBPRI=yes
101 #
102 # LIVE_AST_VALGRIND_ARGS:
103 # Parameters to pass to valgrind if using the 'valgrind' command.
104 #LIVE_AST_VALGRIND_ARGS="-v --leak-check=full --suppressions=contrib/valgrind.supp --log-file=valgrind.log"
105 #
106 # LIVE_AST_FOR_SYSTEM
107 # When generating asterisk.conf, use most components from the installed
108 # system. Also provide a sane var-run directory for those of us who want
109 # to do the right thing and run asterisk as non-root.
110 #LIVE_AST_FOR_SYSTEM=yes
111 ####################### End Samples
112
113 BASE_DIR="${AST_LIVE_BASE_DIR:-$PWD/live}"
114 AST_CONF_DIR="$BASE_DIR/etc/asterisk"
115 AST_CONF="$AST_CONF_DIR/asterisk.conf"
116 AST_BIN="$BASE_DIR/usr/sbin/asterisk"
117 GDB_INIT="$BASE_DIR/gdbinit"
118 LIVE_CONF="$BASE_DIR/live.conf"
119 DISABLED_MODS="chan_h323 pbx_dundi"
120 DISABLED_MODS_FILE="modules-disabled.conf"
121
122 if [ -r "$LIVE_CONF" ]; then . "$LIVE_CONF"; fi
123
124 if [ "$LIVE_AST_LIBPRI_PATH" != '' ]; then
125 LIVE_AST_CONFIGURE_PARAMS="$LIVE_AST_CONFIGURE_PARAMS --with-pri=$LIVE_AST_LIBPRI_PATH"
126 LIVE_AST_LD_PATH_EXTRA="$LIVE_AST_LD_PATH_EXTRA $LIVE_AST_LIBPRI_PATH"
127 fi
128
129 if [ "$LIVE_AST_ZAPTEL_PATH" != '' ]; then
130 LIVE_AST_CONFIGURE_PARAMS="$LIVE_AST_CONFIGURE_PARAMS --with-tonezone=$LIVE_AST_ZAPTEL_PATH"
131 LIVE_AST_CONFIGURE_PARAMS="$LIVE_AST_CONFIGURE_PARAMS --with-zaptel=$LIVE_AST_ZAPTEL_PATH"
132 LIVE_AST_CONFIGURE_PARAMS="$LIVE_AST_CONFIGURE_PARAMS --with-zaptel_transcode=$LIVE_AST_ZAPTEL_PATH"
133 LIVE_AST_CONFIGURE_PARAMS="$LIVE_AST_CONFIGURE_PARAMS --with-zaptel_vldtmf=$LIVE_AST_ZAPTEL_PATH"
134 LIVE_AST_LD_PATH_EXTRA="$LIVE_AST_LD_PATH_EXTRA $LIVE_AST_ZAPTEL_PATH"
135 fi
136
137 if [ "$LIVE_AST_DAHDI_PATH" != '' ]; then
138 LIVE_AST_CONFIGURE_PARAMS="$LIVE_AST_CONFIGURE_PARAMS --with-dahdi=$LIVE_AST_DAHDI_PATH"
139 fi
140
141 if [ "$LIVE_AST_DAHDITOOLS_PATH" != '' ]; then
142 LIVE_AST_CONFIGURE_PARAMS="$LIVE_AST_CONFIGURE_PARAMS --with-tonezone=$LIVE_AST_DAHDITOOLS_PATH"
143 LIVE_AST_LD_PATH_EXTRA="$LIVE_AST_LD_PATH_EXTRA $LIVE_AST_DAHDITOOLS_PATH"
144 fi
145
146 if [ "$LIVE_AST_ZAPLIVE_PATH" != '' ]; then
147 ZAPLIVE_USR_DIR="$LIVE_AST_ZAPLIVE_PATH/live/usr"
148 LIVE_AST_CONFIGURE_PARAMS="$LIVE_AST_CONFIGURE_PARAMS --with-tonezone=$ZAPLIVE_USR_DIR"
149 LIVE_AST_CONFIGURE_PARAMS="$LIVE_AST_CONFIGURE_PARAMS --with-zaptel=$ZAPALIVE_USR_DIR"
150 LIVE_AST_CONFIGURE_PARAMS="$LIVE_AST_CONFIGURE_PARAMS --with-zaptel_transcode=$ZAPALIVE_USR_DIR"
151 LIVE_AST_CONFIGURE_PARAMS="$LIVE_AST_CONFIGURE_PARAMS --with-zaptel_vldtmf=$ZAPALIVE_USR_DIR"
152 LIVE_AST_LD_PATH_EXTRA="$LIVE_AST_LD_PATH_EXTRA $ZAPLIVE_USR_DIR/lib"
153 fi
154
155 # gets rid of excessive spaces. Leves nothing if there were only white spaces:
156 LIVE_AST_LD_PATH_EXTRA=`echo $LIVE_AST_LD_PATH_EXTRA | tr ' ' :`
157 LIVE_AST_LD_PATH_EXTRA="$BASE_DIR/usr/lib:$LIVE_AST_LD_PATH_EXTRA"
158
159 set_ld_env() {
160 if [ "$LD_LIBRARY_PATH" = '' ]; then
161 LD_LIBRARY_PATH="$LIVE_AST_LD_PATH_EXTRA"
162 else
163 LD_LIBRARY_PATH=`echo $LD_LIBRARY_PATH | tr ' ' :`
164 LD_LIBRARY_PATH="$LIVE_AST_LD_PATH_EXTRA:$LD_LIBRARY_PATH"
165 fi
166 export LD_LIBRARY_PATH
167 }
168
169 # if live.conf does not exist, generate it from the sample
170 gen_live_conf() {
171 if [ -r $LIVE_CONF ]; then return; fi
172 # TODO: `dirname $LIVE_CONF` in case someone redefines it?
173 mkdir -p $BASE_DIR
174 sed -n -e '/^#* Begin Samples/,/^#* End Samples/p' "$0" \
175 | sed -e '/^#* \(Begin\|End\) Samples/d' >"$LIVE_CONF"
176 }
177
178 # (re?)generate the ./live/asterisk wrapper script
179 gen_live_asterisk() {
180 cat <<EOF >"$BASE_DIR/asterisk"
181 #!/bin/sh
182 # a wrapper to run asterisk from the "live" copy:
183 EOF
184 if realpath $0 >/dev/null 2>&1; then
185 cat <<EOF >>"$BASE_DIR/asterisk"
186 export AST_LIVE_BASE_DIR="$PWD/live"
187 real_me='`realpath $0`'
188 exec "\$real_me" run "\$@"
189 EOF
190 else # No realpath. Fall back to change working directory:
191 cat <<EOF >>"$BASE_DIR/asterisk"
192 cd "$PWD"
193 exec "$0" run "\$@"
194 EOF
195 fi
196 }
197
198 command="$1"
199 if [ $# -gt 0 ]; then
200 shift
201 fi
202
203 case "$command" in
204 configure)
205 ./configure $LIVE_AST_CONFIGURE_PARAMS "$@"
206 if [ "$LIVE_AST_FORCE_DEF_CONF" != '' ]; then
207 rm -f menuselect.makeopts
208 fi
209 if [ "$LIVE_AST_BRISTUFFED_LIBPRI" != '' ]; then
210 sed -i \
211 -e 's|^\(PRI_INCLUDE=\).*|\1-I/usr/include/bristuffed|' \
212 -e 's|^\(PRI_LIB=\).*|\1-lpri-bristuffed|' \
213 makeopts
214 fi
215 ;;
216 install)
217 make install DESTDIR="$BASE_DIR" "$@"
218 ;;
219 samples)
220 make samples DESTDIR="$BASE_DIR" "$@"
221 sed -r -i \
222 -e '/^\[directories\]\(!\)/s/\(!\).*//' \
223 -e "/^\[directories\]/a; rem-out any of the following to use Asterisk's defaults:" \
224 -e "/^ast(cache|etc|mod|varlib|data|agi|run|spool|log|db|key)dir\>/s| /| $BASE_DIR/|" \
225 "$AST_CONF"
226 if [ "$LIVE_AST_FOR_SYSTEM" != '' ]; then
227 sed -r -i \
228 -e "/^ast(etc|varlib|data|agi|run|spool|log|db|key)dir\>/s|^|;|" \
229 -e "/^;astrundir\>/aastrundir => /var/run/asterisk" \
230 "$AST_CONF"
231 fi
232 # disable some modules that bind on a port that is already in use by a
233 # main Asterisk copy, and would crash asterisk in failing:
234 rm -f "$AST_CONF_DIR/$DISABLED_MODS_FILE"
235 for mod in $DISABLED_MODS; do
236 echo "noload => $mod.so" >> "$AST_CONF_DIR/$DISABLED_MODS_FILE"
237 done
238 echo "#include $DISABLED_MODS_FILE" >> "$AST_CONF_DIR/modules.conf"
239
240 cat <<EOF >"$GDB_INIT"
241 set args -C "$AST_CONF" -c
242 EOF
243 gen_live_asterisk
244 chmod +x "$BASE_DIR/asterisk"
245 # Generate a sample config file for live_ast itself:
246 gen_live_conf
247 ;;
248 conf-file)
249 # Just regenerate live.conf from the sample if it does not already exist:
250 gen_live_conf
251 ;;
252 run)
253 set_ld_env
254 exec $AST_BIN -C $AST_CONF "$@"
255 ;;
256 valgrind)
257 set_ld_env
258 exec valgrind $LIVE_AST_VALGRIND_ARGS $AST_BIN -C $AST_CONF "$@"
259 ;;
260 rsync)
261 remote_host="$1"
262 remote_dir="$2"
263 me=`basename $0`
264 # FIXME: assumes varrundir is /var/run/asterisk
265 rsync -ai "$0" \
266 --exclude '/live/asterisk' \
267 --exclude '/live/var/run/asterisk/*' --exclude '/live/var/log/asterisk/*' \
268 live "$remote_host:$remote_dir/"
269 ssh $remote_host "cd '$remote_dir' && ./$me gen-live-asterisk"
270 ;;
271 gen-live-asterisk)
272 gen_live_asterisk
273 ;;
274 gdb)
275 set_ld_env
276 exec gdb -x $GDB_INIT $AST_BIN
277 ;;
278 *)
279 echo "$0: Unknown command '$command'. Aborting"
280 echo
281 echo "$0: Usage: Equivalent of:"
282 echo "$0 configure [params] ./configure [params]"
283 echo "$0 install make install"
284 echo "$0 samples make samples"
285 echo "$0 run [params] asterisk [params]"
286 echo "$0 gdb gdb asterisk"
287 echo "$0 valgrind valgrind asterisk"
288 echo "$0 rsync [user@]host dir copy files over to [user@]host:dir"
289 echo "$0 gen-live-asterisk regenerate the wrapper ./live/asterisk"
290 echo "$0 conf-file create live.conf if it does not exist"
291 exit 1
292 ;;
293 esac