package/grep: fix egrep/fgrep shebang
authorAngelo Compagnucci <angelo@amarulasolutions.com>
Tue, 4 Feb 2020 14:24:47 +0000 (15:24 +0100)
committerPeter Korsgaard <peter@korsgaard.com>
Tue, 4 Feb 2020 14:53:24 +0000 (15:53 +0100)
egrep/fgrep are wrapper scripts, calling the grep binary with the correct
arguments.

The shell wrappers use the value of SHELL at build time as the shebang value
in these wrapper scripts, which in Buildroot points to /bin/bash.

The target may not have bash available, causing runtime errors.

As a fix, add a post-install hook to change this to /bin/sh.

If the target does not have /bin/sh, simply remove the aliases.

Signed-off-by: Angelo Compagnucci <angelo@amarulasolutions.com>
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
package/grep/Config.in
package/grep/grep.mk

index 5b0471b4c0283a5b533691b7f822e2e1a372c052..665c05c05eccea9b5056e0a68e9e44c546b49794 100644 (file)
@@ -5,6 +5,8 @@ config BR2_PACKAGE_GREP
        help
          The GNU regular expression matcher.
 
+         egrep/fgrep aliases need /bin/sh to be available.
+
          http://www.gnu.org/software/grep/grep.html
 
 comment "grep needs a toolchain w/ wchar"
index eefdfe6a74a86fa352d29d2246aaaa1b7482dd80..cc80553eb91550a8e23eee41c510ce211d0ac9e3 100644 (file)
@@ -13,6 +13,23 @@ GREP_DEPENDENCIES = $(TARGET_NLS_DEPENDENCIES)
 # install into /bin like busybox grep
 GREP_CONF_OPTS = --exec-prefix=/
 
+ifeq ($(BR2_SYSTEM_BIN_SH_NONE),y)
+
+define GREP_REMOVE_ALIAS
+       $(RM) $(TARGET_DIR)/bin/[fe]grep
+endef
+GREP_POST_INSTALL_TARGET_HOOKS += GREP_REMOVE_ALIAS
+
+else
+
+# ensure egrep/fgrep shell wrappers use #!/bin/sh
+define GREP_FIXUP_SHEBANG
+       $(SED) 's/bash$$/sh/' $(TARGET_DIR)/bin/[fe]grep
+endef
+GREP_POST_INSTALL_TARGET_HOOKS += GREP_FIXUP_SHEBANG
+
+endif
+
 # link with iconv if enabled
 ifeq ($(BR2_PACKAGE_LIBICONV),y)
 GREP_CONF_ENV += LIBS=-liconv