On 2022-11-01, Arnaud Ferraris wrote:
> Le 23/09/2022 à 19:22, Vagrant Cascadian a écrit :
>> On 2022-09-23, Arnaud Ferraris wrote:
>>> On Sat, 10 Sep 2022 10:18:39 -0700 Vagrant Cascadian
>>> <vagr...@debian.org> wrote:
>>>> On 2022-06-04, Jonas Smedegaard wrote:
>>>>> Quoting Arnaud Ferraris (2022-06-04 16:39:03)
>>>>>> Currently u-boot-menu makes use of a single configuration file
>>>>>> one has to edit in order to change the default options. It could
>>>>>> be useful to use config fragments containing only one (or more)
>>>>>> variables, so that different packages could change different
>>>>>> config options (for example, one fragment could modify the
>>>>>> default cmdline, while another one could change the DTB folder).
>>>>>
>>>>> Thanks, that sounds like a useful feature indeed.
>>>>>
>>>>> Seems more sensible for me, however, to implement this using debconf.
>>>>>
>>>>> Otherwise, installation and removal of a package would need to trigger
>>>>> u-boot-menu, and u-boot-menu would need to specially examine such
>>>>> cofigfile snippets to skip snippets belonging to removed but not purged
>>>>> packages.
>>>>
>>>> Well, you could implement configuration files snippets directory outside
>>>> of /etc (e.g. /usr/share/u-boot-menu/snippet.d or something like that),
>>>> which would avoid this problem. u-boot-menu could have a dpkg trigger
>>>> that for when files in this directory change.
>>>
>>> I quite like this approach, thanks for the suggestion!
>>>
>>> Do you think allowing both /etc/u-boot-menu.d (aimed solely at
>>> end-users) and /usr/share/u-boot-menu/conf.d (for other packages and/or
>>> derivatives), with a dpkg trigger only on the latter, would make sense?
>>> Or should we aim only for the /usr/share... approach?
>> 
>> I think it's reasonable, though you'd have to encourage packages to
>> *not* use /etc/u-boot-menu*.d, maybe documenting it in
>> README.Debian...
>
> I added some notes about this in both the manpage and a (new) README.Debian
>
>> 
>> I could see a preference order being /etc/default/u-boot which is
>> overidden by /usr/share/u-boot-menu/conf.d which is overridden by
>> /etc/u-boot-menu.d (or /etc/u-boot-menu/conf.d ?).
>
> Yes, that makes the most sense to me (I also used 
> /etc/u-boot-menu/conf.d instead of /etc/u-boot-menu.d for consistency).
>
>> 
>> A fancy implementation might allow /etc to override /usr/share if the
>> filenames match, but that might be more complicated than it's
>> worth. Jonas knows I've fallen into that rabbit hole in packages of the
>> ancient past... :)
>
> Hmm, I don't think that's worth the hassle as it would add *a lot* of 
> complexity for very little gain IMHO.
>
>> 
>> 
>>>> That seems a lot simpler than introducing the complexity of debconf
>>>> generated configuration files...
>>>
>>> Indeed, so far my experiments with debconf for solving this matter have
>>> been sub-optimal at best.
>>>
>>> I'll update my patch in the next few days and submit it asap.
>
> Updated patch attached, as always comments and suggestions are welcome :)

Looks good to me! Even uses dpkg-triggers properly. :)

Thanks!

I'll merge this and take a look at anything else that needs
poking at and maybe upload soon...

live well,
  vagrant


