-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplatform_detector.bash
42 lines (35 loc) · 952 Bytes
/
platform_detector.bash
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
PLATFORM_NAME=""
PLATFORM_IS_LINUX=0
PLATFORM_IS_UBUNTU=0
PLATFORM_IS_ANDROID=0
PLATFORM_IS_RASPBERRY=0
PLATFORM_IS_DARWIN=0
function __uname_contains() {
uname -a | grep -isq "$1"
}
function detect_platform() {
if __uname_contains "Darwin" ; then
PLATFORM_NAME="Darwin"
PLATFORM_IS_DARWIN=1
elif __uname_contains "Linux" ; then
PLATFORM_IS_LINUX=1
if __uname_contains "Ubuntu" ; then
PLATFORM_NAME="Ubuntu"
PLATFORM_IS_UBUNTU=1
elif __uname_contains "raspberrypi" ; then
PLATFORM_NAME="Raspberry Pi OS"
PLATFORM_IS_RASPBERRY=1
elif __uname_contains "Android" ; then
PLATFORM_NAME="Android"
PLATFORM_IS_ANDROID=1
else
echo "Unknown Linux: ${uname}"
return 1
fi
else
echo "Unknown platform: ${uname}"
return 1
fi
return 0
}
detect_platform