1#!/usr/bin/env bash
2# FOSSology mod_deps script
3# This script helps you install dependencies on a system. for a module
4#
5# Copyright (C) 2011 Hewlett-Packard Development Company, L.P.
6# This program is free software; you can redistribute it and/or
7# modify it under the terms of the GNU General Public License
8# version 2 as published by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
19source "$(dirname ${BASH_SOURCE[0]})/../../utils/utils.sh"
20
21#
22# Don't show the -y option.  Should only be used for install testing, as using
23# it without being careful can destroy your system.
24#
25YesOpt=''
26
27EVERYTHING=''
28RUNTIME=''
29BUILDTIME=''
30
31## Options parsing and setup
32# parse options
33OPTS=$(getopt -o rbehy --long runtime,buildtime,everything,help -n 'mod_deps' -- "$@")
34
35if [[ $? -ne 0 ]]; then
36  OPTS='--help'
37fi
38
39eval set -- "$OPTS"
40
41# if no options or just -y then do everything
42if [[ $OPTS == ' --' || $OPTS == ' -y --' ]]; then
43  EVERYTHING=true
44fi
45
46while true; do
47  case "$1" in
48    -r|--runtime)     RUNTIME=true; shift;;
49    -b|--buildtime)   BUILDTIME=true; shift;;
50    -e|--everything)  EVERYTHING=true; shift;;
51    -y)               YesOpt='-y'; shift;;
52    -h|--help)        show_help_for_mod_deps; exit;;
53    --)               shift; break;;
54    *)                echo "ERROR: option $1 not recognised"; exit 1;;
55  esac
56done
57
58set -o errexit -o nounset -o pipefail
59
60must_run_as_root
61need_lsb_release
62
63if [[ $EVERYTHING ]]; then
64  echo "*** Installing both runtime and buildtime dependencies ***"
65  RUNTIME=true
66  BUILDTIME=true
67fi
68
69# figure out what distro we're on
70DISTRO=$(lsb_release --id --short)
71
72########################################################################
73
74if [[ $BUILDTIME ]]; then
75  echo "*** Installing $DISTRO buildtime dependencies ***";
76  case "$DISTRO" in
77    Debian|Ubuntu)
78      apt-get $YesOpt install \
79        libglib2.0-dev
80      ;;
81    RedHatEnterprise*|CentOS|Fedora)
82      yum $YesOpt install \
83        glib2-devel
84      ;;
85    *) echo "ERROR: distro not recognised, please fix and send a patch"; exit 1;;
86  esac
87fi
88
89if [[ $RUNTIME ]]; then
90  echo "*** Installing $DISTRO runtime dependencies ***";
91  case "$DISTRO" in
92    Debian|Ubuntu)
93      apt-get $YesOpt install \
94        libglib2.0-0
95      ;;
96    RedHatEnterprise*|CentOS|Fedora)
97      yum $YesOpt install \
98        glib2
99      ;;
100  esac
101fi
102
103#######################################################################
104