Merge "Example script for scan-build (the llvm static analyzer)"
[asterisk/asterisk.git] / contrib / scripts / install_prereq
1 #! /bin/sh
2 #
3 # $Id$
4 #
5
6 # install_prereq: a script to install distribution-specific
7 # prerequirements
8
9 set -e
10
11 usage() {
12         echo "$0: a script to install distribution-specific prerequirement"
13         echo 'Revision: $Id$'
14         echo ""
15         echo "Usage: $0:                    Shows this message."
16         echo "Usage: $0 test                Prints commands it is about to run."
17         echo "Usage: $0 install             Really install."
18         echo "Usage: $0 install-unpackaged  Really install unpackaged requirements."
19 }
20
21 # Basic build system:
22 PACKAGES_DEBIAN="build-essential"
23 # Asterisk: basic requirements:
24 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libncurses-dev libz-dev libssl-dev libxml2-dev libsqlite3-dev uuid-dev uuid"
25 # Asterisk: for addons:
26 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libcurl-dev libspeex-dev libspeexdsp-dev libogg-dev libvorbis-dev libasound2-dev portaudio19-dev libcurl4-openssl-dev"
27 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libpq-dev unixodbc-dev libsqlite0-dev libmysqlclient15-dev libneon27-dev libgmime-dev libusb-dev liblua5.1-0-dev lua5.1"
28 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libopenh323-dev libvpb-dev libgtk2.0-dev libmysqlclient-dev libbluetooth-dev libradiusclient-ng-dev freetds-dev"
29 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libsnmp-dev libiksemel-dev libcorosync-dev libnewt-dev libpopt-dev libical-dev libspandsp-dev libjack-dev"
30 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libresample-dev libc-client-dev binutils-dev libsrtp-dev libgsm1-dev libedit-dev doxygen libjansson-dev libldap-dev"
31 PACKAGES_DEBIAN="$PACKAGES_DEBIAN subversion git libxslt1-dev"
32 PACKAGES_RH="automake gcc gcc-c++ ncurses-devel openssl-devel libxml2-devel unixODBC-devel libcurl-devel libogg-devel libvorbis-devel speex-devel"
33 PACKAGES_RH="$PACKAGES_RH spandsp-devel freetds-devel net-snmp-devel iksemel-devel corosynclib-devel newt-devel popt-devel libtool-ltdl-devel lua-devel"
34 PACKAGES_RH="$PACKAGES_RH libsqlite3x-devel radiusclient-ng-devel portaudio-devel postgresql-devel libresample-devel neon-devel libical-devel"
35 PACKAGES_RH="$PACKAGES_RH openldap-devel gmime22-devel sqlite2-devel mysql-devel bluez-libs-devel jack-audio-connection-kit-devel gsm-devel libedit-devel libuuid-devel"
36 PACKAGES_RH="$PACKAGES_RH jansson-devel libsrtp-devel pjproject-devel subversion git libxslt-devel"
37
38 PACKAGES_OBSD="popt gmake wget libxml libogg libvorbis curl iksemel spandsp speex iodbc freetds-0.63p1-msdblib mysql-client gmime sqlite sqlite3 jack libxslt"
39
40 KVERS=`uname -r`
41
42 JANSSON_VER=2.4
43
44 case "$1" in
45 test)
46         testcmd=echo
47         ;;
48 install)
49         testcmd=''
50         ;;
51 install-unpackaged)
52         unpackaged="yes"
53         ;;
54 '')
55         usage
56         exit 0
57         ;;
58 *)
59         usage
60         exit 1
61         ;;
62 esac
63
64 in_test_mode() {
65         test "$testcmd" != ''
66 }
67
68 check_installed_debs() {
69         for pack in "$@"
70         do
71                 tocheck="${tocheck} ^${pack}$"
72         done
73         aptitude -F '%c %p' search ${tocheck} 2>/dev/null \
74                 | awk '/^p/{print $2}' \
75                 | grep -v ':i386$'
76 }
77
78 # parsing the output of yum is close to impossible.
79 # We'll use rpm and hope for the best:
80 check_installed_rpms() {
81         for pack in "$@"
82         do
83                 if ! rpm -q $pack >/dev/null 2>/dev/null
84                 then echo $pack
85                 fi
86         done
87 }
88
89 check_installed_pkgs() {
90         for pack in "$@"
91         do
92                 if [ `pkg_info -a | grep $pack | wc -l` = 0 ]; then
93                 echo $pack
94                 fi
95         done
96 }
97
98 handle_debian() {
99         extra_packs=`check_installed_debs $PACKAGES_DEBIAN`
100         $testcmd aptitude install -y $extra_packs
101 }
102
103 handle_rh() {
104         extra_packs=`check_installed_rpms $PACKAGES_RH`
105         $testcmd yum install -y $extra_packs
106 }
107
108 handle_obsd() {
109         extra_packs=`check_installed_pkgs $PACKAGES_OBSD`
110         $testcmd pkg_add $extra_packs
111 }
112
113 install_unpackaged() {
114         echo "*** Installing NBS (Network Broadcast Sound) ***"
115         svn co http://svn.digium.com/svn/nbs/trunk nbs-trunk
116         cd nbs-trunk
117         make && make install
118         cd ..
119
120         # Only install libresample if it wasn't installed via package
121         if ! test -f /usr/include/libresample.h; then
122                 echo "*** Installing libresample ***"
123                 svn co http://svn.digium.com/svn/thirdparty/libresample/trunk libresample-trunk
124                 cd libresample-trunk
125                 ./configure && make && make install
126                 cd ..
127         fi
128
129         # Only install Jansson if it wasn't installed via package
130         if ! test -f /usr/include/jansson.h; then
131                 echo "*** Installing jansson ***"
132                 wget -O - http://www.digip.org/jansson/releases/jansson-${JANSSON_VER}.tar.gz | zcat | tar -xf -
133                 cd jansson-${JANSSON_VER}
134                 ./configure && make all && make install
135                 cd ..
136                 echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
137                 /sbin/ldconfig
138         fi
139
140         # Only install libsrtp if it wasn't installed via package
141         if ! test -f /usr/include/srtp/srtp.h; then
142                 echo "*** Installing libsrtp ***"
143                 if [ ! -d libsrtp ]; then
144                         git clone https://github.com/cisco/libsrtp.git
145                         cd libsrtp
146                 else
147                         cd libsrtp
148                         git pull
149                 fi
150                 ./configure CFLAGS=-fPIC && make libsrtp.a && make uninstall && make install
151                 cd ..
152                 echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
153                 /sbin/ldconfig
154         fi
155
156         # Only install pjproject if it wasn't installed via package
157         if ! test -f /usr/include/pjlib.h; then
158                 echo "*** Installing pjproject ***"
159                 if [ ! -d pjproject ]; then
160                         git clone https://github.com/asterisk/pjproject.git
161                         cd pjproject
162                 else
163                         cd pjproject
164                         git pull
165                 fi
166                 ./configure CFLAGS="-DNDEBUG -DPJ_HAS_IPV6=1" --enable-shared --with-external-speex --with-external-gsm --with-external-srtp --disable-sound --disable-resample && make && make install
167                 cd ..
168                 echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
169                 /sbin/ldconfig
170         fi
171 }
172
173 if in_test_mode; then
174         echo "#############################################"
175         echo "## $1: test mode."
176         echo "## Use the commands here to install your system."
177         echo "#############################################"
178 elif test "${unpackaged}" = "yes" ; then
179         install_unpackaged
180         exit 0
181 fi
182
183 OS=`uname -s`
184 unsupported_distro=''
185
186 # A number of distributions we don't (yet?) support.
187 if [ "$OS" != 'Linux' -a "$OS" != 'OpenBSD' ]; then
188         echo >&2 "$0: Your OS ($OS) is currently not supported. Aborting."
189         exit 1
190 fi
191
192 if [ -f /etc/gentoo-release ]; then
193         unsupported_distro='Gentoo'
194 fi
195
196 if [ -f /etc/mandrake-release ]; then
197         unsupported_distro='Mandriva'
198 fi
199
200 if [ -f /etc/SuSE-release ]; then
201         unsupported_distro='SUSE'
202 fi
203
204 if [ -f /etc/slackware-version ]; then
205         unsupported_distro='Slackware'
206 fi
207
208 if [ "$unsupported_distro" != '' ]; then
209         echo >&2 "$0: Your distribution ($unsupported_distro) is currently not supported. Aborting."
210         exit 1
211 fi
212
213 # The distributions we do support:
214 if [ -r /etc/debian_version ]; then
215         handle_debian
216 elif [ -r /etc/redhat-release ]; then
217         handle_rh
218 elif [ "$OS" = 'OpenBSD' ]; then
219         handle_obsd
220 fi
221
222 if ! in_test_mode; then
223         echo "#############################################"
224         echo "## $1 completed successfully"
225         echo "#############################################"
226 fi