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