-
Notifications
You must be signed in to change notification settings - Fork 142
/
version.sh
executable file
·52 lines (44 loc) · 1.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
#!/bin/sh
rootdir="$1"
[ -n "$rootdir" ] || rootdir=.
if [ -z "$PACKAGE_VERSION" ]; then
eval "$(cd "$rootdir" && grep -m1 PACKAGE_VERSION configure \
2>/dev/null)"
fi
[ ! -f "$1/VERSION" ] || VN="$(cat VERSION)"
if [ -z "$VN" ] && [ -d "$rootdir/.git" ]; then
VN=$(cd "$rootdir" &&
git describe --tags --match 'v[0-9]*' 2>/dev/null)
if [ -z "$VN" ]; then
VN=$(cd "$rootdir" &&
git log -1 --pretty=format:"git-%cd-%h" --date=short \
2>/dev/null)
[ -z "$VN" ] || VN="$PACKAGE_VERSION-$VN"
fi
fi
# try substituted hash if any
if [ -z "$VN" ]; then
git_date="$Format:%ci"
git_hash="$Format:%h$"
if ! [ "${git_hash:0:1}" = "\$" ]; then
git_date="${git_date%% *}"
VN="$PACKAGE_VERSION-$git_date-$git_hash"
fi
fi
# try name of directory (from github tarballs)
if [ -z "$VN" ]; then
srcdir="$(cd "$1" && pwd)"
case "$srcdir" in
*/*-*-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
git_hash="${srcdir##*-}"
[ -z "$PACKAGE_VERSION" ] || VN="$PACKAGE_VERSION-$git_hash"
;;
esac
fi
VN=$(expr "$VN" : v*'\(.*\)')
[ -n "$VN" ] || VN="$PACKAGE_VERSION"
if [ -n "$VN" ]; then
echo "$VN"
else
echo "0-UNKNOWN"
fi