fix: check installed grep is GNU variant

This commit is contained in:
Ming Di Leom 2023-05-20 11:21:08 +00:00
parent e2c8cc3449
commit 2bae35cd3b
No known key found for this signature in database
GPG Key ID: 32D3E28E96A695E8
1 changed files with 22 additions and 10 deletions

View File

@ -10,18 +10,30 @@ else
fi fi
## Use GNU grep, busybox grep is too slow ## Use GNU grep, busybox grep is not as performant
. "/etc/os-release" DISTRO=""
DISTRO="$ID" if [ -f "/etc/os-release" ]; then
. "/etc/os-release"
if [ -z "$(grep --help | grep 'GNU')" ]; then DISTRO="$ID"
if [ "$DISTRO" = "alpine" ]; then
echo "Please install GNU grep 'apk add grep'"
exit 1
fi
alias grep="/usr/bin/grep"
fi 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
mkdir -p "tmp/" mkdir -p "tmp/"
cd "tmp/" cd "tmp/"