Skip to content

Commit

Permalink
future proof rhel kernel version parser logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tariq1890 committed Feb 26, 2024
1 parent ea3bde2 commit c0a9c24
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions rhel8/nvidia-driver
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ _cleanup_package_cache() {

_get_rhel_version_from_kernel() {
local rhel_version_underscore rhel_version_arr
rhel_version_underscore=$(echo "${KERNEL_VERSION}" | sed 's/.*el\([0-9]_[0-9]\).*/\1/g')
# For the Kernel version 4.18.0-513.9.1.el8_9, we expect to extract the string "8_9"
if [[ ${#rhel_version_underscore} -ne 3 ]]; then
rhel_version_underscore=$(echo "${KERNEL_VERSION}" | sed 's/.*el\([0-9]\+_[0-9]\+\).*/\1/g')
# For e.g. :- from the kernel version 4.18.0-513.9.1.el8_9, we expect to extract the string "8_9"
if [[ ! ${rhel_version_underscore} =~ ^[0-9]+_[0-9]+$ ]]; then
echo "Unable to resolve RHEL version from kernel version" >&2
return 1
fi
Expand All @@ -59,6 +59,7 @@ _get_rhel_version_from_kernel() {
return 1
fi
RHEL_VERSION="${rhel_version_arr[0]}.${rhel_version_arr[1]}"
echo "RHEL VERSION successfully resolved from kernel: ${RHEL_VERSION}"
return 0
}

Expand Down
5 changes: 3 additions & 2 deletions rhel8/precompiled/nvidia-driver
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ _cleanup_package_cache() {

_get_rhel_version_from_kernel() {
local rhel_version_underscore rhel_version_arr
rhel_version_underscore=$(echo "${KERNEL_VERSION}" | sed 's/.*el\([0-9]_[0-9]\).*/\1/g')
rhel_version_underscore=$(echo "${KERNEL_VERSION}" | sed 's/.*el\([0-9]\+_[0-9]\+\).*/\1/g')
# For the Kernel version 4.18.0-513.9.1.el8_9, we expect to extract the string "8_9"
if [[ ${#rhel_version_underscore} -ne 3 ]]; then
if [[ ! ${rhel_version_underscore} =~ ^[0-9]+_[0-9]+$ ]]; then
echo "Unable to resolve RHEL version from kernel version" >&2
return 1
fi
Expand All @@ -56,6 +56,7 @@ _get_rhel_version_from_kernel() {
return 1
fi
RHEL_VERSION="${rhel_version_arr[0]}.${rhel_version_arr[1]}"
echo "RHEL VERSION successfully resolved from kernel: ${RHEL_VERSION}"
return 0
}

Expand Down

0 comments on commit c0a9c24

Please sign in to comment.