-
Notifications
You must be signed in to change notification settings - Fork 4
/
version.sh
executable file
·84 lines (77 loc) · 2.13 KB
/
version.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
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
#!/bin/sh
ROCKS_VERSION=`cat /etc/rocks-release | awk '{print $3}'`
DESC_CMD="git describe --match 'v${ROCKS_VERSION}' 2>/dev/null | sed \"s/v\([0-9\.]*\)-*\([0-9]*\)-*\([0-9a-z]*\)/\1 \2 \3/\""
DESC=`eval ${DESC_CMD}`
#DESC=`git describe --match 'v*' 2>/dev/null | sed "s/v\([0-9\.]*\)-*\([0-9]*\)-*\([0-9a-z]*\)/\1 \2 \3/"`
if [ -z "${DESC}" ]
then
# Try to support using the tagged downloads
DESC=`pwd | grep -oe 'mlnx-ofed-roll-.\+' | sed 's/mlnx-ofed-roll-//g'`
LOCAL_REV="-github_archive"
fi
VERSION=`echo ${DESC} | awk '{ print $1 }' | tr "." " "`
COMMIT=`echo ${DESC} | awk '{ print $2 }'`
HASH=`echo ${DESC} | awk '{ print $3}'`
VERSION_MAJ=`echo ${VERSION} | awk '{ print $1 }'`
VERSION_MIN=`echo ${VERSION} | awk '{ print $2 }'`
VERSION_DOT=`echo ${VERSION} | awk '{ print $3 }'`
[ "${VERSION_DOT}" != "" ] && VERSION_DOT="."${VERSION_DOT}
VERSION_REV=${COMMIT}
VERSION_HASH=${HASH}
if [ -z "${VERSION_REV}" ]; then
VERSION_REV="0"
fi
#Allow local revision identifiers
#mimicing backports this is "-<identifier>"
if [ -e localversion ]; then
LOCAL_REV=$(cat localversion)
if [ -n "${LOCAL_REV}" ];
then
LOCAL_REV="-${LOCAL_REV}"
fi
fi
while getopts "avmndrh" opt; do
case $opt in
a)
# Major.Minor-Release.Hash
echo "${VERSION_MAJ}.${VERSION_MIN}${VERSION_DOT}-${VERSION_REV}.${VERSION_HASH}"
exit 0
;;
v)
# Major.Minor.Dot Version
echo "${VERSION_MAJ}.${VERSION_MIN}${VERSION_DOT}"
exit 0
;;
m)
# Major Version
echo "${VERSION_MAJ}"
exit 0
;;
n)
# Minor Version
echo "${VERSION_MIN}"
exit 0
;;
d)
# Dot Version
echo `echo ${VERSION_DOT} | cut -d. -f2`
exit 0
;;
r)
# Revision Version
echo "${VERSION_REV}"
exit 0
;;
h)
# Revision Hash
echo "${VERSION_REV}.${VERSION_HASH}"
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
VERSION="${VERSION_MAJ}.${VERSION_MIN}.${VERSION_REV}${LOCAL_REV}"
echo $VERSION