From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id E1EA315A7D9 for ; Wed, 15 Mar 2023 11:04:45 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 24DB6E0863; Wed, 15 Mar 2023 11:04:45 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id F40F1E0863 for ; Wed, 15 Mar 2023 11:04:44 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 004CA340B1F for ; Wed, 15 Mar 2023 11:04:44 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 589D38E0 for ; Wed, 15 Mar 2023 11:04:42 +0000 (UTC) From: "Ulrich Müller" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Ulrich Müller" Message-ID: <1678878262.d5bd4e5f8d28c3fc6e7d15d639538ac9b6459e7a.ulm@gentoo> Subject: [gentoo-commits] proj/eselect:master commit in: modules/, /, man/ X-VCS-Repository: proj/eselect X-VCS-Files: ChangeLog man/kernel.eselect.5 modules/kernel.eselect X-VCS-Directories: man/ modules/ / X-VCS-Committer: ulm X-VCS-Committer-Name: Ulrich Müller X-VCS-Revision: d5bd4e5f8d28c3fc6e7d15d639538ac9b6459e7a X-VCS-Branch: master Date: Wed, 15 Mar 2023 11:04:42 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 212fd8ef-4fae-47cb-9676-ede3cb59d28e X-Archives-Hash: 45e95b1710aa93e0d22df874366cbb33 commit: d5bd4e5f8d28c3fc6e7d15d639538ac9b6459e7a Author: Florian Schmaus gentoo org> AuthorDate: Tue Mar 14 10:02:59 2023 +0000 Commit: Ulrich Müller gentoo org> CommitDate: Wed Mar 15 11:04:22 2023 +0000 URL: https://gitweb.gentoo.org/proj/eselect.git/commit/?id=d5bd4e5f New "update" action in kernel module * modules/kernel.eselect (do_update, describe_update) (describe_update_options): New action, attempts to update the /usr/src/linux symlink to point to the sources of the running kernel. Bug 901209. * man/kernel.eselect.5: Document it. Thanks to ulm for helpful suggestions when working on this functionality. Bug: https://bugs.gentoo.org/901209 Signed-off-by: Florian Schmaus gentoo.org> [Tweaked bash syntax. Fixed highlighting in man page.] Signed-off-by: Ulrich Müller gentoo.org> ChangeLog | 6 +++++ man/kernel.eselect.5 | 16 ++++++++++-- modules/kernel.eselect | 71 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 90 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 913494f..7bb4ea4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2023-03-14 Florian Schmaus + * modules/kernel.eselect (do_update, describe_update) + (describe_update_options): New action, attempts to update the + /usr/src/linux symlink to point to the sources of the running + kernel. Bug 901209. + * man/kernel.eselect.5: Document it. + * libs/core.bash.in (find_module): Allow to specify an absolute path as the module's filename, bug 901205. diff --git a/man/kernel.eselect.5 b/man/kernel.eselect.5 index b3c5aa5..75d992f 100644 --- a/man/kernel.eselect.5 +++ b/man/kernel.eselect.5 @@ -1,7 +1,7 @@ -.\" Copyright 2005-2020 Gentoo Authors +.\" Copyright 2005-2023 Gentoo Authors .\" Distributed under the terms of the GNU GPL version 2 or later .\" -.TH kernel.eselect 5 "April 2009" "Gentoo Linux" eselect +.TH kernel.eselect 5 "March 2023" "Gentoo Linux" eselect .SH NAME kernel.eselect \- The kernel symlink management module for Gentoo's eselect .SH SYNOPSIS @@ -14,6 +14,9 @@ kernel.eselect \- The kernel symlink management module for Gentoo's eselect .I target .br .B eselect kernel show +.br +.B eselect kernel update +.RB [ ifunset ] .SH DESCRIPTION .B eselect is Gentoo's configuration and management tool. It features modules @@ -45,6 +48,15 @@ output). .B eselect kernel show .br Show the currently selected kernel. +.SH ACTION: UPDATE +.B eselect kernel update +.RB [ ifunset ] +.br +Updates the /usr/src/linux symlink to point to the sources of the +running kernel. If option +.B ifunset +is given, then the symlink will only be updated if it is not currently +pointing to a valid kernel source tree. .SH AUTHOR Aaron Walker .SH SEE ALSO diff --git a/modules/kernel.eselect b/modules/kernel.eselect index 64b5e77..e181886 100644 --- a/modules/kernel.eselect +++ b/modules/kernel.eselect @@ -1,5 +1,5 @@ # -*-eselect-*- vim: ft=eselect -# Copyright 2005-2020 Gentoo Authors +# Copyright 2005-2023 Gentoo Authors # Distributed under the terms of the GNU GPL version 2 or later DESCRIPTION="Manage the /usr/src/linux symlink" @@ -125,3 +125,72 @@ 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 ]]; then + if [[ ! -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 ]]; then + # The /usr/src/linux symlink exists, points to a path that + # exists, and 'ifunset' is provided. Nothing to do. + return + fi + fi + + local targets=( $(find_targets) ) + [[ ${#targets[@]} -gt 0 ]] || die -q "No target kernel-source trees found" + + local running_kernel_release + running_kernel_release=$(uname -r) || die -q "uname failed with $?" + local running_kernel_symlink_target="linux-${running_kernel_release}" + + if [[ -e ${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 + for target in "${targets[@]}"; do + if [[ ${target} == "${running_kernel_symlink_target}" ]]; then + set_symlink "${target}" + return + fi + done + + write_error_msg \ + "No sources for running kernel ${running_kernel_release} found." + if ! is_output_mode brief; then + do_list >&2 + fi + die -q "Could not update the kernel symlink" +} + +### helper functions ### + +test_for_root() { + if [[ ! -w ${EROOT}/usr/src ]]; then + die -q "${EROOT}/usr/src not writeable by current user. Are you root?" + fi +}