> From 2949907b16bff2857cff0fb713967d264feb6567 Mon Sep 17 00:00:00 2001
> From: Arnaud Ferraris <aferra...@debian.org>
> Date: Tue, 1 Nov 2022 13:33:22 +0100
> Subject: [PATCH] u-boot-update: allow using config fragments
>
> In order to allow other packages and/or derivative distros to configure
> specific aspects of `u-boot-menu` it can be useful to allow using config
> fragments. This patch therefore implements loading config files from
> `/usr/share/u-boot-menu/conf.d` (to be used by other packages) and
> `/etc/u-boot-menu.d` (to be used by end-users, taking priority over
> files under the preceding location), overriding the values loaded from
> the default configuration file.
>
> This commit also adds a dpkg trigger so any modification of files under
> `/usr/share/u-boot-menu/conf.d` will result in `u-boot-update` being
> automatically run.
> ---
>  debian/README.Debian        | 32 ++++++++++++++++++++++++++++++++
>  debian/u-boot-menu.postinst |  8 ++++++++
>  debian/u-boot-menu.triggers |  1 +
>  u-boot-update               |  9 +++++++++
>  u-boot-update.8             | 16 +++++++++++++++-
>  5 files changed, 65 insertions(+), 1 deletion(-)
>  create mode 100644 debian/README.Debian
>  create mode 100755 debian/u-boot-menu.postinst
>  create mode 100644 debian/u-boot-menu.triggers
>
> diff --git a/debian/README.Debian b/debian/README.Debian
> new file mode 100644
> index 0000000..f502387
> --- /dev/null
> +++ b/debian/README.Debian
> @@ -0,0 +1,32 @@
> +Configuration files handling
> +============================
> +
> +Configuration files are read from the following locations, ordered by 
> priority:
> +1. /etc/default/u-boot
> +2. /usr/share/u-boot-menu/conf.d/*.conf
> +3. /etc/u-boot-menu/conf.d/*.conf
> +
> +Each configuration file can contain one or more environment variable and is
> +sourced by u-boot-update. See u-boot-update(8) for more information about
> +allowed variables.
> +
> +Variables values can be overriden by highest-priority configuration files. 
> For
> +example, if /etc/default/u-boot contains `U_BOOT_DEFAULT=l0` and there is a
> +file named /usr/share/u-boot-menu/conf.d/new-default.conf containing
> +`U_BOOT_DEFAULT=l0r`, then the menu entry labelled `l0r` will be set as the
> +default entry. Moreover, if there is a file named, for example,
> +/etc/u-boot-menu/conf.d/restore-default.conf containing `U_BOOT_DEFAULT=l1`,
> +then the default menu entry will be the one labelled `l1`.
> +
> +This allows flexible configuration management by allowing other packages (for
> +example, a support package for a specific device) to place configuration
> +fragment files under /usr/share/u-boot-menu/conf.d/ to override the default
> +values provided by u-boot-menu, while leaving an option for the end user to
> +get the final word by creating a configuration fragment file under
> +/etc/u-boot-menu/conf.d/.
> +
> +IMPORTANT: In order to avoid situations where the system might be rendered
> +unbootable by a package removed but not purged, other packages (or downstream
> +distributions) MUST NOT edit or modify files under /etc as those are meant 
> for
> +use by end-users only. Instead, it is mandated for such packages to install
> +their config fragments ONLY under /usr/share/u-boot-menu/conf.d/.
> diff --git a/debian/u-boot-menu.postinst b/debian/u-boot-menu.postinst
> new file mode 100755
> index 0000000..abff2bf
> --- /dev/null
> +++ b/debian/u-boot-menu.postinst
> @@ -0,0 +1,8 @@
> +#!/bin/sh
> +
> +set -e
> +
> +if [ "$1" = "triggered" ]
> +then
> +     /usr/sbin/u-boot-update
> +fi
> diff --git a/debian/u-boot-menu.triggers b/debian/u-boot-menu.triggers
> new file mode 100644
> index 0000000..ae73129
> --- /dev/null
> +++ b/debian/u-boot-menu.triggers
> @@ -0,0 +1 @@
> +interest-noawait /usr/share/u-boot-menu/conf.d
> diff --git a/u-boot-update b/u-boot-update
> index 69da211..8f3cd4f 100755
> --- a/u-boot-update
> +++ b/u-boot-update
> @@ -49,6 +49,15 @@ then
>       . /etc/default/u-boot
>  fi
>  
> +# Reading config file fragments if they exist
> +for file in /usr/share/u-boot-menu/conf.d/*.conf 
> /etc/u-boot-menu/conf.d/*.conf
> +do
> +     if [ -e "${file}" ]
> +     then
> +             . "${file}"
> +     fi
> +done
> +
>  # Reading the os-release file
>  if [ -e /etc/os-release ]
>  then
> diff --git a/u-boot-update.8 b/u-boot-update.8
> index dfc3cd7..0c936fe 100644
> --- a/u-boot-update.8
> +++ b/u-boot-update.8
> @@ -9,7 +9,19 @@ u\-boot\-update \- program to generate u\-boot menu files
>  .SH DESCRIPTION
>  u\-boot\-update is a tool used to generate the menu files
>  used by the U\-BOOT bootloader.
> -Options can be configured in /etc/default/u\-boot.
> +Options can be configured in /etc/default/u\-boot
> +or by adding configuration fragment files to /usr/share/u\-boot\-menu/conf.d/
> +(those take precedence over /etc/default/u\-boot) and/or to
> +/etc/u\-boot\-menu/conf.d/ (those take precedence over the 2 aforementioned
> +locations).
> +
> +.PP
> +
> +In order to avoid situations where the system might be rendered unbootable 
> by a
> +package removal, other packages and downstream distributions MUST NOT edit or
> +modify files under /etc as those are meant for use by end\-users only. 
> Instead,
> +it is mandated for such packages to install their config fragments ONLY under
> +/usr/share/u\-boot\-menu/conf.d/.
>  
>  .PP
>  
> @@ -126,6 +138,8 @@ Default is 'initrd.img'.
>  
>  .SH FILES
>  /etc/default/u-boot
> +/usr/share/u-boot-menu/conf.d/
> +/etc/u-boot-menu/conf.d/
>  
>  .SH HOMEPAGE
>  More information about U\-BOOT
> -- 
> 2.35.1

Attachment: signature.asc
Description: PGP signature

Reply via email to