diff --git a/packaging/tools/get_os.sh b/packaging/tools/get_os.sh index f74b63f9805e937933000d097c24bc6b85663288..ccb0cff4c900804fffe3b9bcf8fb6463f3f6677e 100755 --- a/packaging/tools/get_os.sh +++ b/packaging/tools/get_os.sh @@ -6,9 +6,56 @@ set -e # set -x -# -----------------------Variables definition--------------------- -OS=$(cat /etc/*-release | grep "^NAME=" | cut -d= -f2) -len=$(echo ${#OS}) -len=$((len-2)) -retval=$(echo -ne ${OS:1:${len}} | cut -d" " -f1) -echo -ne $retval +# run uname get kernel os info +function get_kernel() { + read -ra uname <<< "$(uname -srm)" + kernel_name="${uname[0]}" #Darwin,Linux,Windows.. + kernel_release="${uname[1]}" #version + kernel_machine="${uname[2]}" # x86_64 + ARC="${uname[2]}" # x86_64 +} + +get_kernel + +function get_os() { + # !!Must run get_kernel first + case $kernel_name in + Linux|GNU*) + KERNEL=Linux + OS=$(cat /etc/*-release | grep "^NAME=" | cut -d= -f2) + len=$(echo ${#OS}) + len=$((len-2)) + OS=$(echo -ne ${OS:1:${len}} | cut -d" " -f1) + ;; + + CYGWIN*|MSYS*|MINGW*) + # MINGW32_NT,MINGW64_NT... , set OS the same name, check ARC for CPU + OS=Windows + ;; + + Darwin) + OS=Darwin # use kernel name + KERNEL=Darwin + OS_NAME="$(sw_vers -productName)" # OS: Mac OS X + OS_VER="$(sw_vers -productVersion)" # Version :10.15.3 + ;; + + SunOS) + OS=Solaris + ;; + + *BSD|DragonFly|Bitrig) + OS=BSD + ;; + + *) + # other kernel like HP-UX, AIX,etc. + OS="$kernel_name" + ;; + esac +} + +get_os + +echo -ne $OS +