Add a script which installs every package needed for a Debian install of
[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 }
19
20 # Basic build system:
21 PACKAGES_DEBIAN="build-essential"
22 # Asterisk: basic requirements:
23 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libncurses-dev libz-dev libssl-dev"
24 # Asterisk: very useful addons:
25 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libcurl-dev libspeex-dev libogg-dev libvorbis-dev libasound2-dev"
26 # Asterisk: nice-to-have addons:
27 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libpq-dev unixodbc-dev libsqlite-dev"
28 # Not so nice addon:
29 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libopenh323-dev"
30 # Extras for 1.4:
31 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libsnmp-dev libiksemel-dev "
32
33 PACKAGES_RH="gcc gcc-c++ ncurses-devel openssl-devel"
34
35 KVERS=`uname -r`
36
37 case "$1" in
38 test)    testcmd=echo ;;
39 install) testcmd='' ;;
40 '') usage; exit 0 ;;
41 *) usage; exit 1 ;;
42 esac
43
44 in_test_mode() {
45   test "$testcmd" != ''
46 }
47
48 # Fixme: should be done by apt and not by dpkg?
49 check_installed_debs() {
50          dpkg-query -W --showformat '${Status} ${Package}\n' "$@" 2>/dev/null \
51          | awk '/ not-installed/{print $4}'
52 }
53
54 # parsing the output of yum is close to impossible.
55 # We'll use rpm and hope for the best:
56 check_installed_rpms() {
57         for pack in "$@"
58         do
59                 if ! rpm -q $pack >/dev/null 2>/dev/null
60                 then echo $pack
61                 fi
62         done
63 }
64
65 handle_debian() {
66         # echo "# Distribution is Debian or compatible"
67         extra_packs=`check_installed_debs $PACKAGES_DEBIAN`
68         $testcmd apt-get install -y $extra_packs
69 }
70
71 handle_rh() {
72         # echo "# Distribution is RedHat-based or compatible"
73         extra_packs=`check_installed_rpms $PACKAGES_RH`
74         # FIXME: is there yum with RHEL 4?
75         $testcmd yum install -y $extra_packs
76 }
77
78 if in_test_mode; then
79         echo "#############################################"
80         echo "## $1: test mode."
81         echo "## Use the commands here to install your system."
82         echo "#############################################"
83 fi
84
85 OS=`uname -s`
86 unsupported_distro=''
87
88 # A number of distributions we don't (yet?) support.
89 if [ "$OS" != 'Linux' ]; then
90   echo >&2 "$0: Your OS ($OS) is currently not supported. Aborting."
91   exit 1
92 fi
93
94 if [ -f /etc/gentoo-release ]; then
95   unsupported_distro='Gentoo'
96 fi
97
98 if [ -f /etc/mandrake-release ]; then
99   unsupported_distro='Mandriva'
100 fi
101
102 if [ -f /etc/SuSE-release ]; then
103   unsupported_distro='SUSE'
104 fi
105
106 if [ -f /etc/slackware-version ]; then
107   unsupported_distro='Slackware'
108 fi
109
110 if [ "$unsupported_distro" != '' ]; then
111   echo >&2 "$0: Your distribution ($unsupported_distro) is currently not supported. Aborting."
112   exit 1
113 fi
114
115 # The distributions we do support:
116 if [ -r /etc/debian_version ]; then
117   handle_debian
118 elif [ -r /etc/redhat-release ]; then
119   handle_rh
120 fi
121
122 if ! in_test_mode; then
123   echo "#############################################"
124   echo "## $1 completed successfully"
125   echo "#############################################"
126 fi