diff --git a/api/codegen.sh b/api/codegen.sh index 066f5f09..d63ad7c1 100755 --- a/api/codegen.sh +++ b/api/codegen.sh @@ -44,18 +44,13 @@ swagger-codegen generate -i swagger/swagger.yaml -l python-flask -o server 2>&1 # set interactive mode to enable defining a gsed alias shopt -s expand_aliases -# we use sed to make in-file text replacements, but sed works differently on macOS and Linux -if [[ "$OSTYPE" == "linux-gnu"* ]]; then # Linux - alias gsed="sed -i" -elif [[ "$OSTYPE" == "darwin"* ]]; then # macOS - alias gsed="sed -i ''" -elif [[ "$OSTYPE" == "cygwin" ]]; then # POSIX compatible emulation for Windows - alias gsed="sed -i" -elif [[ "$OSTYPE" == "msys"* ]]; then # Git Bash (Windows) - alias gsed="sed -i" +# we use sed to make in-file text replacements, but sed works differently depending on the version +if ! sed -i '1s/^/test/' $(mktemp) 2> /dev/null; then + # macOS (BSD) version of sed + alias gsed="sed -i ''" else - echo "FAILED. OS not compatible with script '${BASH_SOURCE[0]}'" - exit 1 + # POSIX compliant version of sed + alias gsed="sed -i" fi export gsed diff --git a/tools/bash/add_license_headers.sh b/tools/bash/add_license_headers.sh index f8b572e9..e6ef21a2 100755 --- a/tools/bash/add_license_headers.sh +++ b/tools/bash/add_license_headers.sh @@ -7,18 +7,15 @@ # set interactive mode to enable defining a gsed alias shopt -s expand_aliases -if [[ "$OSTYPE" == "linux-gnu"* ]]; then # Linux - alias gsed="sed -i" -elif [[ "$OSTYPE" == "darwin"* ]]; then # macOS - alias gsed="sed -i ''" -elif [[ "$OSTYPE" == "cygwin" ]]; then # POSIX compatible emulation for Windows - alias gsed="sed -i" -elif [[ "$OSTYPE" == "msys"* ]]; then # Git Bash (Windows) - alias gsed="sed -i" +# we use sed to make in-file text replacements, but sed works differently depending on the version +if ! sed -i '1s/^/test/' $(mktemp) 2> /dev/null; then + # macOS (BSD) version of sed + alias gsed="sed -i ''" else - echo "FAILED. OS not compatible with script '${BASH_SOURCE[0]}'" - exit 1 + # POSIX compliant version of sed + alias gsed="sed -i" fi + export gsed hash_comment () {