Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Ignore environment variable stored in binary package
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
bell
Guru
Guru


Joined: 27 Nov 2007
Posts: 510

PostPosted: Fri Jan 12, 2024 5:27 am    Post subject: Ignore environment variable stored in binary package Reply with quote

I maintain overlay for custom device ebuilds and run a binhost for them. Some of ebuilds should be able for optional to update files to (boot)-SD-Card.
Any user is able to mount the device to any place. My idea was: If the user set
Code:
SDCARD_MOUNT_POINT=/mnt/xyz
into make.conf, the files are updated in pkg_preinst() into this place.
I got a working solution already. See https://gitlab.com/bell07/gentoo-switch_overlay/-/blob/master/eclass/sdcard-mount.eclass that is used in
https://gitlab.com/bell07/gentoo-switch_overlay/-/blob/master/sys-boot/nintendo-switch-u-boot/nintendo-switch-u-boot-99999999.ebuild or example.

The major advantage was to get it working with binary provided packages. The binary package does have the variable SDCARD_MOUNT_POINT from buildhost and ignores the setting on target host.
Previosly I solved it by updating the variable with
Code:
SDCARD_MOUNT_POINT="$(portageq envvar SDCARD_MOUNT_POINT)"
in pkg_setup()

But now the emerge dies with portageq in pkg_setup is not allowed error message.
How is the right way to ignore variable value from binhost and use the variable on target?
Back to top
View user's profile Send private message
Genone
Retired Dev
Retired Dev


Joined: 14 Mar 2003
Posts: 9535
Location: beyond the rim

PostPosted: Fri Jan 19, 2024 2:30 pm    Post subject: Reply with quote

Not a direct answer, but wouldn't it be possible to specify a fixed location instead and use symlinks to redirect that to the actual target destination? Then you could also just install these files normally without having to play around with pkg_preinst, and have uninstall support (if desirable). Would be a bit more work if the target location changes regularly, but nothing that couldn't be automated.
Back to top
View user's profile Send private message
bell
Guru
Guru


Joined: 27 Nov 2007
Posts: 510

PostPosted: Tue Apr 09, 2024 6:11 am    Post subject: Reply with quote

I cannot specify and force any specific location.
The partition is like EFI partition, a vfat partition for bootloader files. Or maybe the better comparison is to the raspberry first sdcard partition. The ebuilds should update the bootloader files (bl31.bin, bl33.bin and more) in a bootloader subfolder.
The difference is, the fvat partition contain all user files from vendor OS, so user should be able to access the partition as usual.

Some users mount the partition to /boot - But I do not like to have the linux kernel in the / of this partition, visible for user.
I prefer the /media/sdcard and install the kernel into /boot on the system (ext4) partition. The used bootloader (u-boot) is able to read the kernel from ext4

My hacky solution is
Code:
-   SDCARD_MOUNT_POINT="$(portageq envvar SDCARD_MOUNT_POINT)"
+   CR="${PORTAGE_CONFIGROOT}"
+   if [[ -z "${CR}" ]]; then
+      CR="${ROOT}"
+   fi
+   SDCARD_MOUNT_POINT="$(cat "${CR}"/etc/portage/make.conf | grep SDCARD_MOUNT_POINT= | tail -n 1| sed 's/^.*="//g;s/"$//g')"


Still open for proposals
Back to top
View user's profile Send private message
Genone
Retired Dev
Retired Dev


Joined: 14 Mar 2003
Posts: 9535
Location: beyond the rim

PostPosted: Tue Apr 09, 2024 10:20 am    Post subject: Reply with quote

I think you misunderstood me. It is clear that the actual storage location can't be fixed.
The idea was that instead of using an environment variable to determine it you use a known symlink. So say the user mounts the sd card under /media/sdcard, you create a symlink like /mnt/portage-sdcard-target -> /media/sdcard. The ebuild then installs all files that should go to the sdcard into /mnt/portage-sdcard-target instead of resolving SDCARD_MOUNT_POINT. When the user unmounts the sdcard the symlink is removed again. So the built packages will always have the files that will go to the sdcard in the same location, but due to the symlink they will actually be stored on the sdcard mountpoint.
That way you don't need any special hacks, only logic to create/remove the symlink properly when the sdcard is mounted (which isn't much more complex than setting an environment variable). Only downsides that I can see atm is that you can't specify this per process, so it wouldn't support installing packages to different mountpoints at the same time. But quite possible I'm missing something here. On the Upside you'd get proper uninstall support and could easily check which packages have stuff installed on sdcards even if the mountpoint was changed in between installations.

Working around explicit portage restrictions is usually a bad idea as it will most likely bite you at a later point.
Back to top
View user's profile Send private message
bell
Guru
Guru


Joined: 27 Nov 2007
Posts: 510

PostPosted: Wed Apr 10, 2024 6:50 am    Post subject: Reply with quote

The main idea is to provide the files trough binary packages, but decide on the client if the files should be installed into mounted vfat partition or not.

The files are installed into /usr/share/sdcard1, then optional in addition in pkg_preinst into the mounted partition.

Of course the way, using symlink is valid. Fully remove the sdcard-mount eclass and just to propose to set the symlink at /usr/share/sdcard1.
The hacky part this way is to handle the broken symlink if the partition is not mounted.

The second difference is, I recommend to set CONFIG_PROTECT="$SDCARD_MOUNT_POINT", and keep /usr/share/sdcard1 unprotected to keep the upstream configuration files.

Currently the hacky solution with manually parsing the make.conf does work for me. I estimate the number of users is in the single digits range, so I keep it as is, till anyone run into any issue.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming 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