RPi-Distro / pi-gen

Tool used to create the official Raspberry Pi OS images
BSD 3-Clause "New" or "Revised" License
2.58k stars 1.61k forks source link

Is adding random environment variables to config supported? #674

Closed maxpavlov closed 1 year ago

maxpavlov commented 1 year ago

Can I add my own environment variable to config and expect it to be available for all the .sh scripts that execute during a build? Something like

IMG_NAME="Essential-zero" 
RELEASE="bullseye" 
MY_CUSTOM_VARIABLE=1

Thanks.

bdh1993 commented 1 year ago

As far as I know, it doesn't matter if you put any environment variables in the config file.

You can already see it working well elsewhere.

For example, you can view the FIRST_USER_NAME variable in "build.sh".

This variable is specified only for build.sh, but is used in the file "stage2/01sys-tweaks/01-run.sh".

Variables must be "export" from "build.sh."

image

maxpavlov commented 1 year ago

Thank you @bdh1993 for the comment. Yes, putting a variable in a config file and 'export'ing it from a build.sh would propagate it's availability to the "sub-scripts". However I wonder what is the proper way to add the environment variable into a pipeline so that it's available in "sub-scripts", without a need to export it from the root script.

XECDesign commented 1 year ago

I haven't tried it, but I don't see why an export wouldn't work from the config file. IIRC, it gets sourced by the main build script, so it should be the same.

maxpavlov commented 1 year ago

Yes, export works. So to get it to work you add a variable to config and 'export' it from the build.sh. Minimum of two actions to make a custom env var available to stage scripts.

It works well, I'll close this one. Thanks.

MexHigh commented 6 months ago

How would you need to modify the build-docker.sh in order to accomplish this? I want to access a custom variable in a XX-run-chroot.sh script