You are not logged in.
Hi!
I'm trying to figure out how to make a configurable mkinitcpio hook. I.e. let the user configures something according to their needs/system for a more generic hook.
Important background: I've adapted a backlight hook for my thinkpad (to switch on the backlight for LUKS password prompt during boot, so that I can type it in the dark) from l14kbdlight by primalmotion.
Here are my hook and install scripts:
tpkbdbl-hook
#!/usr/bin/bash
run_hook() {
echo 1 > "/sys/class/leds/tpacpi::kbd_backlight/brightness"
}
# vim: set ft=sh ts=4 sw=4 et:tpkbdbl-install:
#!/bin/bash
build() {
add_module thinkpad_acpi
add_runscript
}
help() {
cat <<HELPEOF
Turns on Librem 14 keyboard backlight.
HELPEOF
}
# vim: set ft=sh ts=4 sw=4 et:Now, this works, but of course it is very inefficient to write an install script and a hook for every laptop, as every laptop out there probably has a different ACPI module (if any) required to control the backlight, different node for controlling it and a dfferent value(s) applicable.
As an exercise, I'm trying to make a more generic hook.
I've created a /etc/mkinitcpio.conf.d/kbdbl.conf :
# The name of the (ACPI) module required for the Kernel to enable controlling the backlight
KBDBL_MODULE=thinkpad_acpi
# The node to control the backlight:
KBDBL_NODE=/sys/class/leds/tpacpi::kbd_backlight/brightness
# Value to set at boot
KBDBL_VALUE=1And tried to modify the hook and install script accordingly. However, the configuration file is only used during the generation of the initrd. I.e. it will work for the install script (replacing thinkpad_acpi with $KBDBL_MODULE), not the hook itself. The hook will not inherit the environment, so this will not work:
run_hook() {
echo $KBDBL_VALUE > "$KBDBL_NODE"
}What would be the most sensible / clean way to implement "a configurable hook", for this use case?
I could use FILES in mkinitcpio.conf, add a configuration file into the initrd (/etc/kbdbl ?) and parse (just source) the configuration from the hook at boot time. But also, I feel like generating a correct plain hook to begin with might be more clean, and add less files into the initrd?
Cheers!
Last edited by Wild Penguin (2023-09-05 16:32:08)
Offline