From 23a137617035c6f0c8cfb89037b6a407352bd374 Mon Sep 17 00:00:00 2001 From: Ming Di Leom <2809763-curben@users.noreply.gitlab.com> Date: Sat, 20 May 2023 11:10:16 +0000 Subject: [PATCH] fix: check installed grep is GNU variant --- src/script.sh | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/script.sh b/src/script.sh index 118432b..ee5b08d 100644 --- a/src/script.sh +++ b/src/script.sh @@ -13,17 +13,27 @@ alias curl="curl -L" alias mkdir="mkdir -p" alias rm="rm -rf" -## Use GNU grep, busybox grep is too slow +## Use GNU grep, busybox grep is not as performant . "/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 +check_grep() { + if [ -z "$(grep --help | grep 'GNU')" ]; then + if [ -x "/usr/bin/grep" ]; then + echo "grep found. try alias" + 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 - alias grep="/usr/bin/grep" -fi +} +check_grep ## Fallback to busybox dos2unix