From 71e763e1ca5235f107b9c4dc449098bd544ecff9 Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Fri, 19 Feb 2021 13:38:59 +0800 Subject: [PATCH] ! fix osx ci fail - prefer greadlink than readlink - prefer gsed than sed --- .travis.yml | 6 ++++++ bin/ap | 7 ++++++- bin/uq | 7 ++++++- lib/console-text-color-themes.sh | 7 ++++++- lib/parseOpts.sh | 11 ++++++++--- test-cases/integration-test.sh | 8 +++++++- test-cases/uq_test.sh | 7 ++++++- 7 files changed, 45 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index efc6822c..51f493a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,8 @@ language: bash # https://docs.travis-ci.com/user/reference/linux/ # The macOS Build Environment # https://docs.travis-ci.com/user/reference/osx/ +# Installing Dependencies +# https://docs.travis-ci.com/user/installing-dependencies/#installing-packages-on-macos matrix: include: - os: linux @@ -19,6 +21,10 @@ matrix: - os: linux dist: focal - os: osx + osx_image: xcode11.3 + install: + - HOMEBREW_NO_AUTO_UPDATE=1 brew install coreutils + - HOMEBREW_NO_AUTO_UPDATE=1 brew install gnu-sed script: - test-cases/integration-test.sh diff --git a/bin/ap b/bin/ap index bceae03c..52b16376 100755 --- a/bin/ap +++ b/bin/ap @@ -12,6 +12,11 @@ # @author Jerry Lee (oldratlee at gmail dot com) set -eEuo pipefail +READLINK_CMD=readlink +if command -v greadlink > /dev/null; then + READLINK_CMD=greadlink +fi + [ $# -eq 0 ] && files=(.) || files=("$@") for f in "${files[@]}"; do @@ -19,5 +24,5 @@ for f in "${files[@]}"; do echo "$f does not exists!" continue } - readlink -f "$f" + $READLINK_CMD -f "$f" done diff --git a/bin/uq b/bin/uq index 75d06f1e..130950e8 100755 --- a/bin/uq +++ b/bin/uq @@ -12,8 +12,13 @@ # @author Jerry Lee (oldratlee at gmail dot com) set -eEuo pipefail +READLINK_CMD=readlink +if command -v greadlink > /dev/null; then + READLINK_CMD=greadlink +fi + PROG="$(basename "$0")" -PROG_PATH="$(readlink -f "${BASH_SOURCE[0]}")" +PROG_PATH="$($READLINK_CMD -f "${BASH_SOURCE[0]}")" PROG_DIR="$(dirname "$PROG_PATH")" ################################################################################ diff --git a/lib/console-text-color-themes.sh b/lib/console-text-color-themes.sh index 8b65f246..9b9337f7 100755 --- a/lib/console-text-color-themes.sh +++ b/lib/console-text-color-themes.sh @@ -5,7 +5,12 @@ # @online-doc https://github.com/oldratlee/useful-scripts/blob/dev-2.x/docs/shell.md#-console-text-color-themessh # @author Jerry Lee (oldratlee at gmail dot com) -readonly _ctct_PROG="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" +_ctct_READLINK_CMD=readlink +if command -v greadlink > /dev/null; then + _ctct_READLINK_CMD=greadlink +fi + +readonly _ctct_PROG="$(basename "$($_ctct_READLINK_CMD -f "${BASH_SOURCE[0]}")")" [ "$_ctct_PROG" == 'console-text-color-themes.sh' ] && readonly _ctct_is_direct_run=true readonly _ctct_ec=$'\033' # escape char diff --git a/lib/parseOpts.sh b/lib/parseOpts.sh index 6d67f736..197ec60f 100755 --- a/lib/parseOpts.sh +++ b/lib/parseOpts.sh @@ -26,6 +26,11 @@ readonly _opts_ec=$'\033' # escape char readonly _opts_eend=$'\033[0m' # escape end +_opts_SED_CMD=sed +if command -v gsed &> /dev/null; then + _opts_SED_CMD=gsed +fi + _opts_colorEcho() { local color=$1 shift @@ -42,7 +47,7 @@ _opts_convertToVarName() { _opts_redEcho "NOT 1 arguemnts when call _opts_convertToVarName: $@" return 1 } - echo "$1" | sed 's/-/_/g' + echo "$1" | $_opts_SED_CMD 's/-/_/g' } ##################################################################### @@ -177,7 +182,7 @@ parseOpts() { local optDescLines=`echo "$optsDescription" | # cut head and tail space - sed -r 's/^\s+//;s/\s+$//' | + $_opts_SED_CMD -r 's/^\s+//;s/\s+$//' | awk -F '[\t ]*\\\\|[\t ]*' '{for(i=1; i<=NF; i++) print $i}'` local optDesc @@ -258,7 +263,7 @@ parseOpts() { ;; -*) # short & long option(-a, -a-long), use same read-in logic. local opt="$1" - local optName=`echo "$1" | sed -r 's/^--?//'` + local optName=`echo "$1" | $_opts_SED_CMD -r 's/^--?//'` local mode=`_opts_findOptMode "$optName"` case "$mode" in -) diff --git a/test-cases/integration-test.sh b/test-cases/integration-test.sh index 7d07e0df..f52f379e 100755 --- a/test-cases/integration-test.sh +++ b/test-cases/integration-test.sh @@ -1,6 +1,12 @@ #!/bin/bash set -eEuo pipefail -cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" + +READLINK_CMD=readlink +if command -v greadlink &> /dev/null; then + READLINK_CMD=greadlink +fi + +cd "$(dirname "$($READLINK_CMD -f "${BASH_SOURCE[0]}")")" ################################################################################ # constants diff --git a/test-cases/uq_test.sh b/test-cases/uq_test.sh index 84b38948..5de8d056 100755 --- a/test-cases/uq_test.sh +++ b/test-cases/uq_test.sh @@ -1,7 +1,12 @@ #!/bin/bash set -eEuo pipefail -BASE="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" +READLINK_CMD=readlink +if command -v greadlink &> /dev/null; then + READLINK_CMD=greadlink +fi + +BASE="$(dirname "$($READLINK_CMD -f "${BASH_SOURCE[0]}")")" cd "$BASE" #################################################