forked from Open-CAS/standalone-linux-io-tracer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_dependencies.sh
executable file
·158 lines (131 loc) · 3.42 KB
/
setup_dependencies.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash
# Copyright(c) 2012-2018 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
# Usage: check_result <RESULT> <ERROR_MESSAGE>
#
function check_result ()
{
local result=$1
local message=$2
if [ ${result} -ne 0 ]
then
echo "[OCTF][ERROR] ${message}" 1>&2
exit ${result}
fi
}
#
# Usage: error <ERROR_MESSAGE_1> [ <ERROR_MESSAGE_2> ... ]
# Note: exits with error
#
function error () {
check_result 255 "$*"
}
#
# Usage: info <INFO_MESSAGE_1> [ <INFO_MESSAGE_2> ... ]
#
function info () {
echo "[OCTF][INFO] $*" 1>&2
}
function detect_distribution ()
{
if [ -f /etc/redhat-release ] || [ -f /etc/centos-release ]
then
if ( cat /etc/redhat-release | grep "Red Hat Enterprise Linux Server release 7." &>/dev/null )
then
echo RHEL7
return 0
fi
fi
if [ -f /etc/redhat-release ] || [ -f /etc/centos-release ]
then
if ( cat /etc/centos-release | grep "CentOS Linux release 7." &>/dev/null )
then
echo CENTOS7
return 0
fi
fi
if [ -f /etc/fedora-release ]
then
if ( cat /etc/fedora-release | grep "Fedora release 30" &>/dev/null )
then
echo FEDORA30
return 0
fi
fi
if [ -f /etc/os-release ]
then
if ( cat /etc/os-release | grep "Ubuntu 18" &>/dev/null )
then
echo UBUNTU18
return 0
fi
fi
return 1
}
function setup_other_deps
{
if [ -f $(dirname "$0")/modules/open-cas-telemetry-framework/setup_dependencies.sh ]
then
$(dirname "$0")/modules/open-cas-telemetry-framework/setup_dependencies.sh
check_result $? "Could not install dependencies"
else
info "No OCTF in the project source tree, assuming OCTF and dependencies are installed systemwide"
fi
}
if [ "$EUID" -ne 0 ]
then
echo "Please run as root to alllow using apt/yum and installing to /opt"
exit 1
fi
distro=$(detect_distribution)
case "${distro}" in
"RHEL7")
info "RHEL7.x detected"
packages="kernel-devel-$(uname -r)"
info "Installing packages: ${packages}"
yum -y install ${packages}
check_result $? "Cannot install required dependencies"
if [ ! -d /usr/src/kernels/$(uname -r) ]
then
error "Linux kernel headers were not properly installed."
fi
setup_other_deps
;;
"CENTOS7")
info "CentOS7.x detected"
packages="kernel-devel-$(uname -r)"
info "Installing packages: ${packages}"
yum -y install ${packages}
check_result $? "Cannot install required dependencies"
if [ ! -d /usr/src/kernels/$(uname -r) ]
then
error "Linux kernel headers were not properly installed."
fi
setup_other_deps
;;
"FEDORA30")
info "Fedora 30 detected"
packages="kernel-devel-$(uname -r)"
info "Installing packages: ${packages}"
dnf -y install ${packages}
check_result $? "Cannot install required dependencies"
setup_other_deps
;;
"UBUNTU18")
info "Ubuntu 18 detected"
packages="linux-headers-$(uname -r)"
info "Installing packages: ${packages}"
apt -y install ${packages}
check_result $? "Cannot install required dependencies"
if [ ! -d /usr/src/linux-headers-$(uname -r) ]
then
error "Linux kernel headers were not properly installed."
fi
setup_other_deps
;;
*)
error "Unknown linux distribution"
exit 1
;;
esac