isbm / berrymill

Think of it as Kiwi++
MIT License
2 stars 5 forks source link

No executable bash found #57

Open wintron04 opened 1 year ago

wintron04 commented 1 year ago

Edge Case:

I have an appliance.kiwi with this section:

<packages type="delete">
<package name="bash"/>
</packages>

The package "bash" is getting deleted! This will happen directly after the config.sh is called by kiwi. After this kiwi will execute images.sh. This will fail with the error that no bash executable could be found on the image!

This can be fixed: Set the executable bit for images.sh (see at 1. https://documentation.suse.com/appliance/kiwi-9/single-html/kiwi/index.html#description-components)

Possible Solutions:

Thoughts on this? @isbm @JiyangLiuG

wintron04 commented 1 year ago

Also the images.sh (to my knowledge) has to have this shebang: #!/bin/dash

!/bin/bash will result in " image/images.sh No such file or directory"

isbm commented 1 year ago

@wintron04 But that's not a problem per se, right? Your images.sh can be also static binary written e.g. in C or Go. It is surely uncomfortable that Kiwi can shoot itself in a foot, but Kiwi runs that script in a chroot, and thus requires the runtime.

This is certainly a Kiwi's fundamental design flaw where Kiwi scripts are sharing the runtime, being a part of the target build. This is surely wrong approach.

To fix this, we need to ensure that those hooks like image.sh or config.sh etc should be entirely independent. One way of doing this is introducing own static shell runtime as a binary, and then removing it after everything is finished.

For example, we can package NuShell or ash etc as static binaries and then sneak them in as e.g. /usr/bin/berryshell with shebang like #!/usr/bin/berryshell, allowing these scripts run independently. If you want to make it really detached, we can call them /usr/bin/berryshell-<random-prefix> and patch image.sh/config.sh/whatever.sh to that, right before it is called and then disposed. At the end of the cycle we can then safely purge the shell binary from the target image.

Ignoring this problem is probably not a best idea, because Berrymill is doing exactly that: fixing Kiwi's flaws.

wintron04 commented 1 year ago

@isbm So something like this?:

  1. package e.g. ash
  2. enhance berrymill to modify appliance.kiwi to include a locally available package (berryshell) in image build
  3. automatically patch shebang in *.sh scripts
  4. bring kiwi to purge berryshell after scripts ran
  5. act like nothing ever happened
isbm commented 1 year ago

@wintron04 So berrymill should come to your machine together with e.g. NuShell, which is there for just a general use. However, NuShell package should have two packages: nushell-static and nushell, where berrymill would install only -static one. And then simply copy /usr/bin/nushell to $CURRENTLY_MOUNTED_KIWI_IMAGE/usr/bin and replace shebang of each external hook as #!/usr/bin/nushell for example, and then copy there as well and run.

Then cleanup all that copied stuff.