From e19b52442bdfd36c64cecc9a8a25bef76347d66a Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 17 Feb 2020 05:59:52 -0500 Subject: [PATCH] fix: remove deprecated egrep calls from codebase --- Makefile | 4 ++-- debian/postinst | 2 +- plugins/common/functions | 6 +++--- plugins/domains/functions | 4 ++-- plugins/nginx-vhosts/functions | 4 ++-- plugins/nginx-vhosts/install | 2 +- plugins/ps/functions | 4 ++-- plugins/scheduler-docker-local/core-post-deploy | 2 +- plugins/scheduler-docker-local/post-delete | 2 +- tests.mk | 6 +++--- tests/shellcheck-exclude | 1 - tests/unit/10_ps-dockerfile.bats | 6 +++--- tests/unit/10_ps-herokuish.bats | 4 ++-- tests/unit/20_config.bats | 4 ++-- tests/unit/40_core_2.bats | 4 ++-- tests/unit/40_nginx-vhosts_2.bats | 2 +- tests/unit/40_tags.bats | 8 ++++---- tests/unit/test_helper.bash | 2 +- 18 files changed, 33 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index 7c2552144..9f4ff110e 100644 --- a/Makefile +++ b/Makefile @@ -155,7 +155,7 @@ sigil: docker: apt-get install -qq -y curl - egrep -i "^docker" /etc/group || groupadd docker + grep -i -E "^docker" /etc/group || groupadd docker usermod -aG docker dokku ifndef CI wget -nv -O - https://get.docker.com/ | sh @@ -171,7 +171,7 @@ ifdef BUILD_STACK @echo "Start building herokuish from source" docker images | grep gliderlabs/herokuish || (git clone ${STACK_URL} /tmp/herokuish && cd /tmp/herokuish && IMAGE_NAME=gliderlabs/herokuish BUILD_TAG=latest VERSION=master make -e ${BUILD_STACK_TARGETS} && rm -rf /tmp/herokuish) else -ifeq ($(shell echo ${PREBUILT_STACK_URL} | egrep -q 'http.*://|file://' && echo $$?),0) +ifeq ($(shell echo ${PREBUILT_STACK_URL} | grep -q -E 'http.*://|file://' && echo $$?),0) @echo "Start importing herokuish from ${PREBUILT_STACK_URL}" docker images | grep gliderlabs/herokuish || wget -nv -O - ${PREBUILT_STACK_URL} | gunzip -cd | docker import - gliderlabs/herokuish else diff --git a/debian/postinst b/debian/postinst index 94257e24c..f5d2ce23c 100755 --- a/debian/postinst +++ b/debian/postinst @@ -29,7 +29,7 @@ call-sshcommand() { setup-user() { echo "Setting up dokku user" call-sshcommand create dokku /usr/bin/dokku - egrep -i "^docker" /etc/group || groupadd docker + grep -i -E "^docker" /etc/group || groupadd docker usermod -aG docker dokku mkdir -p "$DOKKU_ROOT/.ssh" "$DOKKU_ROOT/.dokkurc" touch "$DOKKU_ROOT/.ssh/authorized_keys" diff --git a/plugins/common/functions b/plugins/common/functions index c1f4da510..fc822ca53 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -762,7 +762,7 @@ get_ipv6_regex() { get_dockerfile_exposed_ports() { declare desc="return all exposed ports from passed file path" - local DOCKERFILE_PORTS=$(egrep "^EXPOSE " "$1" | awk '{ print $2 }' | xargs) || true + local DOCKERFILE_PORTS=$(grep -E "^EXPOSE " "$1" | awk '{ print $2 }' | xargs) || true echo "$DOCKERFILE_PORTS" } @@ -796,7 +796,7 @@ extract_directive_from_dockerfile() { declare desc="return requested directive from passed file path" local FILE_PATH="$1" local SEARCH_STRING="$2" - local FOUND_LINE=$(egrep "^${SEARCH_STRING} " "$FILE_PATH" | tail -n1) || true + local FOUND_LINE=$(grep -E "^${SEARCH_STRING} " "$FILE_PATH" | tail -n1) || true echo "$FOUND_LINE" } @@ -858,7 +858,7 @@ internal_get_app_urls() { local DOKKU_PROXY_PORT_MAP=$(config_get "$APP" DOKKU_PROXY_PORT_MAP || true) if [[ -s "$URLS_FILE" ]]; then - local app_urls="$(egrep -v "^#" "$URLS_FILE")" + local app_urls="$(grep -v -E "^#" "$URLS_FILE")" if [[ -n "$DOKKU_PROXY_PORT_MAP" ]]; then local port_map app_vhost local app_vhosts=$(get_app_domains "$APP") diff --git a/plugins/domains/functions b/plugins/domains/functions index 733db5c9b..942352c3b 100755 --- a/plugins/domains/functions +++ b/plugins/domains/functions @@ -63,7 +63,7 @@ domains_add() { for DOMAIN in "$@"; do if [[ $( - egrep -w "^$DOMAIN$" "$APP_VHOST_PATH" >/dev/null 2>&1 + grep -w -E "^$DOMAIN$" "$APP_VHOST_PATH" >/dev/null 2>&1 echo $? ) -eq 0 ]]; then dokku_log_info1 "Skipping: $DOMAIN already added to $APP" @@ -165,7 +165,7 @@ domains_add_global() { for DOMAIN in "$@"; do if [[ $( - egrep -w "^$DOMAIN$" "$GLOBAL_VHOST_PATH" >/dev/null 2>&1 + grep -w -E "^$DOMAIN$" "$GLOBAL_VHOST_PATH" >/dev/null 2>&1 echo $? ) -eq 0 ]]; then dokku_log_info1 "Skipping: $DOMAIN already added" diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index dad1cdc9b..3a2a49470 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -143,7 +143,7 @@ validate_ssl_domains() { local SSL_HOSTNAME=$(get_ssl_hostnames "$APP") local SSL_HOSTNAME_REGEX=$(echo "$SSL_HOSTNAME" | xargs | sed 's|\.|\\.|g' | sed 's/\*/\[^\.\]\*/g' | sed 's/ /|/g') - if ! (egrep -q "^${SSL_HOSTNAME_REGEX}$" "$VHOST_PATH" &>/dev/null); then + if ! (grep -q -E "^${SSL_HOSTNAME_REGEX}$" "$VHOST_PATH" &>/dev/null); then dokku_log_info1 "No matching configured domains for $APP found in SSL certificate. Your app will show as insecure in a browser if accessed via SSL" dokku_log_info1 "Please add appropriate domains via the dokku domains command" [[ -n "$NONSSL_VHOSTS" ]] && dokku_log_info1 "Configured domains for app:" @@ -328,7 +328,7 @@ nginx_build_config() { local SSL_HOSTNAME_REGEX=$(echo "$SSL_HOSTNAME" | xargs | sed 's|\.|\\.|g' | sed 's/\*/\[^\.\]\*/g' | sed 's/ /|/g') if [[ "$IS_APP_VHOST_ENABLED" == "true" ]]; then - local SSL_VHOSTS=$(egrep "^${SSL_HOSTNAME_REGEX}$" "$VHOST_PATH" || true) + local SSL_VHOSTS=$(grep -E "^${SSL_HOSTNAME_REGEX}$" "$VHOST_PATH" || true) else local SSL_VHOSTS=$(<"$DOKKU_ROOT/HOSTNAME") fi diff --git a/plugins/nginx-vhosts/install b/plugins/nginx-vhosts/install index 34739247d..1a193b80d 100755 --- a/plugins/nginx-vhosts/install +++ b/plugins/nginx-vhosts/install @@ -85,7 +85,7 @@ EOF mkdir -p "$NGINX_LOG_ROOT" gpasswd -a dokku adm chgrp --quiet -R adm "$NGINX_LOG_ROOT" - gpasswd -M "$(egrep ^dokku: /etc/group | awk -F ":" '{ print $4 }')" dokku + gpasswd -M "$(grep -E ^dokku: /etc/group | awk -F ":" '{ print $4 }')" dokku [[ -f /etc/logrotate.d/nginx ]] && sed -i -e 's/create 0640 www-data dokku/create 0640 www-data adm/g' /etc/logrotate.d/nginx # Create nginx error templates diff --git a/plugins/ps/functions b/plugins/ps/functions index 8d097bb17..2bd7b7bb8 100755 --- a/plugins/ps/functions +++ b/plugins/ps/functions @@ -83,7 +83,7 @@ generate_scale_file() { local NUM_PROCS=0 [[ "$NAME" == "web" ]] && NUM_PROCS=1 [[ -n "$NAME" ]] && echo "$NAME=$NUM_PROCS" >>"$DOKKU_SCALE_FILE" - done < <(egrep -v "^#" "$DOKKU_PROCFILE" | grep ':' | awk -F ':' '{ print $1 }' | sort | uniq) + done < <(grep -v -E "^#" "$DOKKU_PROCFILE" | grep ':' | awk -F ':' '{ print $1 }' | sort | uniq) else echo "web=1" >>"$DOKKU_SCALE_FILE" fi @@ -110,7 +110,7 @@ set_scale() { fi is_number "$PROC_COUNT" || dokku_log_fail "ps:scale $PROC_COUNT is not a number" dokku_log_info1_quiet "Scaling $APP:$PROC_NAME to $PROC_COUNT" - if (egrep -q "^${PROC_NAME}=" "$DOKKU_SCALE_FILE" >/dev/null 2>&1); then + if (grep -q -E "^${PROC_NAME}=" "$DOKKU_SCALE_FILE" >/dev/null 2>&1); then sed --in-place "s:^${PROC_NAME}=.*:$PROC_NAME=$PROC_COUNT:g" "$DOKKU_SCALE_FILE" else echo "$PROC_NAME=$PROC_COUNT" >>"$DOKKU_SCALE_FILE" diff --git a/plugins/scheduler-docker-local/core-post-deploy b/plugins/scheduler-docker-local/core-post-deploy index 53f89c928..4edb1f656 100755 --- a/plugins/scheduler-docker-local/core-post-deploy +++ b/plugins/scheduler-docker-local/core-post-deploy @@ -16,7 +16,7 @@ trigger-scheduler-docker-local-core-post-deploy() { fi dokku_log_info1 "Renaming containers" - local PROCTYPES="$(egrep -v "^#" "$DOKKU_ROOT/$APP/DOKKU_SCALE" | awk -F '=' '{ print $1 }' | xargs)" + local PROCTYPES="$(grep -v -E "^#" "$DOKKU_ROOT/$APP/DOKKU_SCALE" | awk -F '=' '{ print $1 }' | xargs)" local CONTAINER_FILES="$(find "$DOKKU_ROOT/$APP" -maxdepth 1 -name "CONTAINER.*" -printf "%f\n" 2>/dev/null | sort -t . -k 3 -n | xargs)" local CONTAINER_FILE diff --git a/plugins/scheduler-docker-local/post-delete b/plugins/scheduler-docker-local/post-delete index af97a2817..7d964952e 100755 --- a/plugins/scheduler-docker-local/post-delete +++ b/plugins/scheduler-docker-local/post-delete @@ -18,7 +18,7 @@ trigger-scheduler-docker-local-post-delete() { # remove all application containers & images # shellcheck disable=SC2046 - local DOKKU_APP_CIDS=$("$DOCKER_BIN" container list --all --no-trunc | egrep "dokku/${APP}:" | awk '{ print $1 }' | xargs) + local DOKKU_APP_CIDS=$("$DOCKER_BIN" container list --all --no-trunc | grep "dokku/${APP}:" | awk '{ print $1 }' | xargs) if [[ -n "$DOKKU_APP_CIDS" ]]; then # shellcheck disable=SC2086 "$DOCKER_BIN" container rm --force $DOKKU_APP_CIDS >/dev/null 2>&1 || true diff --git a/tests.mk b/tests.mk index 7f3c16059..51caa5032 100644 --- a/tests.mk +++ b/tests.mk @@ -107,7 +107,7 @@ prime-ssh-known-hosts: lint-setup: @mkdir -p test-results/shellcheck tmp/shellcheck - @find . -not -path '*/\.*' -not -path './debian/*' -not -path './docs/*' -not -path './tests/*' -not -path './vendor/*' -type f | xargs file | grep text | awk -F ':' '{ print $$1 }' | xargs head -n1 | egrep -B1 "bash" | grep "==>" | awk '{ print $$2 }' > tmp/shellcheck/test-files + @find . -not -path '*/\.*' -not -path './debian/*' -not -path './docs/*' -not -path './tests/*' -not -path './vendor/*' -type f | xargs file | grep text | awk -F ':' '{ print $$1 }' | xargs head -n1 | grep -B1 "bash" | grep "==>" | awk '{ print $$2 }' > tmp/shellcheck/test-files @cat tests/shellcheck-exclude | sed -n -e '/^# SC/p' | cut -d' ' -f2 | paste -d, -s > tmp/shellcheck/exclude lint-ci: lint-setup @@ -132,7 +132,7 @@ ci-go-coverage: -w $(GO_REPO_ROOT) \ $(BUILD_IMAGE) \ bash -c "go get github.com/onsi/gomega github.com/schrej/godacov github.com/haya14busa/goverage && \ - go list ./... | egrep -v '/vendor/|/tests/apps/' | xargs goverage -v -coverprofile=coverage.out && \ + go list ./... | grep -v -E '/vendor/|/tests/apps/' | xargs goverage -v -coverprofile=coverage.out && \ godacov -t $$CODACY_TOKEN -r ./coverage.out -c $$CIRCLE_SHA1" || exit $$? go-tests: @@ -143,7 +143,7 @@ go-tests: -w $(GO_REPO_ROOT) \ $(BUILD_IMAGE) \ bash -c "go get github.com/onsi/gomega && \ - go list ./... | egrep -v '/vendor/|/tests/apps/' | xargs go test -v -p 1 -race" || exit $$? + go list ./... | grep -v -E '/vendor/|/tests/apps/' | xargs go test -v -p 1 -race" || exit $$? unit-tests: go-tests @echo running bats unit tests... diff --git a/tests/shellcheck-exclude b/tests/shellcheck-exclude index 57fc5acee..c03f8b1a6 100644 --- a/tests/shellcheck-exclude +++ b/tests/shellcheck-exclude @@ -20,7 +20,6 @@ # SC2174 - When used with -p, -m only applies to the deepest directory - https://github.com/koalaman/shellcheck/wiki/SC2174 # SC2179 - Use array+=("item") to append items to an array - https://github.com/koalaman/shellcheck/wiki/SC2179 # SC2191 - The = here is literal. To assign by index, use ( [index]=value ) with no spaces. To keep as literal, quote it - https://github.com/koalaman/shellcheck/wiki/SC2191 -# SC2196 - egrep is non-standard and deprecated. Use grep -E instead - https://github.com/koalaman/shellcheck/wiki/SC2196 # SC2199 - Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @) - https://github.com/koalaman/shellcheck/wiki/SC2199 # SC2207 - Prefer mapfile or read -a to split command output (or quote to avoid splitting) - https://github.com/koalaman/shellcheck/wiki/SC2207 # SC2219 - Instead of 'let expr', prefer (( expr )) - https://github.com/koalaman/shellcheck/wiki/SC2219 diff --git a/tests/unit/10_ps-dockerfile.bats b/tests/unit/10_ps-dockerfile.bats index 2c0061f08..eba66e24f 100644 --- a/tests/unit/10_ps-dockerfile.bats +++ b/tests/unit/10_ps-dockerfile.bats @@ -98,7 +98,7 @@ teardown() { CIDS+=" " done CIDS_PATTERN=$(echo $CIDS | sed -e "s: :|:g") - run /bin/bash -c "docker ps -q --no-trunc | egrep \"$CIDS_PATTERN\" | wc -l | grep 2" + run /bin/bash -c "docker ps -q --no-trunc | grep -E \"$CIDS_PATTERN\" | wc -l | grep 2" echo "output: $output" echo "status: $status" assert_success @@ -113,7 +113,7 @@ teardown() { CIDS+=" " done CIDS_PATTERN=$(echo $CIDS | sed -e "s: :|:g") - run /bin/bash -c "docker ps -q --no-trunc | egrep \"$CIDS_PATTERN\" | wc -l | grep 1" + run /bin/bash -c "docker ps -q --no-trunc | grep -E \"$CIDS_PATTERN\" | wc -l | grep 1" echo "output: $output" echo "status: $status" assert_success @@ -147,7 +147,7 @@ teardown() { CIDS+=" " done CIDS_PATTERN=$(echo $CIDS | sed -e "s: :|:g") - run /bin/bash -c "docker ps -q --no-trunc | egrep \"$CIDS_PATTERN\" | wc -l | grep 1" + run /bin/bash -c "docker ps -q --no-trunc | grep -E \"$CIDS_PATTERN\" | wc -l | grep 1" echo "output: $output" echo "status: $status" assert_success diff --git a/tests/unit/10_ps-herokuish.bats b/tests/unit/10_ps-herokuish.bats index 3adc11150..7a10482be 100644 --- a/tests/unit/10_ps-herokuish.bats +++ b/tests/unit/10_ps-herokuish.bats @@ -86,7 +86,7 @@ teardown() { CIDS+=" " done CIDS_PATTERN=$(echo $CIDS | sed -e "s: :|:g") - run /bin/bash -c "docker ps -q --no-trunc | egrep \"$CIDS_PATTERN\" | wc -l | grep 2" + run /bin/bash -c "docker ps -q --no-trunc | grep -E \"$CIDS_PATTERN\" | wc -l | grep 2" echo "output: $output" echo "status: $status" assert_success @@ -103,7 +103,7 @@ teardown() { CIDS+=" " done CIDS_PATTERN=$(echo $CIDS | sed -e "s: :|:g") - run /bin/bash -c "docker ps -q --no-trunc | egrep \"$CIDS_PATTERN\" | wc -l | grep 1" + run /bin/bash -c "docker ps -q --no-trunc | grep -E \"$CIDS_PATTERN\" | wc -l | grep 1" echo "output: $output" echo "status: $status" assert_success diff --git a/tests/unit/20_config.bats b/tests/unit/20_config.bats index 0d27f0c87..9b0efd2af 100644 --- a/tests/unit/20_config.bats +++ b/tests/unit/20_config.bats @@ -155,7 +155,7 @@ teardown() { @test "(config) global config (herokuish)" { deploy_app - run /bin/bash -c "dokku run $TEST_APP env | egrep '^global_test=true'" + run /bin/bash -c "dokku run $TEST_APP env | grep -E '^global_test=true'" echo "output: $output" echo "status: $status" assert_success @@ -163,7 +163,7 @@ teardown() { @test "(config) global config (dockerfile)" { deploy_app dockerfile - run /bin/bash -c "dokku run $TEST_APP env | egrep '^global_test=true'" + run /bin/bash -c "dokku run $TEST_APP env | grep -E '^global_test=true'" echo "output: $output" echo "status: $status" assert_success diff --git a/tests/unit/40_core_2.bats b/tests/unit/40_core_2.bats index c7502dca8..21a7d3e65 100644 --- a/tests/unit/40_core_2.bats +++ b/tests/unit/40_core_2.bats @@ -30,11 +30,11 @@ teardown() { @test "(core) run (with --env / -e)" { deploy_app - run /bin/bash -c "dokku run --env TEST=testvalue -e TEST2=testvalue2 $TEST_APP env | egrep '^TEST=testvalue'" + run /bin/bash -c "dokku run --env TEST=testvalue -e TEST2=testvalue2 $TEST_APP env | grep -E '^TEST=testvalue'" echo "output: $output" echo "status: $status" - run /bin/bash -c "dokku run --env TEST=testvalue -e TEST2=testvalue2 $TEST_APP env | egrep '^TEST2=testvalue2'" + run /bin/bash -c "dokku run --env TEST=testvalue -e TEST2=testvalue2 $TEST_APP env | grep -E '^TEST2=testvalue2'" echo "output: $output" echo "status: $status" assert_success diff --git a/tests/unit/40_nginx-vhosts_2.bats b/tests/unit/40_nginx-vhosts_2.bats index 326dea689..15b4d91a5 100644 --- a/tests/unit/40_nginx-vhosts_2.bats +++ b/tests/unit/40_nginx-vhosts_2.bats @@ -18,7 +18,7 @@ teardown() { @test "(nginx-vhosts) nginx (no server tokens)" { deploy_app - run /bin/bash -c "curl -s -D - $(dokku url $TEST_APP) -o /dev/null | egrep '^Server' | egrep '[0-9]+'" + run /bin/bash -c "curl -s -D - $(dokku url $TEST_APP) -o /dev/null | grep -E '^Server' | grep -E '[0-9]+'" echo "output: $output" echo "status: $status" assert_failure diff --git a/tests/unit/40_tags.bats b/tests/unit/40_tags.bats index 4d0b41e21..43c44cdc5 100644 --- a/tests/unit/40_tags.bats +++ b/tests/unit/40_tags.bats @@ -24,7 +24,7 @@ teardown() { echo "output: $output" echo "status: $status" assert_success - run /bin/bash -c "dokku tags $TEST_APP | egrep -q 'v0.9.0'" + run /bin/bash -c "dokku tags $TEST_APP | grep -q -E 'v0.9.0'" echo "output: $output" echo "status: $status" assert_success @@ -33,7 +33,7 @@ teardown() { echo "output: $output" echo "status: $status" assert_success - run /bin/bash -c "dokku tags $TEST_APP | egrep -q 'v0.9.0'" + run /bin/bash -c "dokku tags $TEST_APP | grep -q -E 'v0.9.0'" echo "output: $output" echo "status: $status" assert_failure @@ -48,11 +48,11 @@ teardown() { echo "output: $output" echo "status: $status" assert_success - run /bin/bash -c "docker ps | egrep '/start web'| egrep -q dokku/${TEST_APP}:v0.9.0" + run /bin/bash -c "docker ps | grep -E '/start web'| grep -q -E dokku/${TEST_APP}:v0.9.0" echo "output: $output" echo "status: $status" assert_success - run /bin/bash -c "docker images | egrep "dokku/${TEST_APP}"| egrep -q latest" + run /bin/bash -c "docker images | grep -E "dokku/${TEST_APP}"| grep -q -E latest" echo "output: $output" echo "status: $status" assert_success diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index 1db3e29da..0e5c88909 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -177,7 +177,7 @@ add_domain() { # shellcheck disable=SC2119 check_urls() { local PATTERN="$1" - run /bin/bash -c "dokku --quiet urls $TEST_APP | egrep \"${1}\"" + run /bin/bash -c "dokku --quiet urls $TEST_APP | grep -E \"${1}\"" echo "output: $output" echo "status: $status" assert_success