]> git.proxmox.com Git - ceph.git/blame - ceph/src/pmdk/utils/version.sh
import ceph 16.2.7
[ceph.git] / ceph / src / pmdk / utils / version.sh
CommitLineData
a4b75251
TL
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#
7set -e
8
9if [ -f "$1/VERSION" ]; then
10 cat "$1/VERSION"
11 exit 0
12fi
13
14if [ -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
21else
22 PARSE_GIT_VERSION=0
23fi
24
25LATEST_RELEASE=$(cat $1/ChangeLog | grep "* Version" | cut -d " " -f 3 | sort -rd | head -n1)
26
27if [ $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
34fi
35
36cd "$1"
37
38GIT_DESCRIBE=$(git describe 2>/dev/null) && true
39if [ -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
44fi
45
46# try commit it, git describe can fail when there are no tags (e.g. with shallow clone, like on Travis)
47GIT_COMMIT=$(git log -1 --format=%h) && true
48if [ -n "$GIT_COMMIT" ]; then
49 echo "$LATEST_RELEASE+git.$GIT_COMMIT"
50 exit 0
51fi
52
53cd - >/dev/null
54
55# If nothing works, try to get version from directory name
56VER=$(basename `realpath "$1"` | sed 's/pmdk[-]*\([0-9a-z.+-]*\).*/\1/')
57if [ -n "$VER" ]; then
58 echo "$VER"
59 exit 0
60fi
61
62exit 1