-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathcheck_os.sh
More file actions
84 lines (70 loc) · 1.68 KB
/
check_os.sh
File metadata and controls
84 lines (70 loc) · 1.68 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env bash
# shellcheck disable=SC2034
_BASHUNIT_OS="Unknown"
_BASHUNIT_DISTRO="Unknown"
function bashunit::check_os::init() {
_BASHUNIT_UNAME="$(uname)"
if bashunit::check_os::is_linux; then
_BASHUNIT_OS="Linux"
if bashunit::check_os::is_ubuntu; then
_BASHUNIT_DISTRO="Ubuntu"
elif bashunit::check_os::is_alpine; then
_BASHUNIT_DISTRO="Alpine"
elif bashunit::check_os::is_nixos; then
_BASHUNIT_DISTRO="NixOS"
else
_BASHUNIT_DISTRO="Other"
fi
elif bashunit::check_os::is_macos; then
_BASHUNIT_OS="OSX"
elif bashunit::check_os::is_windows; then
_BASHUNIT_OS="Windows"
else
_BASHUNIT_OS="Unknown"
_BASHUNIT_DISTRO="Unknown"
fi
}
function bashunit::check_os::is_ubuntu() {
command -v apt >/dev/null 2>&1
}
function bashunit::check_os::is_alpine() {
command -v apk >/dev/null 2>&1
}
function bashunit::check_os::is_nixos() {
[ -f /etc/NIXOS ] && return 0
grep -q '^ID=nixos' /etc/os-release 2>/dev/null
}
_BASHUNIT_UNAME="$(uname)"
function bashunit::check_os::is_linux() {
[ "$_BASHUNIT_UNAME" = "Linux" ]
}
function bashunit::check_os::is_macos() {
[ "$_BASHUNIT_UNAME" = "Darwin" ]
}
function bashunit::check_os::is_windows() {
case "$_BASHUNIT_UNAME" in
*MINGW* | *MSYS* | *CYGWIN*)
return 0
;;
*)
return 1
;;
esac
}
function bashunit::check_os::is_busybox() {
case "$_BASHUNIT_DISTRO" in
"Alpine")
return 0
;;
*)
return 1
;;
esac
}
bashunit::check_os::init
export _BASHUNIT_OS
export _BASHUNIT_DISTRO
export -f bashunit::check_os::is_alpine
export -f bashunit::check_os::is_busybox
export -f bashunit::check_os::is_ubuntu
export -f bashunit::check_os::is_nixos