Automatically run a script when entering a toolbox container

Hi all ! (new registered user here)

I’ve been toying with Fedora Silverblue since two days, and I must say this is the most thrilling new thing since a lot of time.

I’m now trying to adapt my old workflows to operate with Silverblue.

At the moment I’m stuck with running a script when I’m entering a specific toolbox. For instance, in my python-dev toolbox container, I would like to automatically load virtualenvwrapper related scripts.

On my old non-silverblue installation, it was done in my .bashrc file because virtualenvwrapper was installed system wide. But putting it in the .bashrc shared with multiple containers and the host system seems wrong to me.

How would you do it ?

Thanks :slight_smile:

Would something like this in .bashrc work?

# If inside toolbox do something
if [[ "$(hostname)" = "toolbox" ]]; then
	do something

That was my first thought too.

But it does not tell which container is actually activated and I did not see any environment variable hosting the information.

This sounds like a good case for an enhancement to toolbox. Should be pretty easy to set an env var that has a configurable container name.

Could you file an issue upstream?

I’ve been reading opened issues and pending PR on the project repository. seems to be a good candidate for my use case if we mix it with the answer of @returntrip. However, having a dedicated env var to store the container name should be available too.

I will take a more in depth look at the project to submit an issue and/or a pull request.



Did anything come of this? I would like to automatically modify the prompt within each toolbox so it includes the container name, so I can more easily keep track of which toolbox I am in.



Hi !

Actually, I did not make a PR on Github because of my lack of time. However here is the solution I use on my system (F32 Silverblue).

This patch will modify toolbox to set an environment variable CONTAINER_NAME in the toolbox container :

--- /usr/bin/toolbox	1970-01-01 01:00:00.000000000 +0100
+++ /usr/local/bin/toolbox	2020-05-24 16:14:27.769552891 +0200
@@ -414,6 +414,8 @@
+              environment_options="$environment_options --env=CONTAINER_NAME=$toolbox_container"
               if ! (echo "$environment_options" | grep COLUMNS >/dev/null 2>&3) && [ "$columns" != "" ] 2>&3; then
                   environment_options="$environment_options --env=COLUMNS=$columns"

Then, my .bashrc is modified by appending these lines:

if [ -f "$HOME/.config/toolbox/bashrc/$CONTAINER_NAME" ]; then
        . "$HOME/.config/toolbox/bashrc/$CONTAINER_NAME"

This will execute the script located in ~/.config/toolbox/bashrc with the same name as the container name.

I hope this late answer will help some of you.