Gentoo Archives: gentoo-commits

From: "Ulrich Müller" <ulm@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/eselect:master commit in: modules/, /, man/
Date: Wed, 15 Mar 2023 11:04:45
Message-Id: 1678878262.d5bd4e5f8d28c3fc6e7d15d639538ac9b6459e7a.ulm@gentoo
1 commit: d5bd4e5f8d28c3fc6e7d15d639538ac9b6459e7a
2 Author: Florian Schmaus <flow <AT> gentoo <DOT> org>
3 AuthorDate: Tue Mar 14 10:02:59 2023 +0000
4 Commit: Ulrich Müller <ulm <AT> gentoo <DOT> org>
5 CommitDate: Wed Mar 15 11:04:22 2023 +0000
6 URL: https://gitweb.gentoo.org/proj/eselect.git/commit/?id=d5bd4e5f
7
8 New "update" action in kernel module
9
10 * modules/kernel.eselect (do_update, describe_update)
11 (describe_update_options): New action, attempts to update the
12 /usr/src/linux symlink to point to the sources of the running
13 kernel. Bug 901209.
14 * man/kernel.eselect.5: Document it.
15
16 Thanks to ulm for helpful suggestions when working on this
17 functionality.
18
19 Bug: https://bugs.gentoo.org/901209
20 Signed-off-by: Florian Schmaus <flow <AT> gentoo.org>
21 [Tweaked bash syntax. Fixed highlighting in man page.]
22 Signed-off-by: Ulrich Müller <ulm <AT> gentoo.org>
23
24 ChangeLog | 6 +++++
25 man/kernel.eselect.5 | 16 ++++++++++--
26 modules/kernel.eselect | 71 +++++++++++++++++++++++++++++++++++++++++++++++++-
27 3 files changed, 90 insertions(+), 3 deletions(-)
28
29 diff --git a/ChangeLog b/ChangeLog
30 index 913494f..7bb4ea4 100644
31 --- a/ChangeLog
32 +++ b/ChangeLog
33 @@ -1,5 +1,11 @@
34 2023-03-14 Florian Schmaus <flow@g.o>
35
36 + * modules/kernel.eselect (do_update, describe_update)
37 + (describe_update_options): New action, attempts to update the
38 + /usr/src/linux symlink to point to the sources of the running
39 + kernel. Bug 901209.
40 + * man/kernel.eselect.5: Document it.
41 +
42 * libs/core.bash.in (find_module): Allow to specify an absolute
43 path as the module's filename, bug 901205.
44
45
46 diff --git a/man/kernel.eselect.5 b/man/kernel.eselect.5
47 index b3c5aa5..75d992f 100644
48 --- a/man/kernel.eselect.5
49 +++ b/man/kernel.eselect.5
50 @@ -1,7 +1,7 @@
51 -.\" Copyright 2005-2020 Gentoo Authors
52 +.\" Copyright 2005-2023 Gentoo Authors
53 .\" Distributed under the terms of the GNU GPL version 2 or later
54 .\"
55 -.TH kernel.eselect 5 "April 2009" "Gentoo Linux" eselect
56 +.TH kernel.eselect 5 "March 2023" "Gentoo Linux" eselect
57 .SH NAME
58 kernel.eselect \- The kernel symlink management module for Gentoo's eselect
59 .SH SYNOPSIS
60 @@ -14,6 +14,9 @@ kernel.eselect \- The kernel symlink management module for Gentoo's eselect
61 .I target
62 .br
63 .B eselect kernel show
64 +.br
65 +.B eselect kernel update
66 +.RB [ ifunset ]
67 .SH DESCRIPTION
68 .B eselect
69 is Gentoo's configuration and management tool. It features modules
70 @@ -45,6 +48,15 @@ output).
71 .B eselect kernel show
72 .br
73 Show the currently selected kernel.
74 +.SH ACTION: UPDATE
75 +.B eselect kernel update
76 +.RB [ ifunset ]
77 +.br
78 +Updates the /usr/src/linux symlink to point to the sources of the
79 +running kernel. If option
80 +.B ifunset
81 +is given, then the symlink will only be updated if it is not currently
82 +pointing to a valid kernel source tree.
83 .SH AUTHOR
84 Aaron Walker <ka0ttic@g.o>
85 .SH SEE ALSO
86
87 diff --git a/modules/kernel.eselect b/modules/kernel.eselect
88 index 64b5e77..e181886 100644
89 --- a/modules/kernel.eselect
90 +++ b/modules/kernel.eselect
91 @@ -1,5 +1,5 @@
92 # -*-eselect-*- vim: ft=eselect
93 -# Copyright 2005-2020 Gentoo Authors
94 +# Copyright 2005-2023 Gentoo Authors
95 # Distributed under the terms of the GNU GPL version 2 or later
96
97 DESCRIPTION="Manage the /usr/src/linux symlink"
98 @@ -125,3 +125,72 @@ do_set() {
99
100 set_symlink "$1" || die -q "Couldn't set a new symlink"
101 }
102 +
103 +### update action ###
104 +
105 +describe_update() {
106 + echo "Update the kernel symlink to running kernel"
107 +}
108 +
109 +describe_update_options() {
110 + echo "ifunset: Do not override currently set version"
111 +}
112 +
113 +do_update() {
114 + [[ -z $1 || $1 == ifunset ]] || die -q "Usage error"
115 + [[ $# -gt 1 ]] && die -q "Too many parameters"
116 + test_for_root
117 +
118 + if [[ -e ${EROOT}/usr/src/linux ]]; then
119 + if [[ ! -L ${EROOT}/usr/src/linux ]]; then
120 + # we have something strange
121 + die -q "${EROOT}/usr/src/linux exists but is not a symlink"
122 + fi
123 +
124 + if [[ $1 == ifunset ]]; then
125 + # The /usr/src/linux symlink exists, points to a path that
126 + # exists, and 'ifunset' is provided. Nothing to do.
127 + return
128 + fi
129 + fi
130 +
131 + local targets=( $(find_targets) )
132 + [[ ${#targets[@]} -gt 0 ]] || die -q "No target kernel-source trees found"
133 +
134 + local running_kernel_release
135 + running_kernel_release=$(uname -r) || die -q "uname failed with $?"
136 + local running_kernel_symlink_target="linux-${running_kernel_release}"
137 +
138 + if [[ -e ${EROOT}/usr/src/linux ]]; then
139 + local current_target
140 + current_target=$(basename "$(canonicalise "${EROOT}/usr/src/linux")")
141 + if [[ ${current_target} == "${running_kernel_symlink_target}" ]]; then
142 + # The /usr/src/linux symlink already points to the running
143 + # kernel's sources. Nothing to do.
144 + return
145 + fi
146 + fi
147 +
148 + local target
149 + for target in "${targets[@]}"; do
150 + if [[ ${target} == "${running_kernel_symlink_target}" ]]; then
151 + set_symlink "${target}"
152 + return
153 + fi
154 + done
155 +
156 + write_error_msg \
157 + "No sources for running kernel ${running_kernel_release} found."
158 + if ! is_output_mode brief; then
159 + do_list >&2
160 + fi
161 + die -q "Could not update the kernel symlink"
162 +}
163 +
164 +### helper functions ###
165 +
166 +test_for_root() {
167 + if [[ ! -w ${EROOT}/usr/src ]]; then
168 + die -q "${EROOT}/usr/src not writeable by current user. Are you root?"
169 + fi
170 +}