951a4f67e18fdb235ae1739db61bf9b5d10db913
[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 case "$1" in
42 test)    testcmd=echo ;;
43 install) testcmd='' ;;
44 install-unpackaged) unpackaged="yes" ;;
45 '') usage; exit 0 ;;
46 *) usage; exit 1 ;;
47 esac
48
49 in_test_mode() {
50   test "$testcmd" != ''
51 }
52
53 check_installed_debs() {
54         for pack in "$@"
55         do
56                 tocheck="${tocheck} ^${pack}$"
57         done
58         aptitude -F '%c %p' search ${tocheck} 2>/dev/null \
59         | awk '/^p/{print $2}'
60 }
61
62 # parsing the output of yum is close to impossible.
63 # We'll use rpm and hope for the best:
64 check_installed_rpms() {
65         for pack in "$@"
66         do
67                 if ! rpm -q $pack >/dev/null 2>/dev/null
68                 then echo $pack
69                 fi
70         done
71 }
72
73 check_installed_pkgs() {
74         for pack in "$@"
75         do
76                 if [ `pkg_info -a | grep $pack | wc -l` = 0 ]; then
77                 echo $pack
78                 fi
79         done
80 }
81
82 handle_debian() {
83         # echo "# Distribution is Debian or compatible"
84         extra_packs=`check_installed_debs $PACKAGES_DEBIAN`
85         $testcmd aptitude install -y $extra_packs
86 }
87
88 handle_rh() {
89         # echo "# Distribution is RedHat-based or compatible"
90         extra_packs=`check_installed_rpms $PACKAGES_RH`
91         # FIXME: is there yum with RHEL 4?
92         $testcmd yum install -y $extra_packs
93 }
94
95 handle_obsd() {
96         # echo "# Distribution is OpenBSD or compatible"
97         extra_packs=`check_installed_pkgs $PACKAGES_OBSD`
98         $testcmd pkg_add $extra_packs
99 }
100
101 install_unpackaged() {
102         echo "*** Installing NBS (Network Broadcast Sound) ***"
103         svn co http://svn.digium.com/svn/nbs/trunk nbs-trunk
104         cd nbs-trunk
105         make && make install
106         cd ..
107
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 }
114
115 if in_test_mode; then
116         echo "#############################################"
117         echo "## $1: test mode."
118         echo "## Use the commands here to install your system."
119         echo "#############################################"
120 elif test "${unpackaged}" = "yes" ; then
121         install_unpackaged
122         exit 0
123 fi
124
125 OS=`uname -s`
126 unsupported_distro=''
127
128 # A number of distributions we don't (yet?) support.
129 if [ "$OS" != 'Linux' -a "$OS" != 'OpenBSD' ]; then
130   echo >&2 "$0: Your OS ($OS) is currently not supported. Aborting."
131   exit 1
132 fi
133
134 if [ -f /etc/gentoo-release ]; then
135   unsupported_distro='Gentoo'
136 fi
137
138 if [ -f /etc/mandrake-release ]; then
139   unsupported_distro='Mandriva'
140 fi
141
142 if [ -f /etc/SuSE-release ]; then
143   unsupported_distro='SUSE'
144 fi
145
146 if [ -f /etc/slackware-version ]; then
147   unsupported_distro='Slackware'
148 fi
149
150 if [ "$unsupported_distro" != '' ]; then
151   echo >&2 "$0: Your distribution ($unsupported_distro) is currently not supported. Aborting."
152   exit 1
153 fi
154
155 # The distributions we do support:
156 if [ -r /etc/debian_version ]; then
157   handle_debian
158 elif [ -r /etc/redhat-release ]; then
159   handle_rh
160 elif [ "$OS" = 'OpenBSD' ]; then
161   handle_obsd
162 fi
163
164 if ! in_test_mode; then
165   echo "#############################################"
166   echo "## $1 completed successfully"
167   echo "#############################################"
168 fi