3ac7a0a1f22003ba6a465638ee8b42366ee52684
[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 KVERS=`uname -r`
150
151 JANSSON_VER=2.11
152
153 case "$1" in
154 test)
155         testcmd=echo
156         ;;
157 install)
158         testcmd=''
159         ;;
160 install-unpackaged)
161         unpackaged="yes"
162         ;;
163 '')
164         usage
165         exit 0
166         ;;
167 *)
168         usage
169         exit 1
170         ;;
171 esac
172
173 in_test_mode() {
174         test "$testcmd" != ''
175 }
176
177 check_installed_debs() {
178         for pack in "$@" ; do
179                 tocheck="${tocheck} ^${pack}$ ~P^${pack}$"
180         done
181         pkgs=$(aptitude -F '%c %p' search ${tocheck} 2>/dev/null | awk '/^p/{print $2}')
182         if [ ${#pkgs} -ne 0 ]; then
183                 echo $pkgs | sed -r -e "s/ ?[^ :]+:i386//g"
184         fi
185 }
186
187 # parsing the output of yum is close to impossible.
188 # We'll use rpm and hope for the best:
189 check_installed_rpms() {
190         for pack in "$@"
191         do
192                 if ! rpm -q $pack >/dev/null 2>/dev/null
193                 then echo $pack
194                 fi
195         done
196 }
197
198 check_installed_equery() {
199         for pack in "$@"
200         do
201                 # equery --quiet list $pack
202                 # is slower and
203                 # would require the optional app-portage/gentoolkit
204                 # /var/lib/portage/world would be the non-dep list
205                 pack_with_version=${pack/:/-} # replace a possible version with '-'
206                 if ! ls -d /var/db/pkg/${pack_with_version}* >/dev/null 2>/dev/null
207                 then echo $pack
208                 fi
209         done
210 }
211
212 check_installed_pacman() {
213         for pack in "$@"
214         do
215                 if ! pacman -Q --explicit $pack >/dev/null 2>/dev/null
216                 then echo $pack
217                 fi
218         done
219 }
220
221 check_installed_pkgs() {
222         for pack in "$@"
223         do
224                 if [ `pkg_info -a | grep $pack | wc -l` = 0 ]; then
225                 echo $pack
226                 fi
227         done
228 }
229
230 check_installed_fpkgs() {
231         for pack in "$@"
232         do
233                 if [ `pkg info -a | grep $pack | wc -l` = 0 ]; then
234                 echo $pack
235                 fi
236         done
237 }
238
239 check_installed_zypper() {
240         for pack in "$@"
241         do
242                 if ! zypper se -ixnC $pack >/dev/null 2>/dev/null
243                 then echo $pack
244                 fi
245         done
246 }
247
248 handle_debian() {
249         if ! [ -x "$(command -v aptitude)" ]; then
250                 apt-get install aptitude
251         fi
252         extra_packs=`check_installed_debs $PACKAGES_DEBIAN`
253         $testcmd aptitude update
254         if [ x"$extra_packs" != "x" ] ; then
255                 $testcmd aptitude install -y $extra_packs
256         fi
257 }
258
259 handle_rh() {
260         extra_packs=`check_installed_rpms $PACKAGES_RH`
261         if [ x"$extra_packs" != "x" ] ; then
262                 $testcmd yum install --skip-broken --assumeyes $extra_packs
263         fi
264 }
265
266 handle_gentoo() {
267         extra_packs=`check_installed_equery $PACKAGES_GENTOO`
268         if [ x"$extra_packs" != "x" ] ; then
269                 $testcmd emerge $extra_packs
270         fi
271 }
272
273 handle_arch() {
274         extra_packs=`check_installed_pacman $PACKAGES_ARCH`
275         if [ x"$extra_packs" != "x" ] ; then
276                 $testcmd pacman -S --asexplicit --noconfirm $extra_packs
277         fi
278 }
279
280 handle_nbsd() {
281         extra_packs=`check_installed_pkgs $PACKAGES_NBSD`
282         if [ x"$extra_packs" != "x" ] ; then
283                 if [ -z "$PKG_PATH" ] ; then
284                         # see NetBSD Problem Report #48177
285                         export PKG_PATH="http://cdn.NetBSD.org/pub/pkgsrc/packages/$(uname -s)/$(uname -p)/$(uname -r)/All"
286                 fi
287                 $testcmd pkg_add $extra_packs
288         fi
289 }
290
291 handle_obsd() {
292         extra_packs=`check_installed_pkgs $PACKAGES_OBSD`
293         if [ x"$extra_packs" != "x" ] ; then
294                 $testcmd pkg_add $extra_packs
295         fi
296 }
297
298 handle_fbsd() {
299         extra_packs=`check_installed_fpkgs $PACKAGES_FBSD`
300         if [ x"$extra_packs" != "x" ] ; then
301                 $testcmd pkg install -y $extra_packs
302         fi
303 }
304
305 handle_SUSE() {
306         extra_packs=`check_installed_zypper $PACKAGES_SUSE`
307         if [ x"$extra_packs" != "x" ] ; then
308                 $testcmd zypper install --no-confirm $extra_packs
309         fi
310 }
311
312 install_unpackaged() {
313         echo "*** Installing NBS (Network Broadcast Sound) ***"
314         svn co http://svn.digium.com/svn/nbs/trunk nbs-trunk
315         cd nbs-trunk
316         make all install
317         cd ..
318
319         # Only install libresample if it wasn't installed via package
320         if ! test -f /usr/include/libresample.h; then
321                 echo "*** Installing libresample ***"
322                 svn co http://svn.digium.com/svn/thirdparty/libresample/trunk libresample-trunk
323                 cd libresample-trunk
324                 ./configure
325                 make all install
326                 cd ..
327         fi
328
329         # Only install Jansson if it wasn't installed via package
330         if ! test -f /usr/include/jansson.h; then
331                 echo "*** Installing jansson ***"
332                 wget -O - http://www.digip.org/jansson/releases/jansson-${JANSSON_VER}.tar.gz | zcat | tar -xf -
333                 cd jansson-${JANSSON_VER}
334                 ./configure
335                 make all install
336                 cd ..
337                 if test -d /etc/ld.so.conf.d; then
338                         echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
339                 else # for example: Slackware 14.2
340                         echo "/usr/local/lib" > /etc/ld.so.conf
341                 fi
342                 /sbin/ldconfig
343         fi
344
345         # Only install libsrtp2 if it wasn't installed via package
346         if ! test -f /usr/include/srtp/srtp.h; then
347                 if ! test -f /usr/include/srtp2/srtp.h; then
348                         echo "*** Installing libsrtp2 ***"
349                         wget -O - http://github.com/cisco/libsrtp/archive/v2.tar.gz | zcat | tar -xf -
350                         cd libsrtp-2
351                         ./configure --enable-openssl
352                         make shared_library install
353                         cd ..
354                         if test -d /etc/ld.so.conf.d; then
355                                 echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
356                         else # for example: Slackware 14.2
357                                 echo "/usr/local/lib" > /etc/ld.so.conf
358                         fi
359                         /sbin/ldconfig
360                 fi
361         fi
362
363         if ! test -f /usr/include/pjlib.h; then
364                 echo "PJProject not installed, yet. Therefore, please, run"
365                 echo "./configure --with-pjproject-bundled"
366         fi
367 }
368
369 if in_test_mode; then
370         echo "#############################################"
371         echo "## $1: test mode."
372         echo "## Use the commands here to install your system."
373         echo "#############################################"
374 elif test "${unpackaged}" = "yes" ; then
375         install_unpackaged
376         exit 0
377 fi
378
379 OS=`uname -s`
380 unsupported_distro=''
381
382 # A number of distributions we don't (yet?) support.
383 if [ "$OS" != 'Linux' -a "$OS" != 'NetBSD' -a "$OS" != 'OpenBSD' -a "$OS" != 'FreeBSD' ]; then
384         echo >&2 "$0: Your OS ($OS) is currently not supported. Aborting."
385         exit 1
386 fi
387
388 if [ -f /etc/mandrake-release ]; then
389         unsupported_distro='Mandriva'
390 fi
391
392 if [ -f /etc/slackware-version ] || ([ -f /etc/os-release ] && . /etc/os-release && [ "$ID" = "slackware" ]); then
393         echo >&2 "$0: Your distribution (Slackware) is currently not supported. Aborting. Try manually:"
394         # libedit requires a newer version than Slackware 14.2, for example Slackware-current
395         # or you build it manually: <http://thrysoee.dk/editline/>
396         echo >&2 "$0: # slackpkg install make gcc pkg-config libedit util-linux sqlite libxml2 patch wget"
397         # required for libjansson
398         echo >&2 "$0: # ./contrib/scripts/install_prereq install-unpackaged"
399         exit 1
400 fi
401
402 if [ "$unsupported_distro" != '' ]; then
403         echo >&2 "$0: Your distribution ($unsupported_distro) is currently not supported. Aborting."
404         exit 1
405 fi
406
407 # The distributions we do support:
408 if [ -r /etc/debian_version ]; then
409         handle_debian
410 elif [ -r /etc/redhat-release ]; then
411         handle_rh
412 elif [ -f /etc/SuSE-release -o -f /etc/novell-release ]; then
413         handle_SUSE
414 elif [ -f /etc/os-release ] && . /etc/os-release && [ "$ID" = "opensuse" ]; then
415         handle_SUSE
416 elif [ -r /etc/arch-release ]; then
417         handle_arch
418 elif [ -f /etc/os-release ] && . /etc/os-release && [ "$ID_LIKE" = "archlinux" ]; then
419         handle_arch # $ID=arch
420 elif [ -f /etc/gentoo-release ]; then
421         handle_gentoo
422 elif [ -f /etc/os-release ] && . /etc/os-release && [ "$ID" = "gentoo" ]; then
423         handle_gentoo
424 elif [ "$OS" = 'NetBSD' ]; then
425         handle_nbsd
426 elif [ "$OS" = 'OpenBSD' ]; then
427         handle_obsd
428 elif [ "$OS" = 'FreeBSD' ]; then
429         handle_fbsd
430 fi
431
432 if ! in_test_mode; then
433         echo "#############################################"
434         echo "## $1 completed successfully"
435         echo "#############################################"
436 fi