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