Files
podman/hack/get_release_info.sh
Chris Evich 0e83851f08 Simplify Makefile help target
An in-line Python script, while flexible, is arguably
more complex and less stable than the long-lived `grep`,
`awk`, and `printf`.  Make use of these simple tools
to display a column-aligned table of target and description
help output.

Also, the first target that appears in a Makefile is considered
the default (when no target is specified on the command-line).
However, despite it's name, the `default` target was not listed
first.  Fix this, and redefine "default" target to "all" as
intended, instead of "help".

Lastly, add a small workaround for a vim syntax-hilighting bug.

Signed-off-by: Chris Evich <cevich@redhat.com>
2021-04-12 10:19:51 -04:00

71 lines
2.0 KiB
Bash
Executable File

#!/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` will never produce a useful version number under all
# branches. This is because the podman release process (see `RELEASE_PROCESS.md`)
# tags release versions only on release-branches (i.e. never on master).
# Scraping the version number directly from the source, is the only way
# to reliably obtain the number from all the various contexts supported by
# the `Makefile`.
scrape_version() {
local v
# extract the value of 'var Version'
v=$(sed -ne 's/^var\s\+Version\s\+=\s.*("\(.*\)").*/\1/p' <version/version.go)
# If it's empty, something has changed in version.go, that would be bad!
test -n "$v"
# Value consumed literally, must not have any embedded newlines
echo -n "$v"
}
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