forked from client9/shlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuname_os.sh
38 lines (34 loc) · 1 KB
/
uname_os.sh
1
2
3
4
5
6
7
8
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
#!/bin/sh
# uname_os converts `uname -s` into standard golang OS types
# golang types are used since they cover
# most platforms and are standardized while raw uname values vary
# wildly. See complete list of values by running
# "go tool dist list"
#
# ## EXAMPLE
#
# ```bash
# OS=$(uname_os)
# ```
#
uname_os() {
os=$(uname -s | tr '[:upper:]' '[:lower:]')
# fixed up for https://github.com/client9/shlib/issues/3
case "$os" in
msys*) os="windows" ;;
mingw*) os="windows" ;;
cygwin*) os="windows" ;;
win*) os="windows" ;; # for windows busybox and like # https://frippery.org/busybox/
esac
# Sun Solaris and derived OS (Illumos, Oracle Solaris) reports to be the very ancient SunOS via uname not what it actually is
if [ "$os" = "sunos" ]; then
# Current illumos versions have -o to check if they are illumos or Solaris without breaking most builds.
if [ $(uname -o) == "illumos" ]; then
os="illumos"
else
os="solaris"
fi
fi
# other fixups here
echo "$os"
}