-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.sh
More file actions
executable file
·100 lines (64 loc) · 2.26 KB
/
utils.sh
File metadata and controls
executable file
·100 lines (64 loc) · 2.26 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
get_os() {
local os=""
local kernelName=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
kernelName="$(uname -s)"
if [ "$kernelName" == "Darwin" ]; then
os="macos" || exit 1
fi
if [ "$kernelName" == "Linux" ]; then
# && [ -e "/etc/os-release" ]; then
os="$(. /etc/os-release; printf "%s" "$ID")" || exit 1
else
os="$kernelName" || exit 1
fi
printf "%s" "$os"
}
get_os_version() {
local os=""
local version=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
os="$(get_os)"
if [ "$os" == "macos" ]; then
version="$(sw_vers -productVersion)"
elif [ -e "/etc/os-release" ]; then
version="$(. /etc/os-release; printf "%s" "$VERSION_ID")"
fi
printf "%s" "$version"
}
# Logging stuff.
e_header() { echo -e "\n\033[1m$@\033[0m"; }
e_success() { echo -e " \033[1;32m✔\033[0m $@"; }
e_error() { echo -e " \033[1;31m✖\033[0m $@"; }
e_arrow() { echo -e " \033[1;33m➜\033[0m $@"; }
verify_os(){
declare -r MINIMUM_MACOS_VERSION="10.10"
declare -r MINIMUM_UBUNTU_VERSION="19.04"
local os_name="$(get_os)"
local os_version="$(get_os_version)"
echo "Versión OS" $os_version "->" $os_name
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Check if the OS is `macOS` and
# it's above the required version.
if [ "$os_name" == "macos" ]; then
if is_supported_version "$os_version" "$MINIMUM_MACOS_VERSION"; then
return 0
else
printf "Sorry, this script is intended only for macOS %s+" "$MINIMUM_MACOS_VERSION"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Check if the OS is `Ubuntu` and
# it's above the required version.
elif [ "$os_name" == "ubuntu" ]; then
if is_supported_version "$os_version" "$MINIMUM_UBUNTU_VERSION"; then
return 0
else
printf "Sorry, this script is intended only for Ubuntu %s+" "$MINIMUM_UBUNTU_VERSION"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
else
printf "Sorry, this script is intended only for macOS and Ubuntu!"
fi
return 1
}