eclass/dist-kernel-utils: Sync with Gentoo

It's from Gentoo commit bb7b3f56b8d85bb1c96d9d0b85a10769fb497005.
This commit is contained in:
Flatcar Buildbot 2025-03-17 07:07:53 +00:00 committed by Krzesimir Nowak
parent a837f7869e
commit d53013abbc

View File

@ -66,18 +66,37 @@ dist-kernel_get_image_path() {
} }
# @FUNCTION: dist-kernel_install_kernel # @FUNCTION: dist-kernel_install_kernel
# @USAGE: <version> <image> <system.map> # @USAGE: [<version>] [<image>] [<system.map>] [<dir>] [<installkernel-args>...]
# @DESCRIPTION: # @DESCRIPTION:
# Install kernel using installkernel tool. <version> specifies # Install kernel using installkernel. Takes the following arguments:
# the kernel version, <image> full path to the image, <system.map> #
# full path to System.map. # <version> -- the target kernel version (default: ${KV_FULL})
#
# <image> -- the full path to the kernel image (default: the image
# as reported by dist-kernel_get_image_path() in the ${KV_DIR})
#
# <system.map> -- the full path to the System.map
# (default: ${KV_DIR}/System.map})
#
# <dir> -- the target directory to install to (default: ${EROOT}/boot)
#
# <installkernel-args> -- extra optional arguments for installkernel
# see man kernel-install and man installkernel. Requires at
# least version 56 of sys-kernel/installkernel.
dist-kernel_install_kernel() { dist-kernel_install_kernel() {
debug-print-function ${FUNCNAME} "$@" debug-print-function ${FUNCNAME} "$@"
[[ ${#} -eq 3 ]] || die "${FUNCNAME}: invalid arguments" local version=${1:-${KV_FULL}}
local version=${1} local image=${2:-${KV_DIR}/$(dist-kernel_get_image_path)}
local image=${2} local map=${3:-${KV_DIR}/System.map}
local map=${3} local dir=${4:-${EROOT}/boot}
local installkernel_args=(
"${version}" "${image}" "${map}" "${dir}"
)
if has_version ">=sys-kernel/installkernel-56"; then
installkernel_args+=( "${@:5}" --verbose )
fi
local success= local success=
# not an actual loop but allows error handling with 'break' # not an actual loop but allows error handling with 'break'
@ -107,8 +126,7 @@ dist-kernel_install_kernel() {
ebegin "Installing the kernel via installkernel" ebegin "Installing the kernel via installkernel"
# note: .config is taken relatively to System.map; # note: .config is taken relatively to System.map;
# initrd relatively to bzImage # initrd relatively to bzImage
ARCH=$(tc-arch-kernel) installkernel "${version}" "${image}" "${map}" \ ARCH=$(tc-arch-kernel) installkernel "${installkernel_args[@]}" || break
"${EROOT}/boot" || break
eend ${?} || die -n "Installing the kernel failed" eend ${?} || die -n "Installing the kernel failed"
success=1 success=1
@ -129,39 +147,49 @@ dist-kernel_install_kernel() {
eerror "in the logs above and once you resolve the problems please" eerror "in the logs above and once you resolve the problems please"
eerror "run the equivalent of the following command to try again:" eerror "run the equivalent of the following command to try again:"
eerror eerror
if has --all "${installkernel_args[@]}"; then
eerror " installkernel ${installkernel_args[*]}"
else
eerror " emerge --config ${kernel}" eerror " emerge --config ${kernel}"
fi
die "Kernel install failed, please fix the problems and run emerge --config" die "Kernel install failed, please fix the problems and run emerge --config"
fi fi
} }
# @FUNCTION: dist-kernel_reinstall_initramfs # @FUNCTION: dist-kernel_reinstall_initramfs
# @USAGE: <kv-dir> <kv-full> # @USAGE: [<kv-dir>] [<kv-full>] [<installkernel-args>...]
# @DESCRIPTION: # @DESCRIPTION:
# Rebuild and install initramfs for the specified dist-kernel. # Rebuild and install initramfs for the specified dist-kernel.
# <kv-dir> is the kernel source directory (${KV_DIR} from linux-info), # Takes the following arguments:
# while <kv-full> is the full kernel version (${KV_FULL}). #
# The function will determine whether <kernel-dir> is actually # <kv-dir> -- the full path to the target kernel (default: ${KV_DIR})
# a dist-kernel, and whether initramfs was used. #
# <kv-full> -- the target kernel version (default: ${KV_FULL})
#
# <installkernel-args> -- extra optional arguments for installkernel
# see man kernel-install and man installkernel. Requires at
# least version 56 of sys-kernel/installkernel.
# #
# This function is to be used in pkg_postinst() of ebuilds installing # This function is to be used in pkg_postinst() of ebuilds installing
# kernel modules that are included in the initramfs. # kernel modules that are included in the initramfs. In order to
# reinstall *all* distribution kernels currently installed on the
# system add the --all argument (requires installkernel-56 or newer).
dist-kernel_reinstall_initramfs() { dist-kernel_reinstall_initramfs() {
debug-print-function ${FUNCNAME} "$@" debug-print-function ${FUNCNAME} "$@"
[[ ${#} -eq 2 ]] || die "${FUNCNAME}: invalid arguments" local kernel_dir=${1:-${KV_DIR}}
local kernel_dir=${1} local ver=${2:-${KV_FULL}}
local ver=${2}
local image_path=${kernel_dir}/$(dist-kernel_get_image_path) local image_path=${kernel_dir}/$(dist-kernel_get_image_path)
if [[ ! -f ${image_path} ]]; then if [[ ! -f ${image_path} ]]; then
eerror "Kernel install missing, image not found:" eerror "Kernel install missing, image not found:"
eerror " ${image_path}" eerror " ${image_path}"
eerror "Initramfs will not be updated. Please reinstall your kernel." eerror "Initramfs will not be updated. Please reinstall kernel ${ver}."
return return
fi fi
dist-kernel_install_kernel "${ver}" "${image_path}" \ dist-kernel_install_kernel "${ver}" "${image_path}" \
"${kernel_dir}/System.map" "${kernel_dir}/System.map" "${EROOT}/boot" "${@:3}"
} }
# @FUNCTION: dist-kernel_PV_to_KV # @FUNCTION: dist-kernel_PV_to_KV