Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Most scripts use /bin/bash, which not all systems have. Use /usr/bin/env instead? #494

Open
xplshn opened this issue Apr 13, 2024 · 11 comments

Comments

@xplshn
Copy link

xplshn commented Apr 13, 2024

Possible fixes:

  • Use /usr/bin/env bash

  • Do not use GNU things

Else, toybox can't be build on systems without bash, like Alpine, obviously it would be trivial to install bash but reducing dependencies (on non-POSIX things) would be great.

@oliverkwebb
Copy link

relevant

@landley
Copy link
Owner

landley commented Apr 14, 2024

If /bin/bash isn't a reliable absolute path, why would /usr/bin/env be a reliable absolute path?

Toybox has scripts/prereq/build.sh to produce prerequisite commands in a portable way (commit 3bbc31c has an example invocation used to build toybox outside homebrew on macos, for example). It doesn't include toysh yet because it's still in pending, but once that's promoted it should include that and you should be able to "sh scripts/make.sh". There's a planned rewrite/replacement of kconfig that should also allow .config file generation to run portably.

It's not finished yet, but that's the plan.

@xplshn
Copy link
Author

xplshn commented Apr 14, 2024

Because not all people have installed bash at /bin/bash. And an error message that reads: make: scripts/genconfig.sh: No such file or directory when scripts/genconfig.sh DOES indeed exist is not quite useful for such people (me including).

/usr/bin/env should be used if you want to run under bash because env will lookup bash in the user's $PATH and run it.

For example, I have bash under ~/.local/bin because my package manager (bigdl) installed it there when I ran it as a user.

@landley
Copy link
Owner

landley commented Apr 14, 2024

If /bin/bash can't be trusted to be at that location, why would /usr/bin/env be any different?

@oliverkwebb
Copy link

If /bin/bash can't be trusted to be at that location, why would /usr/bin/env be any different?

Because env searches your path, doing a direct /bin/bash does not, doing
bash scripts/make.sh either directly or telling the makefile to do it would work I think.

@enh-google
Copy link
Collaborator

Because env searches your path, doing a direct /bin/bash does not, doing

his point is "if /bin/bash isn't there, what reason do i have to assume /usr/bin/env exists?".

@oliverkwebb
Copy link

oliverkwebb commented Apr 15, 2024 via email

@xplshn
Copy link
Author

xplshn commented Apr 15, 2024

env is a pretty standard POSIX utility that’s on most-everything that runs UNIX, bash is not

Absolutely! But that's not the problem, since Landley wants to use Bash syntax, the only problem is that some people may have bash installed in other directories. For example; I wouldn't install software such as Bash into my system, instead, I put such software under ~/.local/bin or /opt/compat/*

@oliverkwebb
Copy link

The solution is to tell your makefile to run a scriptwith bash (Searches path) instead of calling the shebang.

The following diff fixes this:

@@ -14,7 +14,7 @@ all: toybox
 KCONFIG_CONFIG ?= .config

 toybox generated/unstripped/toybox: $(KCONFIG_CONFIG) *.[ch] lib/*.[ch] toys/*/*.c scripts/*.sh Config.in
-       scripts/make.sh
+       bash scripts/make.sh

 .PHONY: clean distclean baseline bloatcheck install install_flat \
        uninstall uninstall_flat tests help change \
@@ -32,7 +32,7 @@ $(KCONFIG_CONFIG): $(KCONFIG_TOP)
 $(KCONFIG_TOP): generated/Config.in generated/Config.probed
 generated/Config.probed: generated/Config.in
 generated/Config.in: toys/*/*.c scripts/genconfig.sh
-       scripts/genconfig.sh
+       bash scripts/genconfig.sh

 # Development targets
 baseline: generated/unstripped/toybox

@xplshn
Copy link
Author

xplshn commented Apr 16, 2024

Its the same. However, it is better to fix the scripts shebang instead of modifying the Makefile to call them with bash.

@tpimh
Copy link

tpimh commented Apr 28, 2024

See previous discussion here: #77

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants