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