06eb05e71445877eae1c5e03617864368d106e4b
[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 libncurses-dev libz-dev libssl-dev libxml2-dev libsqlite3-dev uuid-dev uuid"
25 # Asterisk: for addons:
26 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libcurl-dev libspeex-dev libspeexdsp-dev libogg-dev libvorbis-dev libasound2-dev portaudio19-dev libcurl4-openssl-dev"
27 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libpq-dev unixodbc-dev libsqlite0-dev libmysqlclient15-dev libneon27-dev libgmime-dev libusb-dev liblua5.1-0-dev lua5.1"
28 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libopenh323-dev libvpb-dev libgtk2.0-dev libmysqlclient-dev libbluetooth-dev libradiusclient-ng-dev freetds-dev"
29 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libsnmp-dev libiksemel-dev libcorosync-dev libnewt-dev libpopt-dev libical-dev libspandsp-dev libjack-dev"
30 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libresample-dev libc-client-dev binutils-dev libsrtp-dev libgsm1-dev libedit-dev doxygen libjansson-dev libldap-dev"
31 PACKAGES_DEBIAN="$PACKAGES_DEBIAN subversion git libxslt1-dev"
32 PACKAGES_RH="automake gcc gcc-c++ ncurses-devel openssl-devel libxml2-devel unixODBC-devel libcurl-devel libogg-devel libvorbis-devel speex-devel"
33 PACKAGES_RH="$PACKAGES_RH spandsp-devel freetds-devel net-snmp-devel iksemel-devel corosynclib-devel newt-devel popt-devel libtool-ltdl-devel lua-devel"
34 PACKAGES_RH="$PACKAGES_RH sqlite-devel libsqlite3x-devel radiusclient-ng-devel portaudio-devel postgresql-devel libresample-devel neon-devel libical-devel"
35 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"
36 PACKAGES_RH="$PACKAGES_RH jansson-devel libsrtp-devel pjproject-devel subversion git libxslt-devel"
37
38 PACKAGES_OBSD="popt gmake wget libxml libogg libvorbis curl iksemel spandsp speex iodbc freetds-0.63p1-msdblib mysql-client gmime sqlite sqlite3 jack libxslt"
39
40 KVERS=`uname -r`
41
42 JANSSON_VER=2.4
43
44 case "$1" in
45 test)
46         testcmd=echo
47         ;;
48 install)
49         testcmd=''
50         ;;
51 install-unpackaged)
52         unpackaged="yes"
53         ;;
54 '')
55         usage
56         exit 0
57         ;;
58 *)
59         usage
60         exit 1
61         ;;
62 esac
63
64 in_test_mode() {
65         test "$testcmd" != ''
66 }
67
68 check_installed_debs() {
69         for pack in "$@"
70         do
71                 tocheck="${tocheck} ^${pack}$"
72         done
73         pkgs=$(aptitude -F '%c %p' search ${tocheck} 2>/dev/null | awk '/^p/{print $2}')
74         if ! [ ${#pkgs} -eq 0 ]; then
75                 echo $pkgs | grep -v ':i386$'
76         fi
77 }
78
79 # parsing the output of yum is close to impossible.
80 # We'll use rpm and hope for the best:
81 check_installed_rpms() {
82         for pack in "$@"
83         do
84                 if ! rpm -q $pack >/dev/null 2>/dev/null
85                 then echo $pack
86                 fi
87         done
88 }
89
90 check_installed_pkgs() {
91         for pack in "$@"
92         do
93                 if [ `pkg_info -a | grep $pack | wc -l` = 0 ]; then
94                 echo $pack
95                 fi
96         done
97 }
98
99 handle_debian() {
100         if ! [ -x "$(command -v aptitude)" ]; then
101                 apt-get install aptitude
102         fi
103         extra_packs=`check_installed_debs $PACKAGES_DEBIAN`
104         $testcmd aptitude update
105         $testcmd aptitude install -y $extra_packs
106 }
107
108 handle_rh() {
109         extra_packs=`check_installed_rpms $PACKAGES_RH`
110         $testcmd yum install -y $extra_packs
111 }
112
113 handle_obsd() {
114         extra_packs=`check_installed_pkgs $PACKAGES_OBSD`
115         $testcmd pkg_add $extra_packs
116 }
117
118 install_unpackaged() {
119         echo "*** Installing NBS (Network Broadcast Sound) ***"
120         svn co http://svn.digium.com/svn/nbs/trunk nbs-trunk
121         cd nbs-trunk
122         make && make install
123         cd ..
124
125         # Only install libresample if it wasn't installed via package
126         if ! test -f /usr/include/libresample.h; then
127                 echo "*** Installing libresample ***"
128                 svn co http://svn.digium.com/svn/thirdparty/libresample/trunk libresample-trunk
129                 cd libresample-trunk
130                 ./configure && make && make install
131                 cd ..
132         fi
133
134         # Only install Jansson if it wasn't installed via package
135         if ! test -f /usr/include/jansson.h; then
136                 echo "*** Installing jansson ***"
137                 wget -O - http://www.digip.org/jansson/releases/jansson-${JANSSON_VER}.tar.gz | zcat | tar -xf -
138                 cd jansson-${JANSSON_VER}
139                 ./configure && make all && make install
140                 cd ..
141                 echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
142                 /sbin/ldconfig
143         fi
144
145         # Only install libsrtp if it wasn't installed via package
146         if ! test -f /usr/include/srtp/srtp.h; then
147                 echo "*** Installing libsrtp ***"
148                 if [ ! -d libsrtp ]; then
149                         git clone https://github.com/cisco/libsrtp.git
150                         cd libsrtp
151                 else
152                         cd libsrtp
153                         git pull
154                 fi
155                 ./configure CFLAGS=-fPIC && make libsrtp.a && make uninstall && make install
156                 cd ..
157                 echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
158                 /sbin/ldconfig
159         fi
160
161         # Only install pjproject if it wasn't installed via package
162         if ! test -f /usr/include/pjlib.h; then
163                 echo "*** Installing pjproject ***"
164                 if [ ! -d pjproject ]; then
165                         git clone https://github.com/asterisk/pjproject.git
166                         cd pjproject
167                 else
168                         cd pjproject
169                         git pull
170                 fi
171                 ./configure CFLAGS="-DNDEBUG -DPJ_HAS_IPV6=1" --enable-shared --with-external-speex --with-external-gsm --with-external-srtp --disable-sound --disable-resample && make && make install
172                 cd ..
173                 echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
174                 /sbin/ldconfig
175         fi
176 }
177
178 if in_test_mode; then
179         echo "#############################################"
180         echo "## $1: test mode."
181         echo "## Use the commands here to install your system."
182         echo "#############################################"
183 elif test "${unpackaged}" = "yes" ; then
184         install_unpackaged
185         exit 0
186 fi
187
188 OS=`uname -s`
189 unsupported_distro=''
190
191 # A number of distributions we don't (yet?) support.
192 if [ "$OS" != 'Linux' -a "$OS" != 'OpenBSD' ]; then
193         echo >&2 "$0: Your OS ($OS) is currently not supported. Aborting."
194         exit 1
195 fi
196
197 if [ -f /etc/gentoo-release ]; then
198         unsupported_distro='Gentoo'
199 fi
200
201 if [ -f /etc/mandrake-release ]; then
202         unsupported_distro='Mandriva'
203 fi
204
205 if [ -f /etc/SuSE-release ]; then
206         unsupported_distro='SUSE'
207 fi
208
209 if [ -f /etc/slackware-version ]; then
210         unsupported_distro='Slackware'
211 fi
212
213 if [ "$unsupported_distro" != '' ]; then
214         echo >&2 "$0: Your distribution ($unsupported_distro) is currently not supported. Aborting."
215         exit 1
216 fi
217
218 # The distributions we do support:
219 if [ -r /etc/debian_version ]; then
220         handle_debian
221 elif [ -r /etc/redhat-release ]; then
222         handle_rh
223 elif [ "$OS" = 'OpenBSD' ]; then
224         handle_obsd
225 fi
226
227 if ! in_test_mode; then
228         echo "#############################################"
229         echo "## $1 completed successfully"
230         echo "#############################################"
231 fi