app_voicemail/IMAP: check mailstream not NULL in leave_voicemail
[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 pkg-config"
23 # Asterisk: basic requirements:
24 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libedit-dev libjansson-dev libsqlite3-dev uuid-dev libxml2-dev"
25 # Asterisk: for addons:
26 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libspeex-dev libspeexdsp-dev libogg-dev libvorbis-dev libasound2-dev portaudio19-dev libcurl4-openssl-dev xmlstarlet bison flex"
27 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libpq-dev unixodbc-dev libneon27-dev libgmime-2.6-dev liblua5.2-dev liburiparser-dev libxslt1-dev libssl-dev"
28 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libvpb-dev libmysqlclient-dev libbluetooth-dev libradcli-dev freetds-dev libosptk-dev libjack-jackd2-dev bash"
29 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libsnmp-dev libiksemel-dev libcorosync-common-dev libcpg-dev libcfg-dev libnewt-dev libpopt-dev libical-dev libspandsp-dev"
30 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libresample1-dev libc-client2007e-dev binutils-dev libsrtp0-dev libsrtp2-dev libgsm1-dev doxygen graphviz zlib1g-dev libldap2-dev"
31 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libcodec2-dev libfftw3-dev libsndfile1-dev libunbound-dev"
32 # Asterisk: for the unpackaged below:
33 PACKAGES_DEBIAN="$PACKAGES_DEBIAN wget subversion"
34 # Asterisk: for ./configure --with-pjproject-bundled:
35 PACKAGES_DEBIAN="$PACKAGES_DEBIAN bzip2 patch python-dev"
36
37 # Basic build system:
38 PACKAGES_RH="make gcc gcc-c++ pkgconfig"
39 # Asterisk: basic requirements:
40 PACKAGES_RH="$PACKAGES_RH libedit-devel jansson-devel libuuid-devel sqlite-devel libxml2-devel"
41 # Asterisk: for addons:
42 PACKAGES_RH="$PACKAGES_RH speex-devel speexdsp-devel libogg-devel libvorbis-devel alsa-lib-devel portaudio-devel libcurl-devel xmlstarlet bison flex"
43 PACKAGES_RH="$PACKAGES_RH postgresql-devel unixODBC-devel neon-devel gmime-devel lua-devel uriparser-devel libxslt-devel openssl-devel"
44 PACKAGES_RH="$PACKAGES_RH mysql-devel bluez-libs-devel radcli-devel freetds-devel jack-audio-connection-kit-devel bash"
45 PACKAGES_RH="$PACKAGES_RH net-snmp-devel iksemel-devel corosynclib-devel newt-devel popt-devel libical-devel spandsp-devel"
46 PACKAGES_RH="$PACKAGES_RH libresample-devel uw-imap-devel binutils-devel libsrtp-devel gsm-devel doxygen graphviz zlib-devel openldap-devel hoard"
47 PACKAGES_RH="$PACKAGES_RH codec2-devel fftw-devel libsndfile-devel unbound-devel"
48 # Asterisk: for the unpackaged below:
49 PACKAGES_RH="$PACKAGES_RH wget subversion"
50 # Asterisk: for ./configure --with-pjproject-bundled:
51 PACKAGES_RH="$PACKAGES_RH bzip2 patch python-devel"
52
53 # Basic build system:
54 PACKAGES_SUSE="make gcc gcc-c++ pkg-config"
55 # Asterisk: basic requirements:
56 PACKAGES_SUSE="$PACKAGES_SUSE libedit-devel libjansson-devel libuuid-devel sqlite3-devel libxml2-devel"
57 # Asterisk: for addons:
58 PACKAGES_SUSE="$PACKAGES_SUSE speex-devel speexdsp-devel libogg-devel libvorbis-devel alsa-devel portaudio-devel libcurl-devel xmlstarlet bison flex"
59 PACKAGES_SUSE="$PACKAGES_SUSE postgresql-devel unixODBC-devel libneon-devel gmime-devel lua-devel liburiparser-devel libxslt-devel libopenssl-devel"
60 PACKAGES_SUSE="$PACKAGES_SUSE libmysqlclient-devel bluez-devel freeradius-client-devel freetds-devel bash"
61 PACKAGES_SUSE="$PACKAGES_SUSE net-snmp-devel iksemel-devel libcorosync-devel newt-devel popt-devel libical-devel spandsp-devel"
62 PACKAGES_SUSE="$PACKAGES_SUSE imap-devel libsrtp2-devel libgsm-devel doxygen graphviz zlib-devel openldap2-devel"
63 PACKAGES_SUSE="$PACKAGES_SUSE codec2-devel fftw3-devel libsndfile-devel unbound-devel"
64 # Asterisk: for the unpackaged below:
65 PACKAGES_SUSE="$PACKAGES_SUSE wget subversion"
66 # Asterisk: for ./configure --with-pjproject-bundled:
67 PACKAGES_SUSE="$PACKAGES_SUSE bzip2 patch python-devel"
68
69 # Basic build system:
70 PACKAGES_ARCH="make gcc pkg-config"
71 # Asterisk: basic requirements:
72 PACKAGES_ARCH="$PACKAGES_ARCH libedit jansson libutil-linux libxml2 sqlite"
73 # Asterisk: for addons:
74 PACKAGES_ARCH="$PACKAGES_ARCH speex speexdsp libogg libvorbis alsa-lib portaudio curl xmlstarlet bison flex"
75 PACKAGES_ARCH="$PACKAGES_ARCH postgresql-libs unixodbc neon gmime lua uriparser libxslt openssl"
76 PACKAGES_ARCH="$PACKAGES_ARCH libmariadbclient bluez-libs radcli freetds bash"
77 PACKAGES_ARCH="$PACKAGES_ARCH net-snmp libnewt popt libical spandsp"
78 PACKAGES_ARCH="$PACKAGES_ARCH c-client binutils libsrtp gsm doxygen graphviz zlib libldap"
79 PACKAGES_ARCH="$PACKAGES_ARCH fftw libsndfile unbound"
80 # Asterisk: for the unpackaged below:
81 PACKAGES_ARCH="$PACKAGES_ARCH wget subversion"
82 # Asterisk: for ./configure --with-pjproject-bundled:
83 PACKAGES_ARCH="$PACKAGES_ARCH bzip2 patch python2"
84
85 # Basic build system:
86 PACKAGES_GENTOO="sys-devel/make sys-devel/gcc dev-util/pkgconfig"
87 # Asterisk: basic requirements:
88 PACKAGES_GENTOO="$PACKAGES_GENTOO dev-libs/libedit dev-libs/jansson sys-libs/e2fsprogs-libs dev-libs/libxml2 dev-db/sqlite"
89 # Asterisk: for addons:
90 PACKAGES_GENTOO="$PACKAGES_GENTOO media-libs/speex media-libs/speexdsp media-libs/libogg media-libs/libvorbis media-libs/alsa-lib media-libs/portaudio net-misc/curl app-text/xmlstarlet sys-devel/bison sys-devel/flex"
91 PACKAGES_GENTOO="$PACKAGES_GENTOO dev-db/postgresql dev-db/unixODBC net-libs/neon dev-libs/gmime dev-lang/lua dev-libs/uriparser dev-libs/libxslt dev-libs/openssl"
92 PACKAGES_GENTOO="$PACKAGES_GENTOO virtual/libmysqlclient net-wireless/bluez net-dialup/radiusclient-ng dev-db/freetds app-shells/bash"
93 PACKAGES_GENTOO="$PACKAGES_GENTOO net-analyzer/net-snmp dev-libs/iksemel sys-cluster/corosync dev-libs/newt dev-libs/popt dev-libs/libical media-libs/spandsp"
94 PACKAGES_GENTOO="$PACKAGES_GENTOO net-libs/c-client sys-devel/binutils net-libs/libsrtp media-sound/gsm media-libs/libilbc app-doc/doxygen sys-libs/zlib net-nds/openldap"
95 PACKAGES_GENTOO="$PACKAGES_GENTOO sci-libs/fftw media-libs/libsndfile net-dns/unbound"
96 # Asterisk: for the unpackaged below:
97 PACKAGES_GENTOO="$PACKAGES_GENTOO net-misc/wget dev-vcs/subversion"
98 # Asterisk: for ./configure --with-pjproject-bundled:
99 PACKAGES_GENTOO="$PACKAGES_GENTOO app-arch/bzip2 sys-devel/patch dev-lang/python:2.7"
100
101 # Basic build system:
102 PACKAGES_NBSD="gmake pkg-config"
103 # Asterisk: basic requirements:
104 PACKAGES_NBSD="$PACKAGES_NBSD editline jansson sqlite3 libuuid libxml2"
105 # Asterisk: for addons:
106 PACKAGES_NBSD="$PACKAGES_NBSD speex speexdsp libogg libvorbis alsa-lib portaudio-devel curl bison flex"
107 PACKAGES_NBSD="$PACKAGES_NBSD postgresql10-client unixodbc neon gmime lua52 uriparser libxslt openssl"
108 PACKAGES_NBSD="$PACKAGES_NBSD mysql-client radiusclient-ng freetds bash"
109 PACKAGES_NBSD="$PACKAGES_NBSD net-snmp iksemel popt libical spandsp"
110 PACKAGES_NBSD="$PACKAGES_NBSD imap-uw srtp gsm doxygen graphviz libzip openldap-client"
111 PACKAGES_NBSD="$PACKAGES_NBSD codec2 fftw libsndfile unbound"
112 # Asterisk: for the unpackaged below:
113 PACKAGES_NBSD="$PACKAGES_NBSD wget subversion-base"
114 # Asterisk: for ./configure --with-pjproject-bundled:
115 PACKAGES_NBSD="$PACKAGES_NBSD bzip2 patch python27"
116
117 # Basic build system:
118 PACKAGES_OBSD="gmake"
119 # Asterisk: basic requirements:
120 PACKAGES_OBSD="$PACKAGES_OBSD libxml sqlite3 e2fsprogs jansson"
121 # Asterisk: for addons:
122 PACKAGES_OBSD="$PACKAGES_OBSD speex speexdsp libogg libvorbis portaudio-svn curl xmlstarlet bison"
123 PACKAGES_OBSD="$PACKAGES_OBSD postgresql-client iodbc neon gmime lua%5.2 uriparser libxslt"
124 PACKAGES_OBSD="$PACKAGES_OBSD mariadb-client radcli freetds"
125 PACKAGES_OBSD="$PACKAGES_OBSD net-snmp iksemel popt libical spandsp"
126 PACKAGES_OBSD="$PACKAGES_OBSD c-client libsrtp gsm doxygen graphviz"
127 PACKAGES_OBSD="$PACKAGES_OBSD fftw3 libsndfile"
128 # Asterisk: for the unpackaged below:
129 PACKAGES_OBSD="$PACKAGES_OBSD wget subversion"
130 # Asterisk: for ./configure --with-pjproject-bundled:
131 PACKAGES_OBSD="$PACKAGES_OBSD bzip2 python%2"
132
133 # Basic build system:
134 PACKAGES_FBSD="gmake pkgconf"
135 # Asterisk: basic requirements:
136 PACKAGES_FBSD="$PACKAGES_FBSD libedit jansson e2fsprogs-libuuid sqlite3 libxml2"
137 # Asterisk: for addons:
138 PACKAGES_FBSD="$PACKAGES_FBSD speex speexdsp libogg libvorbis alsa-lib portaudio curl xmlstarlet bison flex"
139 PACKAGES_FBSD="$PACKAGES_FBSD postgresql10-client unixODBC neon gmime26 lua52 uriparser libxslt openssl"
140 PACKAGES_FBSD="$PACKAGES_FBSD mysql57-client radcli freetds"
141 PACKAGES_FBSD="$PACKAGES_FBSD net-snmp iksemel corosync newt popt libical spandsp"
142 PACKAGES_FBSD="$PACKAGES_FBSD cclient libbfd libsrtp gsm libilbc doxygen graphviz libzip openldap-client libhoard"
143 PACKAGES_FBSD="$PACKAGES_FBSD codec2 fftw3 libsndfile unbound"
144 # Asterisk: for the unpackaged below:
145 PACKAGES_FBSD="$PACKAGES_FBSD wget subversion"
146 # Asterisk: for ./configure --with-pjproject-bundled:
147 PACKAGES_FBSD="$PACKAGES_FBSD bzip2 patch python"
148
149 # Basic build system:
150 PACKAGES_DBSD="gmake pkgconf"
151 # Asterisk: basic requirements:
152 PACKAGES_DBSD="$PACKAGES_DBSD libedit jansson e2fsprogs-libuuid sqlite3 libxml2"
153 # Asterisk: for addons:
154 PACKAGES_DBSD="$PACKAGES_DBSD speex speexdsp libogg libvorbis alsa-lib portaudio curl xmlstarlet bison flex"
155 PACKAGES_DBSD="$PACKAGES_DBSD postgresql10-client unixODBC neon gmime26 lua52 uriparser libxslt libressl"
156 PACKAGES_DBSD="$PACKAGES_DBSD mariadb101-client radcli freetds"
157 PACKAGES_DBSD="$PACKAGES_DBSD net-snmp iksemel corosync newt popt libical spandsp"
158 PACKAGES_DBSD="$PACKAGES_DBSD cclient binutils libsrtp gsm libilbc doxygen graphviz libzip openldap-client libhoard"
159 PACKAGES_DBSD="$PACKAGES_DBSD codec2 fftw3 libsndfile unbound"
160 # Asterisk: for the unpackaged below:
161 PACKAGES_DBSD="$PACKAGES_DBSD wget subversion"
162 # Asterisk: for ./configure --with-pjproject-bundled:
163 PACKAGES_DBSD="$PACKAGES_DBSD bzip2 patch python"
164
165 KVERS=`uname -r`
166
167 case "$1" in
168 test)
169         testcmd=echo
170         ;;
171 install)
172         testcmd=''
173         ;;
174 install-unpackaged)
175         unpackaged="yes"
176         ;;
177 '')
178         usage
179         exit 0
180         ;;
181 *)
182         usage
183         exit 1
184         ;;
185 esac
186
187 in_test_mode() {
188         test "$testcmd" != ''
189 }
190
191 check_installed_debs() {
192         for pack in "$@" ; do
193                 tocheck="${tocheck} ^${pack}$ ~P^${pack}$"
194         done
195         pkgs=$(aptitude -F '%c %p' search ${tocheck} 2>/dev/null | awk '/^p/{print $2}')
196         if [ ${#pkgs} -ne 0 ]; then
197                 echo $pkgs | sed -r -e "s/ ?[^ :]+:i386//g"
198         fi
199 }
200
201 # parsing the output of yum is close to impossible.
202 # We'll use rpm and hope for the best:
203 check_installed_rpms() {
204         for pack in "$@"
205         do
206                 if ! rpm -q $pack >/dev/null 2>/dev/null
207                 then echo $pack
208                 fi
209         done
210 }
211
212 check_installed_equery() {
213         for pack in "$@"
214         do
215                 # equery --quiet list $pack
216                 # is slower and
217                 # would require the optional app-portage/gentoolkit
218                 # /var/lib/portage/world would be the non-dep list
219                 pack_with_version=${pack/:/-} # replace a possible version with '-'
220                 if ! ls -d /var/db/pkg/${pack_with_version}* >/dev/null 2>/dev/null
221                 then echo $pack
222                 fi
223         done
224 }
225
226 check_installed_pacman() {
227         for pack in "$@"
228         do
229                 if ! pacman -Q --explicit $pack >/dev/null 2>/dev/null
230                 then echo $pack
231                 fi
232         done
233 }
234
235 check_installed_pkgs() {
236         for pack in "$@"
237         do
238                 if [ `pkg_info -a | grep $pack | wc -l` = 0 ]; then
239                 echo $pack
240                 fi
241         done
242 }
243
244 check_installed_fpkgs() {
245         for pack in "$@"
246         do
247                 if [ `pkg info -a | grep $pack | wc -l` = 0 ]; then
248                 echo $pack
249                 fi
250         done
251 }
252
253 check_installed_zypper() {
254         for pack in "$@"
255         do
256                 if ! zypper se -ixnC $pack >/dev/null 2>/dev/null
257                 then echo $pack
258                 fi
259         done
260 }
261
262 handle_debian() {
263         if ! [ -x "$(command -v aptitude)" ]; then
264                 apt-get install aptitude
265         fi
266         extra_packs=`check_installed_debs $PACKAGES_DEBIAN`
267         $testcmd aptitude update
268         if [ x"$extra_packs" != "x" ] ; then
269                 $testcmd aptitude install -y $extra_packs
270         fi
271 }
272
273 handle_rh() {
274         extra_packs=`check_installed_rpms $PACKAGES_RH`
275         if [ x"$extra_packs" != "x" ] ; then
276                 $testcmd yum install --skip-broken --assumeyes $extra_packs
277         fi
278 }
279
280 handle_gentoo() {
281         extra_packs=`check_installed_equery $PACKAGES_GENTOO`
282         if [ x"$extra_packs" != "x" ] ; then
283                 $testcmd emerge $extra_packs
284         fi
285 }
286
287 handle_arch() {
288         extra_packs=`check_installed_pacman $PACKAGES_ARCH`
289         if [ x"$extra_packs" != "x" ] ; then
290                 $testcmd pacman -S --asexplicit --noconfirm $extra_packs
291         fi
292 }
293
294 handle_nbsd() {
295         extra_packs=`check_installed_pkgs $PACKAGES_NBSD`
296         if [ x"$extra_packs" != "x" ] ; then
297                 if [ -z "$PKG_PATH" ] ; then
298                         # see NetBSD Problem Report #48177
299                         export PKG_PATH="http://cdn.NetBSD.org/pub/pkgsrc/packages/$(uname -s)/$(uname -p)/$(uname -r)/All"
300                 fi
301                 $testcmd pkg_add $extra_packs
302         fi
303 }
304
305 handle_obsd() {
306         extra_packs=`check_installed_pkgs $PACKAGES_OBSD`
307         if [ x"$extra_packs" != "x" ] ; then
308                 $testcmd pkg_add $extra_packs
309         fi
310 }
311
312 handle_fbsd() {
313         extra_packs=`check_installed_fpkgs $PACKAGES_FBSD`
314         if [ x"$extra_packs" != "x" ] ; then
315                 $testcmd pkg install -y $extra_packs
316         fi
317 }
318
319 handle_dbsd() {
320         extra_packs=`check_installed_fpkgs $PACKAGES_DBSD`
321         if [ x"$extra_packs" != "x" ] ; then
322                 $testcmd pkg install -y $extra_packs
323         fi
324 }
325
326 handle_SUSE() {
327         extra_packs=`check_installed_zypper $PACKAGES_SUSE`
328         if [ x"$extra_packs" != "x" ] ; then
329                 $testcmd zypper install --no-confirm $extra_packs
330         fi
331 }
332
333 install_unpackaged() {
334         echo "*** Installing NBS (Network Broadcast Sound) ***"
335         svn co http://svn.digium.com/svn/nbs/trunk nbs-trunk
336         cd nbs-trunk
337         make all install
338         cd ..
339
340         # Only install libresample if it wasn't installed via package
341         if ! test -f /usr/include/libresample.h; then
342                 echo "*** Installing libresample ***"
343                 svn co http://svn.digium.com/svn/thirdparty/libresample/trunk libresample-trunk
344                 cd libresample-trunk
345                 ./configure
346                 make all install
347                 cd ..
348         fi
349
350         # Only install libsrtp2 if it wasn't installed via package
351         if ! test -f /usr/include/srtp/srtp.h; then
352                 if ! test -f /usr/include/srtp2/srtp.h; then
353                         echo "*** Installing libsrtp2 ***"
354                         wget -O - http://github.com/cisco/libsrtp/archive/v2.tar.gz | zcat | tar -xf -
355                         cd libsrtp-2
356                         ./configure --enable-openssl
357                         make shared_library install
358                         cd ..
359                         if test -d /etc/ld.so.conf.d; then
360                                 echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
361                         else # for example: Slackware 14.2
362                                 echo "/usr/local/lib" > /etc/ld.so.conf
363                         fi
364                         /sbin/ldconfig
365                 fi
366         fi
367
368         if ! test -f /usr/include/pjlib.h; then
369                 echo "PJProject not installed, yet. Therefore, please, run"
370                 echo "./configure --with-pjproject-bundled"
371         fi
372 }
373
374 if in_test_mode; then
375         echo "#############################################"
376         echo "## $1: test mode."
377         echo "## Use the commands here to install your system."
378         echo "#############################################"
379 elif test "${unpackaged}" = "yes" ; then
380         install_unpackaged
381         exit 0
382 fi
383
384 OS=`uname -s`
385 unsupported_distro=''
386
387 # A number of distributions we don't (yet?) support.
388 if [ "$OS" != 'Linux' -a "$OS" != 'NetBSD' -a "$OS" != 'OpenBSD' -a "$OS" != 'FreeBSD' -a "$OS" != 'DragonFly' ]; then
389         echo >&2 "$0: Your OS ($OS) is currently not supported. Aborting."
390         exit 1
391 fi
392
393 if [ -f /etc/mandrake-release ]; then
394         unsupported_distro='Mandriva'
395 fi
396
397 if [ -f /etc/slackware-version ] || ([ -f /etc/os-release ] && . /etc/os-release && [ "$ID" = "slackware" ]); then
398         echo >&2 "$0: Your distribution (Slackware) is currently not supported. Aborting. Try manually:"
399         # libedit requires a newer version than Slackware 14.2, for example Slackware-current
400         # or you build it manually: <http://thrysoee.dk/editline/>
401         echo >&2 "$0: # slackpkg install make gcc pkg-config libedit util-linux sqlite libxml2 patch wget"
402         # required for libjansson
403         echo >&2 "$0: # ./contrib/scripts/install_prereq install-unpackaged"
404         exit 1
405 fi
406
407 if [ "$unsupported_distro" != '' ]; then
408         echo >&2 "$0: Your distribution ($unsupported_distro) is currently not supported. Aborting."
409         exit 1
410 fi
411
412 # The distributions we do support:
413 if [ -r /etc/debian_version ]; then
414         handle_debian
415 elif [ -r /etc/redhat-release ]; then
416         handle_rh
417 elif [ -f /etc/SuSE-release -o -f /etc/novell-release ]; then
418         handle_SUSE
419 elif [ -f /etc/os-release ] && . /etc/os-release && [ "$ID" = "opensuse" ]; then
420         handle_SUSE
421 elif [ -r /etc/arch-release ]; then
422         handle_arch
423 elif [ -f /etc/os-release ] && . /etc/os-release && [ "$ID_LIKE" = "archlinux" ]; then
424         handle_arch # $ID=arch
425 elif [ -f /etc/gentoo-release ]; then
426         handle_gentoo
427 elif [ -f /etc/os-release ] && . /etc/os-release && [ "$ID" = "gentoo" ]; then
428         handle_gentoo
429 elif [ "$OS" = 'NetBSD' ]; then
430         handle_nbsd
431 elif [ "$OS" = 'OpenBSD' ]; then
432         handle_obsd
433 elif [ "$OS" = 'FreeBSD' ]; then
434         handle_fbsd
435 elif [ "$OS" = 'DragonFly' ]; then
436         handle_dbsd
437 fi
438
439 if ! in_test_mode; then
440         echo "#############################################"
441         echo "## $1 completed successfully"
442         echo "#############################################"
443 fi