install_prereq: Build jansson from source, when necessary
[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_RH="automake gcc gcc-c++ ncurses-devel openssl-devel libxml2-devel unixODBC-devel libcurl-devel libogg-devel libvorbis-devel speex-devel"
32 PACKAGES_RH="$PACKAGES_RH spandsp-devel freetds-devel net-snmp-devel iksemel-devel corosynclib-devel newt-devel popt-devel libtool-ltdl-devel lua-devel"
33 PACKAGES_RH="$PACKAGES_RH libsqlite3x-devel radiusclient-ng-devel portaudio-devel postgresql-devel libresample-devel neon-devel libical-devel"
34 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"
35 PACKAGES_RH="$PACKAGES_RH jansson-devel"
36
37 PACKAGES_OBSD="popt gmake wget libxml libogg libvorbis curl iksemel spandsp speex iodbc freetds-0.63p1-msdblib mysql-client gmime sqlite sqlite3 jack"
38
39 KVERS=`uname -r`
40
41 JANSSON_VER=2.4
42
43 case "$1" in
44 test)    testcmd=echo ;;
45 install) testcmd='' ;;
46 install-unpackaged) unpackaged="yes" ;;
47 '') usage; exit 0 ;;
48 *) usage; exit 1 ;;
49 esac
50
51 in_test_mode() {
52   test "$testcmd" != ''
53 }
54
55 check_installed_debs() {
56         for pack in "$@"
57         do
58                 tocheck="${tocheck} ^${pack}$"
59         done
60         aptitude -F '%c %p' search ${tocheck} 2>/dev/null \
61         | awk '/^p/{print $2}'
62 }
63
64 # parsing the output of yum is close to impossible.
65 # We'll use rpm and hope for the best:
66 check_installed_rpms() {
67         for pack in "$@"
68         do
69                 if ! rpm -q $pack >/dev/null 2>/dev/null
70                 then echo $pack
71                 fi
72         done
73 }
74
75 check_installed_pkgs() {
76         for pack in "$@"
77         do
78                 if [ `pkg_info -a | grep $pack | wc -l` = 0 ]; then
79                 echo $pack
80                 fi
81         done
82 }
83
84 handle_debian() {
85         extra_packs=`check_installed_debs $PACKAGES_DEBIAN`
86         $testcmd aptitude install -y $extra_packs
87 }
88
89 handle_rh() {
90         extra_packs=`check_installed_rpms $PACKAGES_RH`
91         $testcmd yum install -y $extra_packs
92 }
93
94 handle_obsd() {
95         extra_packs=`check_installed_pkgs $PACKAGES_OBSD`
96         $testcmd pkg_add $extra_packs
97 }
98
99 install_unpackaged() {
100         echo "*** Installing NBS (Network Broadcast Sound) ***"
101         svn co http://svn.digium.com/svn/nbs/trunk nbs-trunk
102         cd nbs-trunk
103         make && make install
104         cd ..
105
106         # Only install libresample if it wasn't installed via package
107         if ! test -f /usr/include/libresample.h; then
108             echo "*** Installing libresample ***"
109             svn co http://svn.digium.com/svn/thirdparty/libresample/trunk libresample-trunk
110             cd libresample-trunk
111             ./configure && make && make install
112             cd ..
113         fi
114
115         # Only install Jansson if it wasn't installed via package
116         if ! test -f /usr/include/jansson.h; then
117                 echo "*** Installing jansson ***"
118                 wget -O - http://www.digip.org/jansson/releases/jansson-${JANSSON_VER}.tar.gz | zcat | tar -xf -
119                 cd jansson-${JANSSON_VER}
120                 ./configure && make all && make install
121                 cd ..
122                 echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
123                 /sbin/ldconfig
124         fi
125 }
126
127 if in_test_mode; then
128         echo "#############################################"
129         echo "## $1: test mode."
130         echo "## Use the commands here to install your system."
131         echo "#############################################"
132 elif test "${unpackaged}" = "yes" ; then
133         install_unpackaged
134         exit 0
135 fi
136
137 OS=`uname -s`
138 unsupported_distro=''
139
140 # A number of distributions we don't (yet?) support.
141 if [ "$OS" != 'Linux' -a "$OS" != 'OpenBSD' ]; then
142   echo >&2 "$0: Your OS ($OS) is currently not supported. Aborting."
143   exit 1
144 fi
145
146 if [ -f /etc/gentoo-release ]; then
147   unsupported_distro='Gentoo'
148 fi
149
150 if [ -f /etc/mandrake-release ]; then
151   unsupported_distro='Mandriva'
152 fi
153
154 if [ -f /etc/SuSE-release ]; then
155   unsupported_distro='SUSE'
156 fi
157
158 if [ -f /etc/slackware-version ]; then
159   unsupported_distro='Slackware'
160 fi
161
162 if [ "$unsupported_distro" != '' ]; then
163   echo >&2 "$0: Your distribution ($unsupported_distro) is currently not supported. Aborting."
164   exit 1
165 fi
166
167 # The distributions we do support:
168 if [ -r /etc/debian_version ]; then
169   handle_debian
170 elif [ -r /etc/redhat-release ]; then
171   handle_rh
172 elif [ "$OS" = 'OpenBSD' ]; then
173   handle_obsd
174 fi
175
176 if ! in_test_mode; then
177   echo "#############################################"
178   echo "## $1 completed successfully"
179   echo "#############################################"
180 fi