-
Notifications
You must be signed in to change notification settings - Fork 601
/
version.sh
executable file
·62 lines (54 loc) · 1.47 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
#!/bin/sh
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 'Diamond-.\+' | sed 's/Diamond-//g'`
LOCAL_REV="-github_archive"
fi
VERSION=`echo ${DESC} | awk '{ print $1 }' | tr "." " "`
COMMIT=`echo ${DESC} | awk '{ print $2 }'`
VERSION_MAJ=`echo ${VERSION} | awk '{ print $1 }'`
VERSION_MIN=`echo ${VERSION} | awk '{ print $2 }'`
VERSION_REV=${COMMIT}
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 "mnr" opt; do
case $opt in
m)
# Major Version
echo "${VERSION_MAJ}"
exit 0
;;
n)
# Minor Version
echo "${VERSION_MIN}"
exit 0
;;
r)
# Revision Version
echo "${VERSION_REV}"
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
VERSION="${VERSION_MAJ}.${VERSION_MIN}.${VERSION_REV}${LOCAL_REV}"
if [ -e src/diamond/version.py.tmpl ]
then
cat src/diamond/version.py.tmpl | sed "s/__VERSIONTOKENHERE__/${VERSION}/g" > src/diamond/version.py
fi
echo $VERSION