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