-
Notifications
You must be signed in to change notification settings - Fork 0
/
OSVersionHandler.sh
39 lines (34 loc) · 1.24 KB
/
OSVersionHandler.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
39
#! /bin/bash
function osVersionHandler {
input="$1"
primaryValue=$(echo -n "$input" | /usr/bin/awk -F '.' '{print $1}')
primaryMajor=$(echo -n "$input" | /usr/bin/awk -F '.' '{print $2}')
primaryMinor=$(echo -n "$input" | /usr/bin/awk -F '.' '{print $3}')
fullVersion=$(/usr/bin/sw_vers -productVersion)
primary=$(echo -n "$fullVersion" | /usr/bin/awk -F '.' '{print $1}')
major=$(echo -n "$fullVersion" | /usr/bin/awk -F '.' '{print $2}')
minor=$(echo -n "$fullVersion" | /usr/bin/awk -F '.' '{print $3}')
if [[ $primaryValue -eq $primary ]] && [[ $primaryMajor -eq $major ]] && [[ $primaryMinor -eq $minor ]]
then
versionReturn="MATCHES"
else
if [[ $primaryValue -gt $primary ]] || [[ $primaryMajor -gt $major ]]
then
versionReturn="OLDERMAJOR"
elif [[ $primaryValue -eq $primary ]] && [[ $primaryMajor -eq $major ]] && [[ $primaryMinor -gt $minor ]]
then
versionReturn="OLDERMINOR"
elif [[ $primaryValue -lt $primary ]] || [[ $primaryMajor -lt $major ]]
then
versionReturn="NEWERMAJOR"
elif [[ $primaryValue -eq $primary ]] && [[ $primaryMajor -eq $major ]] && [[ $primaryMinor -lt $minor ]]
then
versionReturn="NEWERMINOR"
fi
fi
}
osVersionHandler "11.0.0"
echo $versionReturn
echo $primary
echo $major
echo $minor