Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Prune linux-firmware non-greedy
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 19505

PostPosted: Wed Aug 03, 2022 8:43 pm    Post subject: Prune linux-firmware non-greedy Reply with quote

Prerequisites:
File names of firmware to be retained.
Some ability to work with awk regular expressions (or an alternative tool, suitably exchanged for awk).

What it does:
Applies a filter based on a common portion of firmware filenames.
Intercepts the emerge process during the install phase, replacing contents of the "WHENCE" file to contain only filtered list of files.
Creates a linux-firmware-<version> savedconfig file during the instprep phase.
Portage continues the install as normal, only installing the desired firmware files and an appropriate savedconfig file.

Partial example:
(output shortened, including use of "wc -l")
Code:
$ ebuild /var/db/repos/gentoo/sys-kernel/linux-firmware/linux-firmware-20220708.ebuild install
$ cd /var/tmp/portage/sys-kernel/linux-firmware-20220708/temp/

awk pattern match keeping all rtl_nic files or select rtl_nic files:
Code:
$ awk '/rtl_nic/ { print $0 }' WHENCE |wc -l
31
$ awk '/rtl_nic\/rtl8(168|411)/ { print $0 }' WHENCE |wc -l
15
Modify the awk pattern match to suit your needs.

New hardware requires new files:
Either move the file from he env path location temporarily.
Or use the previously show ebuild command to identify new files (located in /var/tmp/portage/sys-kernel/linux-firmware-20220708/work/).


The code:
TODO (someday): Store patterns in variables.

/etc/portage/env/sys-kernel/linux-firmware:
# Ebuild Phase: install
if [ "${CATEGORY}" == "sys-kernel" ] && \
   [ "${PN}" == "linux-firmware" ]   && \
   [ "${EBUILD_PHASE}" == "install" ]
then
        local wf
        wf="${WORKDIR}/${P}/WHENCE"

        /bin/cp -a ${wf} ${T}/ \
            || die "Error copying ${wf} to temp directory."

        awk '/(rtl_nic\/rtl8(168|411)|amd-ucode\/microcode_amd(_fam16h)?.bin)/ { print $0 }' "${T}/WHENCE" > "${wf}" \
            || die "Error creating new ${wf} file."
fi


# Ebuild Phase: instprep
if [ "${CATEGORY}" == "sys-kernel" ] && \
   [ "${PN}" == "linux-firmware" ]   && \
   [ "${EBUILD_PHASE}" == "instprep" ]
then
        local sc

        sc="${D}/etc/portage/savedconfig/sys-kernel/${P}"
        /bin/cp -a ${sc} ${T}/ \
            || die "Error copying ${sc} to temp directory."

        awk '/^#/ { print $0 }' "${T}/${P}" > "${sc}" \
            || die "Error preparing new ${sc} file."
        awk '/^(amd|rtl)/ { print $0 }' "${T}/${P}" |sort >> "${sc}" \
            || die "Error populating new ${sc} file."
fi

_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum