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