Przeglądaj źródła

chore(scripts): get-distro support windows

Zaiming (Stone) Shi 4 lat temu
rodzic
commit
4897e00aab
1 zmienionych plików z 23 dodań i 14 usunięć
  1. 23 14
      scripts/get-distro.sh

+ 23 - 14
scripts/get-distro.sh

@@ -5,18 +5,27 @@
 
 set -euo pipefail
 
-if [ "$(uname -s)" = 'Darwin' ]; then
-    DIST='macos'
-    VERSION_ID=$(sw_vers | gsed -n '/^ProductVersion:/p' | gsed -r 's/ProductVersion:(.*)/\1/g' | gsed -r 's/([0-9]+).*/\1/g' | gsed 's/^[ \t]*//g')
-    SYSTEM="$(echo "${DIST}${VERSION_ID}" | gsed -r 's/([a-zA-Z]*)-.*/\1/g')"
-elif [ "$(uname -s)" = 'Linux' ]; then
-    if grep -q -i 'centos' /etc/*-release; then
-        DIST='centos'
-        VERSION_ID="$(rpm --eval '%{centos_ver}')"
-    else
-        DIST="$(sed -n '/^ID=/p' /etc/os-release | sed -r 's/ID=(.*)/\1/g' | sed 's/"//g')"
-        VERSION_ID="$(sed -n '/^VERSION_ID=/p' /etc/os-release | sed -r 's/VERSION_ID=(.*)/\1/g' | sed 's/"//g')"
-    fi
-    SYSTEM="$(echo "${DIST}${VERSION_ID}" | sed -r 's/([a-zA-Z]*)-.*/\1/g')"
-fi
+UNAME="$(uname -s)"
+
+case "$UNAME" in
+    Darwin)
+        DIST='macos'
+        VERSION_ID=$(sw_vers | gsed -n '/^ProductVersion:/p' | gsed -r 's/ProductVersion:(.*)/\1/g' | gsed -r 's/([0-9]+).*/\1/g' | gsed 's/^[ \t]*//g')
+        SYSTEM="$(echo "${DIST}${VERSION_ID}" | gsed -r 's/([a-zA-Z]*)-.*/\1/g')"
+        ;;
+    Linux)
+        if grep -q -i 'centos' /etc/*-release; then
+            DIST='centos'
+            VERSION_ID="$(rpm --eval '%{centos_ver}')"
+        else
+            DIST="$(sed -n '/^ID=/p' /etc/os-release | sed -r 's/ID=(.*)/\1/g' | sed 's/"//g')"
+            VERSION_ID="$(sed -n '/^VERSION_ID=/p' /etc/os-release | sed -r 's/VERSION_ID=(.*)/\1/g' | sed 's/"//g')"
+        fi
+        SYSTEM="$(echo "${DIST}${VERSION_ID}" | sed -r 's/([a-zA-Z]*)-.*/\1/g')"
+        ;;
+    CYGWIN*|MSYS*|MINGW*)
+        SYSTEM="windows"
+        ;;
+esac
+
 echo "$SYSTEM"