-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathensure_kernel.sh
More file actions
executable file
·75 lines (67 loc) · 2.77 KB
/
ensure_kernel.sh
File metadata and controls
executable file
·75 lines (67 loc) · 2.77 KB
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
#!/bin/bash
# ensure_kernel.sh: install exact kernel (if NVIDIA_SETUP_INSTALL_KERNEL=true) or
# verify current kernel meets requirement (see NVIDIA_SETUP_KERNEL_ALLOW_NEWER).
set -e
#
# NVIDIA_SETUP_KERNEL_ALLOW_NEWER (default: false). When false, the running kernel
# must match the required upstream version exactly. When true, the running kernel
# may be newer (current >= required).
STEPS_DIR="${SKYHOOK_DIR}/skyhook_dir/steps"
if [ -f "${SKYHOOK_DIR}/skyhook_dir/utilities.sh" ]; then
# shellcheck source=../utilities.sh
. "${SKYHOOK_DIR}/skyhook_dir/utilities.sh"
elif [ -f "$(dirname "$0")/../utilities.sh" ]; then
. "$(dirname "$0")/../utilities.sh"
else
echo "ERROR: utilities.sh not found" >&2
exit 1
fi
install_kernel() {
"${STEPS_DIR}/install_kernel.sh" "${KERNEL}"
}
# Returns 0 if current >= required (by upstream version).
# Compares only the upstream part (before first '-') so local suffixes like
# -1007-aws vs -1018-aws do not reverse the order (sort -V on full uname -r
# can treat 6.17.0-1007 as "smaller" than 6.14.0-1018 because 1007 < 1018).
check_kernel_at_least() {
local required="$1"
local current
current=$(uname -r)
local required_upstream="${required%%-*}"
local current_upstream="${current%%-*}"
local first
first=$(printf '%s\n' "${required_upstream}" "${current_upstream}" | sort -V | head -n1)
if [ "${first}" = "${required_upstream}" ]; then
return 0
fi
return 1
}
# Returns 0 if current upstream version equals required upstream version (exact match).
check_kernel_exact() {
local required="$1"
local current
current=$(uname -r)
local required_upstream="${required%%-*}"
local current_upstream="${current%%-*}"
[ "${current_upstream}" = "${required_upstream}" ]
}
# When TEST_CHECK_KERNEL_AT_LEAST is set, skip normal execution so tests can source this file and call check_kernel_at_least.
if [ -z "${TEST_CHECK_KERNEL_AT_LEAST:-}" ]; then
if [ "${NVIDIA_SETUP_INSTALL_KERNEL:-false}" = "true" ]; then
install_kernel
exit 0
fi
# Check current kernel meets requirement (exact or at-least depending on env)
required_full="$(resolve_full_kernel "${KERNEL}")"
if [ "${NVIDIA_SETUP_KERNEL_ALLOW_NEWER:-false}" = "true" ]; then
if ! check_kernel_at_least "${required_full}"; then
echo "Error: current kernel $(uname -r) is not >= required ${required_full}. Set NVIDIA_SETUP_INSTALL_KERNEL=true to install the exact kernel, or boot with a compatible kernel." >&2
exit 1
fi
else
if ! check_kernel_exact "${required_full}"; then
echo "Error: current kernel $(uname -r) does not match required ${required_full} (exact match required). Set NVIDIA_SETUP_KERNEL_ALLOW_NEWER=true to allow a newer kernel, or NVIDIA_SETUP_INSTALL_KERNEL=true to install the exact kernel." >&2
exit 1
fi
fi
fi