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