[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#1116709: hw-detect: list_deb_firmware() does not find files in trixie packages after /usr merge



Cyril Brulebois <kibi@debian.org> writes:

> [ Re-adding submitter… ]
>
> Philip Hands <phil@hands.com> (2025-09-30):
>> alexander barakin <alex@barak.in> writes:
>> 
>> >  list_deb_firmware () {
>> >  	udpkg -c "$1" \
>> > -		| grep '^\./lib/firmware/' \
>> > -		| sed -e 's!^\./lib/firmware/!!' \
>> > +		| grep '^\.\(/usr\)\?/lib/firmware/' \
>> > +		| sed -e 's!^\.\(/usr\)\?/lib/firmware/!!' \
>> >  		| grep -v '^$'
>> >  }
>> 
>> Here's a variation on that which avoids the `grep | sed | grep` pipe,
>> and takes advantage of the fact that we have support for -E in d-i.
>> 
>>   https://salsa.debian.org/installer-team/hw-detect/-/merge_requests/14
>
> If we go for that, maybe include some comments to explain what that's
> doing, so that non-sed experts can grok what's happening?

Looking at this particular example:

	udpkg -c "$1" | sed -nE 's!^\.(/usr)?/lib/firmware/(.)!\2!p'

The things that make that work are:

  `-n` option and the 'p' flag at the end of the pattern:

     The `-n` tells sed to suppress its output, which we do in order to
     not need the initial grep that was selecting just the line we're
     interested in. The sed replacement pattern then selects that line,
     and does a replacement, and the `p` means:

       If the pattern matched, print the resulting pattern space
       (so what's on the line after the substitution).

  `-E` means "Use extended regular expressions" which is why I can get
       away without backslash-escaping the parentheses.

  `\2` this is whatever the second match was, which is the single
       character after the slash that is matched by `(.)`.  The reason
       for that is to make sure that the pattern does not match the
       directory that the `grep -v '^$'` was there to remove, and since
       it does not match, the line is suppressed by the `-n` and there
       is no need to have a final grep to get rid of it.

       Since we stop matching at that character, whatever's left on the
       rest of the line will be untouched, and will therefore be
       "printed" to STDOUT as a result of the `p` flag.


A very quick grep seems to show that the `sed -e ...p` usage appears 216
times in the existing D-I code. The use of a `\2` is seen 46 times, with
`\1` (so the same concept) used 353 times, while `-E` is obviously a
more recent arrival, with only 11 hits.

I'm sure we don't want to add comments to all of those instances, so
perhaps we need a README.sed (or some such) covering the features that
actually get used in D-I, and the ways of doing things that do not
involve redundant pipelines with repetitive (and thus hard to maintain)
parameters.

If you like, I could start the README as another MR, using the above
explanation as an initial draft.  Perhaps that could grow into a more
general guide of what works or doesn't in the D-I environment, in which
case it needs a better name.

Cheers, Phil.
-- 
Philip Hands -- https://hands.com/~phil


Reply to: