3 # live_ast: run asterisk from a newly-built copy with minimal changes.
5 # Copyright (C) 2007 Tzafrir Cohen <tzafrir.cohen@xorcom.com>
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.
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.
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
22 # This script allows you to install Asterisk into a subdirectory of
23 # your source distribution and run it from there.
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
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
37 # A standard debugging cycle of a code in a module:
39 # # edit apps/app_skel.c
40 # contrib/scripts/live_ast install
41 # contrib/scripts/live_ast run -r
43 # module unload app_skel.so
44 # module load app_skel.so
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 .
51 ####################### Begin Samples
52 # optional environment variables. Set those in live/live.conf or in
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"
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"
68 #LIVE_AST_DAHDI_PATH="/path/to/dahdi-linux/dir"
69 #LIVE_AST_DAHDITOOLS_PATH="/path/to/dahdi-tools/dir"
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
77 #LIVE_AST_ZAPLIVE_PATH="/path/to/zaptel"
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
83 #LIVE_AST_LD_PATH_EXTRA="$HOME/lib:$HOME/libtest /opt/testapp"
85 # LIVE_AST_CONFIGURE_PARAMS:
86 # Extra parameters to pass to ./configure.
87 #LIVE_AST_CONFIGURE_PARAMS="--enable-dev-mode"
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
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
100 #LIVE_AST_BRISTUFFED_LIBPRI=yes
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"
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
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"
122 if [ -r "$LIVE_CONF" ]; then . "$LIVE_CONF"; fi
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"
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"
137 if [ "$LIVE_AST_DAHDI_PATH" != '' ]; then
138 LIVE_AST_CONFIGURE_PARAMS="$LIVE_AST_CONFIGURE_PARAMS --with-dahdi=$LIVE_AST_DAHDI_PATH"
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"
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"
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"
160 if [ "$LD_LIBRARY_PATH" = '' ]; then
161 LD_LIBRARY_PATH="$LIVE_AST_LD_PATH_EXTRA"
163 LD_LIBRARY_PATH=`echo $LD_LIBRARY_PATH | tr ' ' :`
164 LD_LIBRARY_PATH="$LIVE_AST_LD_PATH_EXTRA:$LD_LIBRARY_PATH"
166 export LD_LIBRARY_PATH
169 # if live.conf does not exist, generate it from the sample
171 if [ -r $LIVE_CONF ]; then return; fi
172 # TODO: `dirname $LIVE_CONF` in case someone redefines it?
174 sed -n -e '/^#* Begin Samples/,/^#* End Samples/p' "$0" \
175 | sed -e '/^#* \(Begin\|End\) Samples/d' >"$LIVE_CONF"
178 # (re?)generate the ./live/asterisk wrapper script
179 gen_live_asterisk() {
180 cat <<EOF >"$BASE_DIR/asterisk"
182 # a wrapper to run asterisk from the "live" copy:
189 if [ $# -gt 0 ]; then
195 ./configure $LIVE_AST_CONFIGURE_PARAMS "$@"
196 if [ "$LIVE_AST_FORCE_DEF_CONF" != '' ]; then
197 rm -f menuselect.makeopts
199 if [ "$LIVE_AST_BRISTUFFED_LIBPRI" != '' ]; then
201 -e 's|^\(PRI_INCLUDE=\).*|\1-I/usr/include/bristuffed|' \
202 -e 's|^\(PRI_LIB=\).*|\1-lpri-bristuffed|' \
207 make install DESTDIR="$BASE_DIR" "$@"
210 make samples DESTDIR="$BASE_DIR" "$@"
212 -e '/^\[directories\]\(!\)/s/\(!\).*//' \
213 -e "/^\[directories\]/a; rem-out any of the following to use Asterisk's defaults:" \
214 -e "/^ast(etc|mod|varlib|data|agi|run|spool|log|db|key)dir\>/s| /| $BASE_DIR/|" \
216 if [ "$LIVE_AST_FOR_SYSTEM" != '' ]; then
218 -e "/^ast(etc|varlib|data|agi|run|spool|log|db|key)dir\>/s|^|;|" \
219 -e "/^;astrundir\>/aastrundir => /var/run/asterisk" \
222 # disable some modules that bind on a port that is already in use by a
223 # main Asterisk copy, and would crash asterisk in failing:
224 rm -f "$AST_CONF_DIR/$DISABLED_MODS_FILE"
225 for mod in $DISABLED_MODS; do
226 echo "noload => $mod.so" >> "$AST_CONF_DIR/$DISABLED_MODS_FILE"
228 echo "#include $DISABLED_MODS_FILE" >> "$AST_CONF_DIR/modules.conf"
230 cat <<EOF >"$GDB_INIT"
231 set args -C "$AST_CONF" -c
234 chmod +x "$BASE_DIR/asterisk"
235 # Generate a sample config file for live_ast itself:
239 # Just regenerate live.conf from the sample if it does not already exist:
244 $AST_BIN -C $AST_CONF "$@"
248 valgrind $LIVE_AST_VALGRIND_ARGS $AST_BIN -C $AST_CONF "$@"
254 # FIXME: assumes varrundir is /var/run/asterisk
256 --exclude '/live/asterisk' \
257 --exclude '/live/var/run/asterisk/*' --exclude '/live/var/log/asterisk/*' \
258 live "$remote_host:$remote_dir/"
259 ssh $remote_host "cd '$remote_dir' && ./$me gen-live-asterisk"
266 gdb -x $GDB_INIT $AST_BIN
269 echo "$0: Unknown command '$command'. Aborting"
271 echo "$0: Usage: Equivalent of:"
272 echo "$0 configure [params] ./configure [params]"
273 echo "$0 install make install"
274 echo "$0 samples make samples"
275 echo "$0 run [params] asterisk [params]"
276 echo "$0 gdb gdb asterisk"
277 echo "$0 valgrind valgrind asterisk"
278 echo "$0 rsync [user@]host dir copy files over to [user@]host:dir"
279 echo "$0 gen-live-asterisk regenerate the wrapper ./live/asterisk"
280 echo "$0 conf-file create live.conf if it does not exist"