]> git.proxmox.com Git - ceph.git/blob - ceph/src/pmdk/utils/version.sh
import ceph 16.2.7
[ceph.git] / ceph / src / pmdk / utils / version.sh
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright 2017-2020, Intel Corporation
4 #
5 # utils/version.sh -- determine project's version
6 #
7 set -e
8
9 if [ -f "$1/VERSION" ]; then
10 cat "$1/VERSION"
11 exit 0
12 fi
13
14 if [ -f $1/GIT_VERSION ]; then
15 echo -n "\$Format:%h\$" | cmp -s $1/GIT_VERSION - && true
16 if [ $? -eq 0 ]; then
17 PARSE_GIT_VERSION=0
18 else
19 PARSE_GIT_VERSION=1
20 fi
21 else
22 PARSE_GIT_VERSION=0
23 fi
24
25 LATEST_RELEASE=$(cat $1/ChangeLog | grep "* Version" | cut -d " " -f 3 | sort -rd | head -n1)
26
27 if [ $PARSE_GIT_VERSION -eq 1 ]; then
28 GIT_VERSION_HASH=$(cat $1/GIT_VERSION)
29
30 if [ -n "$GIT_VERSION_HASH" ]; then
31 echo "$LATEST_RELEASE+git.$GIT_VERSION_HASH"
32 exit 0
33 fi
34 fi
35
36 cd "$1"
37
38 GIT_DESCRIBE=$(git describe 2>/dev/null) && true
39 if [ -n "$GIT_DESCRIBE" ]; then
40 # 1.5-19-gb8f78a329 -> 1.5+git19.gb8f78a329
41 # 1.5-rc1-19-gb8f78a329 -> 1.5-rc1+git19.gb8f78a329
42 echo "$GIT_DESCRIBE" | sed "s/\([0-9.]*\)-rc\([0-9]*\)-\([0-9]*\)-\([0-9a-g]*\)/\1-rc\2+git\3.\4/" | sed "s/\([0-9.]*\)-\([0-9]*\)-\([0-9a-g]*\)/\1+git\2.\3/"
43 exit 0
44 fi
45
46 # try commit it, git describe can fail when there are no tags (e.g. with shallow clone, like on Travis)
47 GIT_COMMIT=$(git log -1 --format=%h) && true
48 if [ -n "$GIT_COMMIT" ]; then
49 echo "$LATEST_RELEASE+git.$GIT_COMMIT"
50 exit 0
51 fi
52
53 cd - >/dev/null
54
55 # If nothing works, try to get version from directory name
56 VER=$(basename `realpath "$1"` | sed 's/pmdk[-]*\([0-9a-z.+-]*\).*/\1/')
57 if [ -n "$VER" ]; then
58 echo "$VER"
59 exit 0
60 fi
61
62 exit 1