-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathos_version.sh
More file actions
40 lines (34 loc) · 819 Bytes
/
os_version.sh
File metadata and controls
40 lines (34 loc) · 819 Bytes
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
##
# Get the operating system version
#
# Just the major version number is returned
#
function os_version() {
if [ "$(uname -s)" == 'FreeBSD' ]; then
local _V="$(uname -K)"
if [ ${#_V} -eq 6 ]; then
echo "${_V:0:1}"
elif [ ${#_V} -eq 7 ]; then
echo "${_V:0:2}"
fi
elif [ -f '/etc/os-release' ]; then
local VERS="$(egrep '^VERSION_ID=' /etc/os-release | sed 's:VERSION_ID=::')"
if [[ "$VERS" =~ '"' ]]; then
# Strip quotes around the OS name
VERS="$(echo "$VERS" | sed 's:"::g')"
fi
if [[ "$VERS" =~ \. ]]; then
# Remove the decimal point and everything after
# Trims "24.04" down to "24"
VERS="${VERS/\.*/}"
fi
if [[ "$VERS" =~ "v" ]]; then
# Remove the "v" from the version
# Trims "v24" down to "24"
VERS="${VERS/v/}"
fi
echo "$VERS"
else
echo 0
fi
}