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) 2018 Siemens AG
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)
71CODENAME=$(lsb_release --codename --short)
72
73########################################################################
74
75if [[ $BUILDTIME ]]; then
76  echo "*** Installing $DISTRO buildtime dependencies ***";
77  case "$DISTRO" in
78    Debian|Ubuntu)
79      apt-get $YesOpt install \
80        libjsoncpp-dev libboost-system-dev libboost-filesystem-dev
81      ;;
82    Fedora)
83      yum $YesOpt install \
84        jsoncpp-devel
85      ;;
86    RedHatEnterprise*|CentOS)
87      yum $YesOpt install epel-release;
88      yum $YesOpt install \
89        jsoncpp-devel
90      ;;
91    *) echo "ERROR: Unknown or Unsupported $DISTRO $CODENAME release, please report to the mailing list"; exit 1;;
92  esac
93fi
94
95if [[ $RUNTIME ]]; then
96  echo "*** Installing $DISTRO runtime dependencies ***";
97  case "$DISTRO" in
98    Debian|Ubuntu)
99      case "$CODENAME" in
100        stretch)
101          apt-get $YesOpt install libjsoncpp1 libboost-filesystem1.62.0;;
102        buster|sid)
103          apt-get $YesOpt install libjsoncpp1 libboost-filesystem1.67.0;;
104        xenial)
105          apt-get $YesOpt install libjsoncpp1 libboost-filesystem1.58.0;;
106        bionic)
107          apt-get $YesOpt install libjsoncpp1 libboost-filesystem1.65.1;;
108        focal)
109          apt-get $YesOpt install libjsoncpp1 libboost-filesystem1.71.0;;
110        *) echo "ERROR: Unknown or Unsupported $DISTRO $CODENAME release, please report to the mailing list"; exit 1;;
111      esac;;
112    Fedora)
113      yum $YesOpt install \
114        jsoncpp
115      ;;
116    RedHatEnterprise*|CentOS)
117      yum $YesOpt install epel-release;
118      yum $YesOpt install \
119        jsoncpp
120      ;;
121    *) echo "ERROR: Unknown or Unsupported $DISTRO $CODENAME release, please report to the mailing list"; exit 1;;
122  esac
123fi
124
125#######################################################################
126