Fix documentation replication issues
[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 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         aptitude -F '%c %p' search ${tocheck} 2>/dev/null \
74         | awk '/^p/{print $2}'
75 }
76
77 # parsing the output of yum is close to impossible.
78 # We'll use rpm and hope for the best:
79 check_installed_rpms() {
80         for pack in "$@"
81         do
82                 if ! rpm -q $pack >/dev/null 2>/dev/null
83                 then echo $pack
84                 fi
85         done
86 }
87
88 check_installed_pkgs() {
89         for pack in "$@"
90         do
91                 if [ `pkg_info -a | grep $pack | wc -l` = 0 ]; then
92                 echo $pack
93                 fi
94         done
95 }
96
97 handle_debian() {
98         extra_packs=`check_installed_debs $PACKAGES_DEBIAN`
99         $testcmd aptitude install -y $extra_packs
100 }
101
102 handle_rh() {
103         extra_packs=`check_installed_rpms $PACKAGES_RH`
104         $testcmd yum install -y $extra_packs
105 }
106
107 handle_obsd() {
108         extra_packs=`check_installed_pkgs $PACKAGES_OBSD`
109         $testcmd pkg_add $extra_packs
110 }
111
112 install_unpackaged() {
113         echo "*** Installing NBS (Network Broadcast Sound) ***"
114         svn co http://svn.digium.com/svn/nbs/trunk nbs-trunk
115         cd nbs-trunk
116         make && make install
117         cd ..
118
119         # Only install libresample if it wasn't installed via package
120         if ! test -f /usr/include/libresample.h; then
121                 echo "*** Installing libresample ***"
122                 svn co http://svn.digium.com/svn/thirdparty/libresample/trunk libresample-trunk
123                 cd libresample-trunk
124                 ./configure && make && make install
125                 cd ..
126         fi
127
128         # Only install Jansson if it wasn't installed via package
129         if ! test -f /usr/include/jansson.h; then
130                 echo "*** Installing jansson ***"
131                 wget -O - http://www.digip.org/jansson/releases/jansson-${JANSSON_VER}.tar.gz | zcat | tar -xf -
132                 cd jansson-${JANSSON_VER}
133                 ./configure && make all && make install
134                 cd ..
135                 echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
136                 /sbin/ldconfig
137         fi
138
139         # Only install libsrtp if it wasn't installed via package
140         if ! test -f /usr/include/srtp/srtp.h; then
141                 echo "*** Installing libsrtp ***"
142                 if [ ! -d libsrtp ]; then
143                         git clone https://github.com/cisco/libsrtp.git
144                         cd libsrtp
145                 else
146                         cd libsrtp
147                         git pull
148                 fi
149                 ./configure CFLAGS=-fPIC && make libsrtp.a && make uninstall && make install
150                 cd ..
151                 echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
152                 /sbin/ldconfig
153         fi
154
155         # Only install pjproject if it wasn't installed via package
156         if ! test -f /usr/include/pjlib.h; then
157                 echo "*** Installing pjproject ***"
158                 if [ ! -d pjproject ]; then
159                         git clone https://github.com/asterisk/pjproject.git
160                         cd pjproject
161                 else
162                         cd pjproject
163                         git pull
164                 fi
165                 ./configure --enable-shared --with-external-speex --with-external-gsm --with-external-srtp --disable-sound --disable-resample && make && make install
166                 cd ..
167                 echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
168                 /sbin/ldconfig
169         fi
170 }
171
172 if in_test_mode; then
173         echo "#############################################"
174         echo "## $1: test mode."
175         echo "## Use the commands here to install your system."
176         echo "#############################################"
177 elif test "${unpackaged}" = "yes" ; then
178         install_unpackaged
179         exit 0
180 fi
181
182 OS=`uname -s`
183 unsupported_distro=''
184
185 # A number of distributions we don't (yet?) support.
186 if [ "$OS" != 'Linux' -a "$OS" != 'OpenBSD' ]; then
187         echo >&2 "$0: Your OS ($OS) is currently not supported. Aborting."
188         exit 1
189 fi
190
191 if [ -f /etc/gentoo-release ]; then
192         unsupported_distro='Gentoo'
193 fi
194
195 if [ -f /etc/mandrake-release ]; then
196         unsupported_distro='Mandriva'
197 fi
198
199 if [ -f /etc/SuSE-release ]; then
200         unsupported_distro='SUSE'
201 fi
202
203 if [ -f /etc/slackware-version ]; then
204         unsupported_distro='Slackware'
205 fi
206
207 if [ "$unsupported_distro" != '' ]; then
208         echo >&2 "$0: Your distribution ($unsupported_distro) is currently not supported. Aborting."
209         exit 1
210 fi
211
212 # The distributions we do support:
213 if [ -r /etc/debian_version ]; then
214         handle_debian
215 elif [ -r /etc/redhat-release ]; then
216         handle_rh
217 elif [ "$OS" = 'OpenBSD' ]; then
218         handle_obsd
219 fi
220
221 if ! in_test_mode; then
222         echo "#############################################"
223         echo "## $1 completed successfully"
224         echo "#############################################"
225 fi