From a4b04fcb7ad231871fcb96e9a9af73937d8b7a32 Mon Sep 17 00:00:00 2001 From: Ming Di Leom <2809763-curben@users.noreply.gitlab.com> Date: Sat, 20 May 2023 11:27:31 +0000 Subject: [PATCH] fix: check installed grep is GNU variant --- src/script.sh | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/script.sh b/src/script.sh index 04a36a5..f2caa09 100644 --- a/src/script.sh +++ b/src/script.sh @@ -10,18 +10,30 @@ else fi -## Use GNU grep, busybox grep is too slow -. "/etc/os-release" -DISTRO="$ID" - -if [ -z "$(grep --help | grep 'GNU')" ]; then - if [ "$DISTRO" = "alpine" ]; then - echo "Please install GNU grep 'apk add grep'" - exit 1 - fi - alias grep="/usr/bin/grep" +## Use GNU grep, busybox grep is not as performant +DISTRO="" +if [ -f "/etc/os-release" ]; then + . "/etc/os-release" + DISTRO="$ID" fi +check_grep() { + if [ -z "$(grep --help | grep 'GNU')" ]; then + if [ -x "/usr/bin/grep" ]; then + alias grep="/usr/bin/grep" + check_grep + else + if [ "$DISTRO" = "alpine" ]; then + echo "Please install GNU grep 'apk add grep'" + else + echo "GNU grep not found" + fi + exit 1 + fi + fi +} +check_grep + rm -rf "tmp/" mkdir -p "tmp/"