Przeglądaj źródła

Merge pull request #9575 from id/chore-fix-runner_root_dir-detection-on-macos

chore: fix RUNNER_ROOT_DIR detection on MacOS
Ivan Dyachkov 3 lat temu
rodzic
commit
dc4d58593b
1 zmienionych plików z 10 dodań i 3 usunięć
  1. 10 3
      bin/emqx

+ 10 - 3
bin/emqx

@@ -13,10 +13,17 @@ DEBUG="${DEBUG:-0}"
 #   so we can't use it universally.
 # - `stat -f%R` on MacOS does exactly what `readlink -f` does on Linux, but we can't use it
 #   as a universal solution either because GNU stat has different syntax and this argument is invalid.
+#   Also, version of stat which supports this syntax is only available since MacOS 12
 if [ "$(uname -s)" == 'Darwin' ]; then
-    # if homebrew coreutils package is installed, GNU version of stat can take precedence,
-    # so we use absolute path to ensure we are calling MacOS default
-    RUNNER_ROOT_DIR="$(cd "$(dirname "$(/usr/bin/stat -f%R "$0" || echo "$0")")"/..; pwd -P)"
+    product_version="$(sw_vers -productVersion | cut -d '.' -f 1)"
+    if [ "$product_version" -ge 12 ]; then
+        # if homebrew coreutils package is installed, GNU version of stat can take precedence,
+        # so we use absolute path to ensure we are calling MacOS default
+        RUNNER_ROOT_DIR="$(cd "$(dirname "$(/usr/bin/stat -f%R "$0" || echo "$0")")"/..; pwd -P)"
+    else
+        # try our best to resolve link on MacOS <= 11
+        RUNNER_ROOT_DIR="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/..; pwd -P)"
+    fi
 else
     RUNNER_ROOT_DIR="$(cd "$(dirname "$(realpath "$0" || echo "$0")")"/..; pwd -P)"
 fi