get_os.sh 1.4 KB
Newer Older
F
Frozen 已提交
1 2 3 4 5 6 7 8
#!/bin/bash
#
# This file is used to install TAOS time-series database on linux systems. The operating system 
# is required to use systemd to manage services at boot

set -e
# set -x

A
ablozhou 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
# 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