forked from munin-monitoring/munin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetversion
executable file
·47 lines (42 loc) · 1.24 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
#!/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 "devel" branch, generate a "devel-date-hash" version.
#
# - For other branches, use "git describe". This should result in a
# clean version for the tagged releases on "master", and a
# version-revision on the packaging tags.
#
# If we're still looking for a version, use "unknown".
current_git_branch() {
git branch | awk '$1 == "*" {print $2}'
}
generate_version_string() {
branch="$(current_git_branch)"
case "${branch}" in
master)
git describe
;;
*)
GIT_REVISION="$(git describe --long | sed 's/-g.*//')"
git log -n 1 --pretty="${GIT_REVISION}-${branch}-%ad-%tc" --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