Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] Automatically modifying custom "forked" .ebuilds
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
JarzaClay
n00b
n00b


Joined: 21 Aug 2024
Posts: 23

PostPosted: Wed Aug 21, 2024 8:36 pm    Post subject: Automatically modifying custom "forked" .ebuilds Reply with quote

I want to modify the gentoo-sources ebuild to include this snippet:

Code:
post_pkg_postinst() {
# Eselect the new kernel or genkernel will build the current one
   eselect kernel set linux-"${KV}"
   CURRENT_KV=$(uname -r)
# Check if genkernel has been run previously for the running kernel and use that config
   if [[ -f "${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" ]] ; then
      genkernel --no-module-rebuild --kernel-config="${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" all
# Use latest kernel config from current kernel
   elif [[ -f "${EROOT}/usr/src/linux-${CURRENT_KV}/.config" ]] ; then
      genkernel --no-module-rebuild --kernel-config="${EROOT}/usr/src/linux-${CURRENT_KV}/.config" all
# Use known running good kernel
   elif [[ -f /proc/config.gz ]] ; then
      zcat /proc/config.gz >> "${EROOT}/tmp/genkernel.config"
      genkernel --no-module-rebuild --kernel-config="${EROOT}/tmp/genkernel.config" all
      rm "${EROOT}/tmp/genkernel.config"
# No valid configs known, compile a clean one
   else
      genkernel --no-module-rebuild all
   fi
}


How can I do this, and also pull the lastest version when updating with portage, without having to rewrite it every update?


Last edited by JarzaClay on Mon Aug 26, 2024 3:51 pm; edited 1 time in total
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20485

PostPosted: Wed Aug 21, 2024 10:33 pm    Post subject: Reply with quote

Create your own repository:
https://wiki.gentoo.org/wiki/Creating_an_ebuild_repository

You could also intercept what the regular ebuild does:
https://wiki.gentoo.org/wiki//etc/portage/bashrc

An example of the latter I use for pruning what linux-firmware installs:
https://forums.gentoo.org/viewtopic-t-1155439.html
_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
JarzaClay
n00b
n00b


Joined: 21 Aug 2024
Posts: 23

PostPosted: Wed Aug 21, 2024 10:50 pm    Post subject: Reply with quote

How could I do this by hosting my own repository? I wouldn't like to necessarily maintain it, I just want it to automatically pull the latest package version, while maintaining the same post_pkg_postinst() declaration. Is there a way that I could just add changes from other parts of the ebuild, and disregard updates to post_pkg_postinst()?
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22648

PostPosted: Wed Aug 21, 2024 11:09 pm    Post subject: Reply with quote

Isn't post_pkg_postinst reserved for use outside the ebuild, such that you can guarantee the ebuild will not define that function? Anything the ebuild needs for this phase should be in pkg_postinst. If so, a bashrc hook defining post_pkg_postinst for this package should suffice, and would let you avoid ever modifying the ebuild.
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20485

PostPosted: Thu Aug 22, 2024 12:20 am    Post subject: Reply with quote

JarzaClay wrote:
How could I do this by hosting my own repository? I wouldn't like to necessarily maintain it, I just want it to automatically pull the latest package version, while maintaining the same post_pkg_postinst() declaration. Is there a way that I could just add changes from other parts of the ebuild, and disregard updates to post_pkg_postinst()?
You mentioned wanting to modify an ebuild. The only way to really do that is to put it in a local repository. I wasn't familiar with post_pkg_postinst() and didn't realize it wasn't a "real" ebuild function. So that wouldn't modify the ebuild itself.

The portage bashrc concept would be the correct method. One thing to remember is that it runs for every package. So instead...

You'd put your function in:
/etc/portage/env/sys-kernel/gentoo-sources

I don't know if putting it in there itself is sufficient. I've used it without a function and added my own checks, so that's probably not the best method, but it works.
_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
JarzaClay
n00b
n00b


Joined: 21 Aug 2024
Posts: 23

PostPosted: Thu Aug 22, 2024 1:46 pm    Post subject: Reply with quote

Thank you guys for all of your help! I was under the impression that this was a function of an ebuild, but it isn't. Thanks again for all of your help, I will test this tonight!
Back to top
View user's profile Send private message
sam_
Developer
Developer


Joined: 14 Aug 2020
Posts: 1961

PostPosted: Fri Aug 23, 2024 2:03 pm    Post subject: Reply with quote

That said, what you're doing is essentially what gentoo-kernel does. Please consider using that.
Back to top
View user's profile Send private message
spica
Guru
Guru


Joined: 04 Jun 2021
Posts: 330

PostPosted: Sun Sep 01, 2024 7:39 am    Post subject: Re: Reply with quote

JarzaClay wrote:
I want to modify the gentoo-sources ebuild [...] and also pull the lastest version when updating with portage, without having to rewrite it every update?


In general programming, when we re-use code from another file, we either copy the block of code or include the whole file.
Since the https://projects.gentoo.org/qa/policy-guide/ebuild-format.html#pg0102 policy requires that code be contained in ebuild/class files, and sourceing/evaling is not allowed for non-ebuild/class files, this makes it semiacceptable/semiforbiddable to source other ebuild files in a locally managed ebuild.This approach seems unpredictable and is not recommended https://forums.gentoo.org/viewtopic-t-1163131-highlight-.html
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo 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