-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.sh
executable file
·89 lines (68 loc) · 1.5 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
85
86
87
88
89
#!/bin/bash
# generate version string
######################
# release version
MAJOR=0
MINOR=0
MICRO=1
# ----------------------------------------------
# function to print helptext
function help()
{
echo "$0 --long | --short | --major | --minor | --micro | --git"
}
# output micro version
function micro()
{
echo -n $MICRO
}
# output minor version
function minor()
{
echo -n $MINOR
}
# output major version
function major()
{
echo -n $MAJOR
}
# output git version
function output_git()
{
T=$(git describe --always --dirty)
echo -n ${T%%"\n"*}
}
# output short version string
function output_short()
{
echo -n $(major).$(minor).$(micro)
}
# output long version string
function output_long()
{
echo -n $(major).$(minor).$(micro)-$(output_git)
}
# parse cmdline arguments
TEMP=`getopt -o lsMmug --long long,short,major,minor,micro,git -n 'version.sh' -- "$@"`
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"
while true ; do
case "$1" in
# long
-l|--long) output_long ; shift 1 ;;
# short
-s|--short) output_short ; shift 1 ;;
# git
-g|--git) output_git ; shift 1 ;;
# major
-M|--major) major ; shift 1 ;;
# minor
-m|--minor) minor ; shift 1 ;;
# micro
-u|--micro) micro ; shift 1 ;;
# ?!
--) shift ; break ;;
*) echo "Argument parsing error!" ; exit 1 ;;
esac
done