From: Redjard <eselect.patches.gentoo@redjard.org>
Add Hooks to Eselect
For example for "eselect kernel list" the script /etc/eselect/hooks/kernel/list/pre
is called before the eselect acts, and
/etc/eselect/hooks/kernel/list/post afterwards.
In the functions you can use and modify $params, the value of which the do_<action> function of the respective select module is then called with.
by Redjard 2023-08-18 (eselect.patches.gentoo@redjard.org)
https://discord.com/channels/249111029668249601/1140975737168478279
From: Redjard <eselect.patches.gentoo@redjard.org>
Add Hooks to Eselect
For example for "eselect kernel list" the script /etc/eselect/hooks/kernel/list/pre is called before the eselect acts,
and /etc/eselect/hooks/kernel/list/post afterwards.
You have to provide the rationale here. You can't expect people to signMy bad, not much of value is locked in the proprietary service but I
up for some shady third-party service to read it.
if [ "$EUID" -ne 0 ]; then die "run as root please"; fi/etc/eselect/hooks/kernel/set/pre:
# (re)generate /etc/portage/sets/active_kernels which selects the/etc/eselect/hooks/kernel/set/post:
On Mon, 21 Aug 2023, Redjard wrote:
To roughly summarize, I was asking for a method to hook into eselect,
to modify the behavior of eselect kernel set.
I was pointed in the direction of a user patch by konsolebox, and consequently wrote the patch.
I provided an example for using the patched hooks, which I will repeat
below.
-check_do() {
+check_do() {
local function=$1
- shift
+ shift; params="$@"
if is_function "${function}" ; then
- ${function} "$@"
+ run_hook "${ESELECT_MODULE_NAME}" "${function##do_}" pre
+ ${function} "${params}"
+ run_hook "${ESELECT_MODULE_NAME}" "${function##do_}" post
else
die "No function ${function}"
fi
}
Suggestion: A more flexible approach would make pre/post directories, such that "any" file therein (exceptions for backups, etc) would be sourced.
In run_hook something like (as written assumes bashisms OK, didn't verify
if that's valid for eselect or not):
local action=$1
local subaction=$2
local hookscriptdir=$3
for $hookfile in
/etc/eselect/hooks/${action}/${subaction}/${hookscriptdir}/*
do [[
# maybe skip either the executable or README test?
# or perhaps only match *.sh filenames instead
# to reflect the in-shell sourcing?
-x $hookfile &&
$hookfile == ${hookfile#README} &&
$hookfile == ${hookfile#.} &&
$hookfile == ${hookfile%.bak} &&
$hookfile == ${hookfile%\~}
]] && source "$hookfile"
done
regcomp(&classicalre, "^[a-zA-Z0-9_-][a-zA-Z0-9._-]+$",REG_EXTENDED | REG_NOSUB)which curiously appears to be different from upstream "^[a-zA-Z0-9_-]+$",
On Mon, 21 Aug 2023, Redjard wrote:
I did consider doing so, however with that approach my effective fork
of the kernel.eselect module would get continually outdated, while a
wrapper module requires a different command [...]
In addition to user patches, you can also put your own modules in the ${HOME}/.eselect/modules/ directory.
For example, you could either copy kernel.eselect to there and modify
it. Or, you could have a mykernel.eselect module, along these lines:
Also, by design, eselect itself doesn't rely on any configuration in
/etc so this would be a somewhat intrusive change.
# l /etc/eselect/
total 4.0K
drwxr-xr-x 1 root root 48 2023-08-15 19:59:07 .
drwxr-xr-x 1 root root 3.0K 2023-08-21 12:07:30 ..
drwxrwxr-x 1 root root 12 2023-08-15 19:59:31 hooks
-rw-r--r-- 1 root root 1.6K 2023-05-19 16:57:34 repository.conf
drwxr-xr-x 1 root root 120 2023-08-10 03:09:50 wine
As a side note, your previously posted patch wouldn't work as-is:
- ${function} "$@"Using a scalar variable instead of "$@" (which is an array) would break
+ ${function} "${params}"
quite a few modules.
Sorry, but I don't see much incentive for adding such a hook mechanism.
created in 2005. Also, by design, eselect itself doesn't rely on any configuration in /etc so this would be a somewhat intrusive change.
Suggestion: A more flexible approach would make pre/post directories,
do [[
# maybe skip either the executable or README test?
# or perhaps only match *.sh filenames instead
# to reflect the in-shell sourcing?
-x $hookfile &&
$hookfile == ${hookfile#README} &&
$hookfile == ${hookfile#.} &&
$hookfile == ${hookfile%.bak} &&
$hookfile == ${hookfile%\~}
]] && source "$hookfile"
done
On Mon, 21 Aug 2023, konsolebox wrote:
This actually allows users to virtually extend an eselect module without needing to fork it. The things people can do are endless.
First, changing a low-level function like check_do() is really a no-no, because this function is documented in the eselect developer guide and third-party modules may rely on it.
check_do
The check_do utility function checks that the first parameter is a
function, and then calls it with any additional parameters as its
arguments. If the function does not exist, die is called.
Again, this is mostly internal.
[...] Given that eselect modules are normally run as root and the damage that can result from bugs, I'd rather keep things simple, instead of introducing "endless" possibilities. This approach has worked very well during the last 18 years.
Second, instead of executing a separate script for every hook, there [should] be a file defining shell functions for all subactions of a
given module. But I haven't thought about any details, because as I
said, I don't see much incentive for such a thing.
If there was, it would have been suggested previously
since eselect was created in 2005.
This isn't what eselect modules were designed for. They are specialised tools that are supposed to do one thing, and one thing only. It's like suggesting that a command like cat or mv would need configuration or
some extension mechanism.
On Mon, 21 Aug 2023, konsolebox wrote:
This actually allows users to virtually extend an eselect module without needing to fork it. The things people can do are endless.
This isn't what eselect modules were designed for. They are specialised
tools that are supposed to do one thing, and one thing only.
suggesting that a command like cat or mv would need configuration or
some extension mechanism.
that can result from bugs, I'd rather keep things simple, instead of introducing "endless" possibilities. This approach has worked very well during the last 18 years.
(If anything, a hook mechanism would look very different from what was proposed here. First, changing a low-level function like check_do() is
really a no-no, because this function is documented in the eselect
developer guide and third-party modules may rely on it. Second, instead
of executing a separate script for every hook, there would be a file
defining shell functions for all subactions of a given module. But I
haven't thought about any details, because as I said, I don't see much incentive for such a thing.)
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 407 |
Nodes: | 16 (2 / 14) |
Uptime: | 15:44:41 |
Calls: | 8,555 |
Calls today: | 7 |
Files: | 13,219 |
Messages: | 5,925,786 |