commit: 24b0d7ec0075e5be6ebad0a2f603f9f42670d871
Author: Florian Schmaus <flow <AT> gentoo <DOT> org>
AuthorDate: Tue Mar 14 10:02:59 2023 +0000
Commit: Florian Schmaus <flow <AT> gentoo <DOT> org>
CommitDate: Tue Mar 14 12:04:18 2023 +0000
URL: https://gitweb.gentoo.org/proj/eselect.git/commit/?id=24b0d7ec
Add 'update' action to kernel module
The 'update' action attempts to update the /usr/src/linux symlink to
point to the sources of the running kernel.
Signed-off-by: Florian Schmaus <flow <AT> gentoo.org>
modules/kernel.eselect | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
diff --git a/modules/kernel.eselect b/modules/kernel.eselect
index 64b5e77..fbbf7a9 100644
--- a/modules/kernel.eselect
+++ b/modules/kernel.eselect
@@ -125,3 +125,67 @@ do_set() {
set_symlink "$1" || die -q "Couldn't set a new symlink"
}
+
+### update action ###
+
+describe_update() {
+ echo "Update the kernel symlink to running kernel"
+}
+
+describe_update_options() {
+ echo "ifunset: Do not override currently set version"
+}
+
+do_update() {
+ [[ -z $1 || $1 == ifunset ]] || die -q "Usage error"
+ [[ $# -gt 1 ]] && die -q "Too many parameters"
+ test_for_root
+
+ if [[ -e ${EROOT}/usr/src/linux && ! -L ${EROOT}/usr/src/linux ]]; then
+ # we have something strange
+ die -q "${EROOT}/usr/src/linux exists but is not a symlink"
+ fi
+
+ if [[ $1 == ifunset \
+ && -L ${EROOT}/usr/src/linux \
+ && -e ${EROOT}/usr/src/linux ]]; then
+ # The /usr/src/linux symlink exists, points to a path that
+ # exists, and 'ifunset' is provided. Nothing to do.
+ return
+ fi
+
+ local targets=( $(find_targets) )
+ local running_kernel_release=$(uname --kernel-release)
+ local running_kernel_symlink_target="linux-${running_kernel_release}"
+
+ if [[ -L ${EROOT}/usr/src/linux ]]; then
+ local current_target
+ current_target=$(basename "$(canonicalise
"${EROOT}/usr/src/linux")")
+ if [[ ${current_target} == ${running_kernel_symlink_target} ]];
then
+ # The /usr/src/linux symlink already points to the
running
+ # kernel's sources. Nothing to do.
+ return
+ fi
+ fi
+
+ local target
+ local target_list=()
+ for target in ${targets[@]}; do
+ if [[ ${target} == ${current_kernel_symlink_target} ]]; then
+ set_symlink "${target}"
+ return
+ fi
+ target_list+=("- ${target}\n")
+ done
+
+ local msg
+ msg="No kernel sources for running kernel ${running_kernel_release}
found."
+ msg+=" Available sources:\n${target_list[@]}"
+ die -q "${msg}"
+}
+
+### helper functions ###
+
+test_for_root() {
+ [[ -w ${EROOT}/usr/src ]] || die -q "${EROOT}/usr/src not writeable by
current user. Are you root?"
+}