-
Notifications
You must be signed in to change notification settings - Fork 22
/
setup_dependencies.sh
executable file
·102 lines (85 loc) · 2.64 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
#!/bin/bash
# Copyright(c) 2012-2020 Intel Corporation
# Copyright 2024 Solidigm All Rights Reserved
# SPDX-License-Identifier: BSD-3-Clause
IOTRACE_DIR="$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)"
OCTF_DIR=${IOTRACE_DIR}/modules/open-cas-telemetry-framework
# Include common script utilites from OCTF
PREFIX="IOTRACE"
. ${OCTF_DIR}/tools/scripts/octf-common.sh
function iotrace_get_kernel_package () {
case "${DISTRO}" in
"RHEL7"|"RHEL8"|"CENTOS7"|"CENTOS8"|"FEDORA")
echo "kernel-devel"
;;
"UBUNTU"|"DEBIAN")
echo "linux-headers"
;;
*)
error "Unknown Linux distribution"
;;
esac
}
function iotrace_get_distribution_pkg_dependencies () {
local pkgs="clang llvm"
case "${DISTRO}" in
"RHEL7"|"CENTOS7"|"RHEL8"|"CENTOS8"|"FEDORA")
echo "${pkgs} rpm-build elfutils-libelf-devel libblkid-devel libbpf-devel zlib bpftool"
;;
"UBUNTU"|"DEBIAN")
echo "${pkgs} dpkg libblkid-dev libbpf-dev zlib1g-dev linux-tools-common linux-tools-generic"
;;
*)
error "Unknown Linux distribution"
;;
esac
}
function iotrace_setup_kernel_headers () {
local kernel_version=$(uname -r)
local kernel_dir=$(readlink -f /lib/modules/${kernel_version}/build)
if [ -d "${kernel_dir}" ]
then
info "Kernel headers already available: ${kernel_dir}"
return 0
fi
info "Install kernel headers"
local installer=$(get_distribution_pkg_manager)
${installer} $(iotrace_get_kernel_package)
if [ ! -d "${kernel_dir}" ]
then
info "Cannot install kernel headers appropriate to running kernel"
info "Try to install specific kernel headers version: ${kernel_version}"
case "${DISTRO}" in
"RHEL7"|"CENTOS7"|"RHEL8"|"CENTOS8"|"FEDORA")
${installer} "kernel-devel-uname-r == $(uname -r)"
;;
"UBUNTU"|"DEBIAN")
${installer} linux-headers-$(uname -r)
;;
*)
error "Unknown Linux distribution"
;;
esac
fi
if [ ! -d "${kernel_dir}" ]
then
info "Consider updating the system kernel to match available headers"
error "The installed kernel headers do not match to the running kernel version."
fi
return 0
}
if [ "$EUID" -ne 0 ]
then
error "Please run as root to allow using package manager"
fi
# Include and execute OCTF setup dependencies
bash -c ${OCTF_DIR}/setup_dependencies.sh
if [ $? -ne 0 ]
then
error "Cannot setup OCTF submodule dependencies"
exit 1
fi
PKGS=$(iotrace_get_distribution_pkg_dependencies)
install_pacakges $PKGS
iotrace_setup_kernel_headers
exit 0