install_prereq: Add Arch Linux.
[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 pkg-config"
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 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 # Basic build system:
38 PACKAGES_RH="make gcc gcc-c++ pkgconfig"
39 # Asterisk: basic requirements:
40 PACKAGES_RH="$PACKAGES_RH libedit-devel jansson-devel libuuid-devel sqlite-devel libxml2-devel"
41 # Asterisk: for addons:
42 PACKAGES_RH="$PACKAGES_RH speex-devel speexdsp-devel libogg-devel libvorbis-devel alsa-lib-devel portaudio-devel libcurl-devel xmlstarlet bison flex"
43 PACKAGES_RH="$PACKAGES_RH postgresql-devel unixODBC-devel libtool-ltdl-devel neon-devel gmime-devel lua-devel uriparser-devel libxslt-devel openssl-devel"
44 PACKAGES_RH="$PACKAGES_RH mysql-devel bluez-libs-devel radcli-devel freetds-devel jack-audio-connection-kit-devel bash"
45 PACKAGES_RH="$PACKAGES_RH net-snmp-devel iksemel-devel corosynclib-devel newt-devel popt-devel libical-devel spandsp-devel"
46 PACKAGES_RH="$PACKAGES_RH libresample-devel uw-imap-devel binutils-devel libsrtp-devel gsm-devel doxygen graphviz zlib-devel openldap-devel hoard"
47 PACKAGES_RH="$PACKAGES_RH codec2-devel fftw-devel libsndfile-devel unbound-devel"
48 # Asterisk: for the unpackaged below:
49 PACKAGES_RH="$PACKAGES_RH wget subversion"
50 # Asterisk: for ./configure --with-pjproject-bundled:
51 PACKAGES_RH="$PACKAGES_RH bzip2 patch python-devel"
52
53 # Basic build system:
54 PACKAGES_SUSE="make gcc gcc-c++ pkg-config"
55 # Asterisk: basic requirements:
56 PACKAGES_SUSE="$PACKAGES_SUSE libedit-devel libjansson-devel libuuid-devel sqlite3-devel libxml2-devel"
57 # Asterisk: for addons:
58 PACKAGES_SUSE="$PACKAGES_SUSE speex-devel speexdsp-devel libogg-devel libvorbis-devel alsa-devel portaudio-devel libcurl-devel xmlstarlet bison flex"
59 PACKAGES_SUSE="$PACKAGES_SUSE postgresql-devel unixODBC-devel libtool libneon-devel gmime-devel lua-devel liburiparser-devel libxslt-devel libopenssl-devel"
60 PACKAGES_SUSE="$PACKAGES_SUSE libmysqlclient-devel bluez-devel freeradius-client-devel freetds-devel bash"
61 PACKAGES_SUSE="$PACKAGES_SUSE net-snmp-devel iksemel-devel libcorosync-devel newt-devel popt-devel libical-devel spandsp-devel"
62 PACKAGES_SUSE="$PACKAGES_SUSE imap-devel libsrtp2-devel libgsm-devel doxygen graphviz zlib-devel openldap2-devel"
63 PACKAGES_SUSE="$PACKAGES_SUSE codec2-devel fftw3-devel libsndfile-devel unbound-devel"
64 # Asterisk: for the unpackaged below:
65 PACKAGES_SUSE="$PACKAGES_SUSE wget subversion"
66 # Asterisk: for ./configure --with-pjproject-bundled:
67 PACKAGES_SUSE="$PACKAGES_SUSE bzip2 patch python-devel"
68
69 # Basic build system:
70 PACKAGES_ARCH="make gcc pkg-config"
71 # Asterisk: basic requirements:
72 PACKAGES_ARCH="$PACKAGES_ARCH libedit jansson libutil-linux libxml2 sqlite"
73 # Asterisk: for addons:
74 PACKAGES_ARCH="$PACKAGES_ARCH speex speexdsp libogg libvorbis alsa-lib portaudio curl xmlstarlet bison flex"
75 PACKAGES_ARCH="$PACKAGES_ARCH postgresql-libs unixodbc libtool neon gmime lua uriparser libxslt openssl"
76 PACKAGES_ARCH="$PACKAGES_ARCH libmariadbclient bluez-libs radcli freetds bash"
77 PACKAGES_ARCH="$PACKAGES_ARCH net-snmp libnewt popt libical spandsp"
78 PACKAGES_ARCH="$PACKAGES_ARCH c-client binutils libsrtp gsm doxygen graphviz zlib libldap"
79 PACKAGES_ARCH="$PACKAGES_ARCH fftw libsndfile unbound"
80 # Asterisk: for the unpackaged below:
81 PACKAGES_ARCH="$PACKAGES_ARCH wget subversion"
82 # Asterisk: for ./configure --with-pjproject-bundled:
83 PACKAGES_ARCH="$PACKAGES_ARCH bzip2 patch python2"
84
85 # Basic build system:
86 PACKAGES_NBSD="gmake pkg-config"
87 # Asterisk: basic requirements:
88 PACKAGES_NBSD="$PACKAGES_NBSD editline jansson sqlite3 libuuid libxml2"
89 # Asterisk: for addons:
90 PACKAGES_NBSD="$PACKAGES_NBSD speex speexdsp libogg libvorbis alsa-lib portaudio-devel curl bison flex"
91 PACKAGES_NBSD="$PACKAGES_NBSD postgresql10-client unixodbc libltdl neon gmime lua52 uriparser libxslt openssl"
92 PACKAGES_NBSD="$PACKAGES_NBSD mysql-client radiusclient-ng freetds bash"
93 PACKAGES_NBSD="$PACKAGES_NBSD net-snmp iksemel popt libical spandsp"
94 PACKAGES_NBSD="$PACKAGES_NBSD imap-uw srtp gsm doxygen graphviz libzip openldap-client"
95 PACKAGES_NBSD="$PACKAGES_NBSD codec2 fftw libsndfile unbound"
96 # Asterisk: for the unpackaged below:
97 PACKAGES_NBSD="$PACKAGES_NBSD wget subversion-base"
98 # Asterisk: for ./configure --with-pjproject-bundled:
99 PACKAGES_NBSD="$PACKAGES_NBSD bzip2 patch python27"
100
101 # Basic build system:
102 PACKAGES_OBSD="gmake"
103 # Asterisk: basic requirements:
104 PACKAGES_OBSD="$PACKAGES_OBSD libxml sqlite3 e2fsprogs jansson"
105 # Asterisk: for addons:
106 PACKAGES_OBSD="$PACKAGES_OBSD speex speexdsp libogg libvorbis portaudio-svn curl xmlstarlet bison"
107 PACKAGES_OBSD="$PACKAGES_OBSD postgresql-client iodbc libltdl neon gmime lua%5.2 uriparser libxslt"
108 PACKAGES_OBSD="$PACKAGES_OBSD mariadb-client radcli freetds"
109 PACKAGES_OBSD="$PACKAGES_OBSD net-snmp iksemel popt libical spandsp"
110 PACKAGES_OBSD="$PACKAGES_OBSD c-client libsrtp gsm doxygen graphviz"
111 PACKAGES_OBSD="$PACKAGES_OBSD fftw3 libsndfile"
112 # Asterisk: for the unpackaged below:
113 PACKAGES_OBSD="$PACKAGES_OBSD wget subversion"
114 # Asterisk: for ./configure --with-pjproject-bundled:
115 PACKAGES_OBSD="$PACKAGES_OBSD bzip2 python%2"
116
117 # Basic build system:
118 PACKAGES_FBSD="gmake pkgconf"
119 # Asterisk: basic requirements:
120 PACKAGES_FBSD="$PACKAGES_FBSD libedit jansson e2fsprogs-libuuid sqlite3 libxml2"
121 # Asterisk: for addons:
122 PACKAGES_FBSD="$PACKAGES_FBSD speex speexdsp libogg libvorbis alsa-lib portaudio curl xmlstarlet bison flex"
123 PACKAGES_FBSD="$PACKAGES_FBSD postgresql10-client unixODBC libltdl neon gmime26 lua52 uriparser libxslt openssl"
124 PACKAGES_FBSD="$PACKAGES_FBSD mysql57-client radcli freetds"
125 PACKAGES_FBSD="$PACKAGES_FBSD net-snmp iksemel corosync newt popt libical spandsp"
126 PACKAGES_FBSD="$PACKAGES_FBSD cclient libbfd libsrtp gsm libilbc doxygen graphviz libzip openldap-client libhoard"
127 PACKAGES_FBSD="$PACKAGES_FBSD codec2 fftw3 libsndfile unbound"
128 # Asterisk: for the unpackaged below:
129 PACKAGES_FBSD="$PACKAGES_FBSD wget subversion"
130 # Asterisk: for ./configure --with-pjproject-bundled:
131 PACKAGES_FBSD="$PACKAGES_FBSD bzip2 patch python"
132
133 KVERS=`uname -r`
134
135 JANSSON_VER=2.11
136
137 case "$1" in
138 test)
139         testcmd=echo
140         ;;
141 install)
142         testcmd=''
143         ;;
144 install-unpackaged)
145         unpackaged="yes"
146         ;;
147 '')
148         usage
149         exit 0
150         ;;
151 *)
152         usage
153         exit 1
154         ;;
155 esac
156
157 in_test_mode() {
158         test "$testcmd" != ''
159 }
160
161 check_installed_debs() {
162         for pack in "$@" ; do
163                 tocheck="${tocheck} ^${pack}$ ~P^${pack}$"
164         done
165         pkgs=$(aptitude -F '%c %p' search ${tocheck} 2>/dev/null | awk '/^p/{print $2}')
166         if [ ${#pkgs} -ne 0 ]; then
167                 echo $pkgs | sed -r -e "s/ ?[^ :]+:i386//g"
168         fi
169 }
170
171 # parsing the output of yum is close to impossible.
172 # We'll use rpm and hope for the best:
173 check_installed_rpms() {
174         for pack in "$@"
175         do
176                 if ! rpm -q $pack >/dev/null 2>/dev/null
177                 then echo $pack
178                 fi
179         done
180 }
181
182 check_installed_pacman() {
183         for pack in "$@"
184         do
185                 if ! pacman -Q --explicit $pack >/dev/null 2>/dev/null
186                 then echo $pack
187                 fi
188         done
189 }
190
191 check_installed_pkgs() {
192         for pack in "$@"
193         do
194                 if [ `pkg_info -a | grep $pack | wc -l` = 0 ]; then
195                 echo $pack
196                 fi
197         done
198 }
199
200 check_installed_fpkgs() {
201         for pack in "$@"
202         do
203                 if [ `pkg info -a | grep $pack | wc -l` = 0 ]; then
204                 echo $pack
205                 fi
206         done
207 }
208
209 check_installed_zypper() {
210         for pack in "$@"
211         do
212                 if ! zypper se -ixnC $pack >/dev/null 2>/dev/null
213                 then echo $pack
214                 fi
215         done
216 }
217
218 handle_debian() {
219         if ! [ -x "$(command -v aptitude)" ]; then
220                 apt-get install aptitude
221         fi
222         extra_packs=`check_installed_debs $PACKAGES_DEBIAN`
223         $testcmd aptitude update
224         if [ x"$extra_packs" != "x" ] ; then
225                 $testcmd aptitude install -y $extra_packs
226         fi
227 }
228
229 handle_rh() {
230         extra_packs=`check_installed_rpms $PACKAGES_RH`
231         if [ x"$extra_packs" != "x" ] ; then
232                 $testcmd yum install --skip-broken --assumeyes $extra_packs
233         fi
234 }
235
236 handle_arch() {
237         extra_packs=`check_installed_pacman $PACKAGES_ARCH`
238         if [ x"$extra_packs" != "x" ] ; then
239                 $testcmd pacman -S --asexplicit --noconfirm $extra_packs
240         fi
241 }
242
243 handle_nbsd() {
244         extra_packs=`check_installed_pkgs $PACKAGES_NBSD`
245         if [ x"$extra_packs" != "x" ] ; then
246                 if [ -z "$PKG_PATH" ] ; then
247                         # see NetBSD Problem Report #48177
248                         export PKG_PATH="http://cdn.NetBSD.org/pub/pkgsrc/packages/$(uname -s)/$(uname -p)/$(uname -r)/All"
249                 fi
250                 $testcmd pkg_add $extra_packs
251         fi
252 }
253
254 handle_obsd() {
255         extra_packs=`check_installed_pkgs $PACKAGES_OBSD`
256         if [ x"$extra_packs" != "x" ] ; then
257                 $testcmd pkg_add $extra_packs
258         fi
259 }
260
261 handle_fbsd() {
262         extra_packs=`check_installed_fpkgs $PACKAGES_FBSD`
263         if [ x"$extra_packs" != "x" ] ; then
264                 $testcmd pkg install -y $extra_packs
265         fi
266 }
267
268 handle_SUSE() {
269         extra_packs=`check_installed_zypper $PACKAGES_SUSE`
270         if [ x"$extra_packs" != "x" ] ; then
271                 $testcmd zypper install --no-confirm $extra_packs
272         fi
273 }
274
275 install_unpackaged() {
276         echo "*** Installing NBS (Network Broadcast Sound) ***"
277         svn co http://svn.digium.com/svn/nbs/trunk nbs-trunk
278         cd nbs-trunk
279         make all install
280         cd ..
281
282         # Only install libresample if it wasn't installed via package
283         if ! test -f /usr/include/libresample.h; then
284                 echo "*** Installing libresample ***"
285                 svn co http://svn.digium.com/svn/thirdparty/libresample/trunk libresample-trunk
286                 cd libresample-trunk
287                 ./configure
288                 make all install
289                 cd ..
290         fi
291
292         # Only install Jansson if it wasn't installed via package
293         if ! test -f /usr/include/jansson.h; then
294                 echo "*** Installing jansson ***"
295                 wget -O - http://www.digip.org/jansson/releases/jansson-${JANSSON_VER}.tar.gz | zcat | tar -xf -
296                 cd jansson-${JANSSON_VER}
297                 ./configure
298                 make all install
299                 cd ..
300                 echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
301                 /sbin/ldconfig
302         fi
303
304         # Only install libsrtp2 if it wasn't installed via package
305         if ! test -f /usr/include/srtp/srtp.h; then
306                 if ! test -f /usr/include/srtp2/srtp.h; then
307                         echo "*** Installing libsrtp2 ***"
308                         wget -O - http://github.com/cisco/libsrtp/archive/v2.tar.gz | zcat | tar -xf -
309                         cd libsrtp-2
310                         ./configure --enable-openssl
311                         make shared_library install
312                         cd ..
313                         echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
314                         /sbin/ldconfig
315                 fi
316         fi
317
318         if ! test -f /usr/include/pjlib.h; then
319                 echo "PJProject not installed, yet. Therefore, please, run"
320                 echo "./configure --with-pjproject-bundled"
321         fi
322 }
323
324 if in_test_mode; then
325         echo "#############################################"
326         echo "## $1: test mode."
327         echo "## Use the commands here to install your system."
328         echo "#############################################"
329 elif test "${unpackaged}" = "yes" ; then
330         install_unpackaged
331         exit 0
332 fi
333
334 OS=`uname -s`
335 unsupported_distro=''
336
337 # A number of distributions we don't (yet?) support.
338 if [ "$OS" != 'Linux' -a "$OS" != 'NetBSD' -a "$OS" != 'OpenBSD' -a "$OS" != 'FreeBSD' ]; then
339         echo >&2 "$0: Your OS ($OS) is currently not supported. Aborting."
340         exit 1
341 fi
342
343 if [ -f /etc/gentoo-release ]; then
344         unsupported_distro='Gentoo'
345 fi
346
347 if [ -f /etc/mandrake-release ]; then
348         unsupported_distro='Mandriva'
349 fi
350
351 if [ -f /etc/slackware-version ]; then
352         unsupported_distro='Slackware'
353 fi
354
355 if [ "$unsupported_distro" != '' ]; then
356         echo >&2 "$0: Your distribution ($unsupported_distro) is currently not supported. Aborting."
357         exit 1
358 fi
359
360 # The distributions we do support:
361 if [ -r /etc/debian_version ]; then
362         handle_debian
363 elif [ -r /etc/redhat-release ]; then
364         handle_rh
365 elif [ -f /etc/SuSE-release -o -f /etc/novell-release ]; then
366         handle_SUSE
367 elif [ -f /etc/os-release ] && . /etc/os-release && [ "$ID" = "opensuse" ]; then
368         handle_SUSE
369 elif [ -r /etc/arch-release ]; then
370         handle_arch
371 elif [ -f /etc/os-release ] && . /etc/os-release && [ "$ID_LIKE" = "archlinux" ]; then
372         handle_arch # $ID=arch
373 elif [ "$OS" = 'NetBSD' ]; then
374         handle_nbsd
375 elif [ "$OS" = 'OpenBSD' ]; then
376         handle_obsd
377 elif [ "$OS" = 'FreeBSD' ]; then
378         handle_fbsd
379 fi
380
381 if ! in_test_mode; then
382         echo "#############################################"
383         echo "## $1 completed successfully"
384         echo "#############################################"
385 fi