forked from Chia-Network/bladebit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract-version.sh
executable file
·81 lines (64 loc) · 1.78 KB
/
extract-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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#! /usr/bin/env bash
set -eo pipefail
_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)"
cd $_dir
# Arguments
ver_component=$1 # The user specified a specified component from the full verison.
# See the case switch below.
# Grab version specified in the file
_IFS=IFS
IFS=
version_str=$(cat VERSION | head -n 1 | xargs)
bb_version_suffix=$(cat VERSION | tail -n 1 | xargs)
version_header='src/Version.h'
IFS=$_IFS
if [[ "$version_str" == "$bb_version_suffix" ]]; then
bb_version_suffix=
fi
# prepend a '-' to the suffix, if necessarry
if [[ -n "$bb_version_suffix" ]] && [[ "${bb_version_suffix:0:1}" != "-" ]]; then
bb_version_suffix="-${bb_version_suffix}"
fi
bb_ver_maj=$(printf $version_str | sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+)/\1/' | xargs)
bb_ver_min=$(printf $version_str | sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+)/\2/' | xargs)
bb_ver_rev=$(printf $version_str | sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+)/\3/' | xargs)
bb_git_commit=$GITHUB_SHA
if [[ -z $bb_git_commit ]]; then
set +e
bb_git_commit=$(git rev-parse HEAD)
set -e
fi
if [[ -z $bb_git_commit ]]; then
bb_git_commit="unknown"
fi
# Check if the user wants a specific component
if [[ -n $ver_component ]]; then
case "$ver_component" in
"major")
echo -n $bb_ver_maj
;;
"minor")
echo -n $bb_ver_min
;;
"revision")
echo -n $bb_ver_rev
;;
"suffix")
echo -n $bb_version_suffix
;;
"commit")
echo -n $bb_git_commit
;;
*)
>&2 echo "Invalid version component '${ver_component}'"
exit 1
;;
esac
exit 0
fi
# Emit all version components
# echo "MAJ: $bb_ver_maj"
# echo "MIN: $bb_ver_min"
# echo "REV: $bb_ver_rev"
# echo "SUF: $bb_version_suffix"
# echo "COM: $bb_git_commit"