forked from munin-monitoring/munin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getversion
executable file
·70 lines (62 loc) · 1.95 KB
/
getversion
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
#!/bin/sh
# Generate a version string for use when building.
#
# * If RELEASE exists, and is non-empty, use the contents of that file.
# This is in case we're building from a tarball.
#
# * If we're inside a git tree:
# - For the "master" branch, use "git describe".
# - For "detached" branches (mostly for tag checkouts), also use "git describe".
# - For other branches, use a "$VERSION-$NBCOMMITS-$BRANCH-$DATE-g$COMMIT"
# sortof version.
#
# * Try to make it up from the directory name (munin-2.0.1 -> 2.0.1)
#
# * If we're still looking for a version, just fallback to "unknown".
current_git_branch() {
GB="$(git branch | awk '$1 == "*" {print $2}')"
case $GB in
# git checkout 402c6d6
# git branch
# * (detached from 402c6d6)
# devel
# --> This is new with git 1.8+
"(detached" ) echo "detached";;
# git checkout 2.0.9
# git branch
# * (no branch)
# devel
"(no" ) echo;;
* ) echo $GB;;
esac
}
generate_version_string() {
branch="$(current_git_branch)"
case "${branch}" in
""|master|devel|stable-*)
git describe
;;
*)
branch=$(echo $branch | sed -e 's/[^0-9A-Za-z\.\-\_]/_/g' )
# "foo | read VAR" does *not* work
# workaround stolen from http://www.etalabs.net/sh_tricks.html
read VERSION COMMITS HASH <<EOF
$(git describe --long | perl -lne 'print "$1 $2 $3" if m/(.*)-(\d+)-g(\w+)/')
EOF
# As git describe, we also use the "-g" magic string to denote a git hash
git log -n 1 --pretty="${VERSION}-${branch}-%ad-c${COMMITS}-g%h" --date=short
;;
esac
}
generate_version_string_from_dir() {
basename $(pwd) | grep -e '^munin-' | cut -c7-
}
if [ -s "RELEASE" ]; then
cat RELEASE
elif [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
generate_version_string
elif [ ! -z "$(generate_version_string_from_dir)" ]; then
generate_version_string_from_dir
else
echo "unknown"
fi