dae8dee682ab1b3bfa051995689f6ad86fb706ab
[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 libltdl-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 libtool-ltdl-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 libtool 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_NBSD="gmake pkg-config"
71 # Asterisk: basic requirements:
72 PACKAGES_NBSD="$PACKAGES_NBSD editline jansson sqlite3 libuuid libxml2"
73 # Asterisk: for addons:
74 PACKAGES_NBSD="$PACKAGES_NBSD speex speexdsp libogg libvorbis alsa-lib portaudio-devel curl bison flex"
75 PACKAGES_NBSD="$PACKAGES_NBSD postgresql10-client unixodbc libltdl neon gmime lua52 uriparser libxslt openssl"
76 PACKAGES_NBSD="$PACKAGES_NBSD mysql-client radiusclient-ng freetds bash"
77 PACKAGES_NBSD="$PACKAGES_NBSD net-snmp iksemel popt libical spandsp"
78 PACKAGES_NBSD="$PACKAGES_NBSD imap-uw srtp gsm doxygen graphviz libzip openldap-client"
79 PACKAGES_NBSD="$PACKAGES_NBSD codec2 fftw libsndfile unbound"
80 # Asterisk: for the unpackaged below:
81 PACKAGES_NBSD="$PACKAGES_NBSD wget subversion-base"
82 # Asterisk: for ./configure --with-pjproject-bundled:
83 PACKAGES_NBSD="$PACKAGES_NBSD bzip2 patch python27"
84
85 # Basic build system:
86 PACKAGES_OBSD="gmake"
87 # Asterisk: basic requirements:
88 PACKAGES_OBSD="$PACKAGES_OBSD libxml sqlite3 e2fsprogs jansson"
89 # Asterisk: for addons:
90 PACKAGES_OBSD="$PACKAGES_OBSD speex speexdsp libogg libvorbis portaudio-svn curl xmlstarlet bison"
91 PACKAGES_OBSD="$PACKAGES_OBSD postgresql-client iodbc libltdl neon gmime lua%5.2 uriparser libxslt"
92 PACKAGES_OBSD="$PACKAGES_OBSD mariadb-client radcli freetds"
93 PACKAGES_OBSD="$PACKAGES_OBSD net-snmp iksemel popt libical spandsp"
94 PACKAGES_OBSD="$PACKAGES_OBSD c-client libsrtp gsm doxygen graphviz"
95 PACKAGES_OBSD="$PACKAGES_OBSD fftw3 libsndfile"
96 # Asterisk: for the unpackaged below:
97 PACKAGES_OBSD="$PACKAGES_OBSD wget subversion"
98 # Asterisk: for ./configure --with-pjproject-bundled:
99 PACKAGES_OBSD="$PACKAGES_OBSD bzip2 python%2"
100
101 # Basic build system:
102 PACKAGES_FBSD="gmake pkgconf"
103 # Asterisk: basic requirements:
104 PACKAGES_FBSD="$PACKAGES_FBSD libedit jansson e2fsprogs-libuuid sqlite3 libxml2"
105 # Asterisk: for addons:
106 PACKAGES_FBSD="$PACKAGES_FBSD speex speexdsp libogg libvorbis alsa-lib portaudio curl xmlstarlet bison flex"
107 PACKAGES_FBSD="$PACKAGES_FBSD postgresql10-client unixODBC libltdl neon gmime26 lua52 uriparser libxslt openssl"
108 PACKAGES_FBSD="$PACKAGES_FBSD mysql57-client radcli freetds"
109 PACKAGES_FBSD="$PACKAGES_FBSD net-snmp iksemel corosync newt popt libical spandsp"
110 PACKAGES_FBSD="$PACKAGES_FBSD cclient libbfd libsrtp gsm libilbc doxygen graphviz libzip openldap-client libhoard"
111 PACKAGES_FBSD="$PACKAGES_FBSD codec2 fftw3 libsndfile unbound"
112 # Asterisk: for the unpackaged below:
113 PACKAGES_FBSD="$PACKAGES_FBSD wget subversion"
114 # Asterisk: for ./configure --with-pjproject-bundled:
115 PACKAGES_FBSD="$PACKAGES_FBSD bzip2 patch python"
116
117 KVERS=`uname -r`
118
119 JANSSON_VER=2.11
120
121 case "$1" in
122 test)
123         testcmd=echo
124         ;;
125 install)
126         testcmd=''
127         ;;
128 install-unpackaged)
129         unpackaged="yes"
130         ;;
131 '')
132         usage
133         exit 0
134         ;;
135 *)
136         usage
137         exit 1
138         ;;
139 esac
140
141 in_test_mode() {
142         test "$testcmd" != ''
143 }
144
145 check_installed_debs() {
146         for pack in "$@" ; do
147                 tocheck="${tocheck} ^${pack}$ ~P^${pack}$"
148         done
149         pkgs=$(aptitude -F '%c %p' search ${tocheck} 2>/dev/null | awk '/^p/{print $2}')
150         if [ ${#pkgs} -ne 0 ]; then
151                 echo $pkgs | sed -r -e "s/ ?[^ :]+:i386//g"
152         fi
153 }
154
155 # parsing the output of yum is close to impossible.
156 # We'll use rpm and hope for the best:
157 check_installed_rpms() {
158         for pack in "$@"
159         do
160                 if ! rpm -q $pack >/dev/null 2>/dev/null
161                 then echo $pack
162                 fi
163         done
164 }
165
166 check_installed_pkgs() {
167         for pack in "$@"
168         do
169                 if [ `pkg_info -a | grep $pack | wc -l` = 0 ]; then
170                 echo $pack
171                 fi
172         done
173 }
174
175 check_installed_fpkgs() {
176         for pack in "$@"
177         do
178                 if [ `pkg info -a | grep $pack | wc -l` = 0 ]; then
179                 echo $pack
180                 fi
181         done
182 }
183
184 check_installed_zypper() {
185         for pack in "$@"
186         do
187                 if ! zypper se -ixnC $pack >/dev/null 2>/dev/null
188                 then echo $pack
189                 fi
190         done
191 }
192
193 handle_debian() {
194         if ! [ -x "$(command -v aptitude)" ]; then
195                 apt-get install aptitude
196         fi
197         extra_packs=`check_installed_debs $PACKAGES_DEBIAN`
198         $testcmd aptitude update
199         if [ x"$extra_packs" != "x" ] ; then
200                 $testcmd aptitude install -y $extra_packs
201         fi
202 }
203
204 handle_rh() {
205         extra_packs=`check_installed_rpms $PACKAGES_RH`
206         if [ x"$extra_packs" != "x" ] ; then
207                 $testcmd yum install --skip-broken --assumeyes $extra_packs
208         fi
209 }
210
211 handle_nbsd() {
212         extra_packs=`check_installed_pkgs $PACKAGES_NBSD`
213         if [ x"$extra_packs" != "x" ] ; then
214                 if [ -z "$PKG_PATH" ] ; then
215                         # see NetBSD Problem Report #48177
216                         export PKG_PATH="http://cdn.NetBSD.org/pub/pkgsrc/packages/$(uname -s)/$(uname -p)/$(uname -r)/All"
217                 fi
218                 $testcmd pkg_add $extra_packs
219         fi
220 }
221
222 handle_obsd() {
223         extra_packs=`check_installed_pkgs $PACKAGES_OBSD`
224         if [ x"$extra_packs" != "x" ] ; then
225                 $testcmd pkg_add $extra_packs
226         fi
227 }
228
229 handle_fbsd() {
230         extra_packs=`check_installed_fpkgs $PACKAGES_FBSD`
231         if [ x"$extra_packs" != "x" ] ; then
232                 $testcmd pkg install -y $extra_packs
233         fi
234 }
235
236 handle_SUSE() {
237         extra_packs=`check_installed_zypper $PACKAGES_SUSE`
238         if [ x"$extra_packs" != "x" ] ; then
239                 $testcmd zypper install --no-confirm $extra_packs
240         fi
241 }
242
243 install_unpackaged() {
244         echo "*** Installing NBS (Network Broadcast Sound) ***"
245         svn co http://svn.digium.com/svn/nbs/trunk nbs-trunk
246         cd nbs-trunk
247         make all install
248         cd ..
249
250         # Only install libresample if it wasn't installed via package
251         if ! test -f /usr/include/libresample.h; then
252                 echo "*** Installing libresample ***"
253                 svn co http://svn.digium.com/svn/thirdparty/libresample/trunk libresample-trunk
254                 cd libresample-trunk
255                 ./configure
256                 make all install
257                 cd ..
258         fi
259
260         # Only install Jansson if it wasn't installed via package
261         if ! test -f /usr/include/jansson.h; then
262                 echo "*** Installing jansson ***"
263                 wget -O - http://www.digip.org/jansson/releases/jansson-${JANSSON_VER}.tar.gz | zcat | tar -xf -
264                 cd jansson-${JANSSON_VER}
265                 ./configure
266                 make all install
267                 cd ..
268                 echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
269                 /sbin/ldconfig
270         fi
271
272         # Only install libsrtp2 if it wasn't installed via package
273         if ! test -f /usr/include/srtp/srtp.h; then
274                 if ! test -f /usr/include/srtp2/srtp.h; then
275                         echo "*** Installing libsrtp2 ***"
276                         wget -O - http://github.com/cisco/libsrtp/archive/v2.tar.gz | zcat | tar -xf -
277                         cd libsrtp-2
278                         ./configure --enable-openssl
279                         make shared_library install
280                         cd ..
281                         echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
282                         /sbin/ldconfig
283                 fi
284         fi
285
286         if ! test -f /usr/include/pjlib.h; then
287                 echo "PJProject not installed, yet. Therefore, please, run"
288                 echo "./configure --with-pjproject-bundled"
289         fi
290 }
291
292 if in_test_mode; then
293         echo "#############################################"
294         echo "## $1: test mode."
295         echo "## Use the commands here to install your system."
296         echo "#############################################"
297 elif test "${unpackaged}" = "yes" ; then
298         install_unpackaged
299         exit 0
300 fi
301
302 OS=`uname -s`
303 unsupported_distro=''
304
305 # A number of distributions we don't (yet?) support.
306 if [ "$OS" != 'Linux' -a "$OS" != 'NetBSD' -a "$OS" != 'OpenBSD' -a "$OS" != 'FreeBSD' ]; then
307         echo >&2 "$0: Your OS ($OS) is currently not supported. Aborting."
308         exit 1
309 fi
310
311 if [ -f /etc/gentoo-release ]; then
312         unsupported_distro='Gentoo'
313 fi
314
315 if [ -f /etc/mandrake-release ]; then
316         unsupported_distro='Mandriva'
317 fi
318
319 if [ -f /etc/slackware-version ]; then
320         unsupported_distro='Slackware'
321 fi
322
323 if [ "$unsupported_distro" != '' ]; then
324         echo >&2 "$0: Your distribution ($unsupported_distro) is currently not supported. Aborting."
325         exit 1
326 fi
327
328 # The distributions we do support:
329 if [ -r /etc/debian_version ]; then
330         handle_debian
331 elif [ -r /etc/redhat-release ]; then
332         handle_rh
333 elif [ -f /etc/SuSE-release -o -f /etc/novell-release ]; then
334         handle_SUSE
335 elif [ -f /etc/os-release ] && . /etc/os-release && [ "$ID" = "opensuse" ]; then
336         handle_SUSE
337 elif [ "$OS" = 'NetBSD' ]; then
338         handle_nbsd
339 elif [ "$OS" = 'OpenBSD' ]; then
340         handle_obsd
341 elif [ "$OS" = 'FreeBSD' ]; then
342         handle_fbsd
343 fi
344
345 if ! in_test_mode; then
346         echo "#############################################"
347         echo "## $1 completed successfully"
348         echo "#############################################"
349 fi