blob: 40c473246202c5264ec694e9bf152a3f8d8c81e1 (
plain)
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
|
#!/usr/bin/env bash
# This script produces various bits of metadata needed by Makefile. Using
# a script allows uniform behavior across multiple environments and
# distributions. The script expects a single argument, as reflected below.
set -euo pipefail
cd "${GOSRC:-$(dirname $0)/../}"
valid_args() {
REGEX='^\s+[[:upper:]]+\*[)]'
egrep --text --no-filename --group-separator=' ' --only-matching "$REGEX" "$0" | \
cut -d '*' -f 1
}
# `git describe` does not reliably produce a useful version number.
scrape_version() {
local versionfile='version/version.go'
local version_line=$(grep -m 1 'var Version =' $versionfile)
local version_string=$(cut -d '"' -f 2 <<<"$version_line")
echo "$version_string" | tr -d '[:space:]'
}
unset OUTPUT
case "$1" in
# Wild-card suffix needed by valid_args() e.g. possible bad grep of "$(echo $FOO)"
VERSION*)
OUTPUT="${CIRRUS_TAG:-$(scrape_version)}"
;;
NUMBER*)
OUTPUT="$($0 VERSION | sed 's/-.*//')"
;;
DIST_VER*)
OUTPUT="$(source /etc/os-release; echo $VERSION_ID | cut -d '.' -f 1)"
;;
DIST*)
OUTPUT="$(source /etc/os-release; echo $ID)"
;;
ARCH*)
OUTPUT="${GOARCH:-$(go env GOARCH 2> /dev/null)}"
;;
BASENAME*)
OUTPUT="podman"
;;
REMOTENAME*)
OUTPUT="$($0 BASENAME)-remote"
;;
*)
echo "Error, unknown/unsupported argument '$1', valid arguments:"
valid_args
exit 1
;;
esac
if [[ -n "$OUTPUT" ]]
then
echo -n "$OUTPUT"
else
echo "Error, empty output for info: '$1'" > /dev/stderr
exit 2
fi
|