github.com/AbhinandanKurakure/podman/v3@v3.4.10/hack/get_release_info.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # This script produces various bits of metadata needed by Makefile.  Using
     4  # a script allows uniform behavior across multiple environments and
     5  # distributions.  The script expects a single argument, as reflected below.
     6  
     7  set -euo pipefail
     8  
     9  cd "${GOSRC:-$(dirname $0)/../}"
    10  
    11  valid_args() {
    12      REGEX='^\s+[[:upper:]]+\*[)]'
    13      egrep --text --no-filename --group-separator=' ' --only-matching "$REGEX" "$0" | \
    14          cut -d '*' -f 1
    15  }
    16  
    17  # `git describe` will never produce a useful version number under all
    18  # branches.  This is because the podman release process (see `RELEASE_PROCESS.md`)
    19  # tags release versions only on release-branches (i.e. never on main).
    20  # Scraping the version number directly from the source, is the only way
    21  # to reliably obtain the number from all the various contexts supported by
    22  # the `Makefile`.
    23  scrape_version() {
    24      local v
    25      # extract the value of 'var Version'
    26      v=$(sed -ne 's/^var\s\+Version\s\+=\s.*("\(.*\)").*/\1/p' <version/version.go)
    27      # If it's empty, something has changed in version.go, that would be bad!
    28      test -n "$v"
    29      # Value consumed literally, must not have any embedded newlines
    30      echo -n "$v"
    31  }
    32  
    33  unset OUTPUT
    34  case "$1" in
    35      # Wild-card suffix needed by valid_args() e.g. possible bad grep of "$(echo $FOO)"
    36      VERSION*)
    37          OUTPUT="${CIRRUS_TAG:-$(scrape_version)}"
    38          ;;
    39      NUMBER*)
    40          OUTPUT="$($0 VERSION | sed 's/-.*//')"
    41          ;;
    42      DIST_VER*)
    43          OUTPUT="$(source /etc/os-release; echo $VERSION_ID | cut -d '.' -f 1)"
    44          ;;
    45      DIST*)
    46          OUTPUT="$(source /etc/os-release; echo $ID)"
    47          ;;
    48      ARCH*)
    49          OUTPUT="${GOARCH:-$(go env GOARCH 2> /dev/null)}"
    50          ;;
    51      BASENAME*)
    52          OUTPUT="podman"
    53          ;;
    54      REMOTENAME*)
    55          OUTPUT="$($0 BASENAME)-remote"
    56          ;;
    57      *)
    58          echo "Error, unknown/unsupported argument '$1', valid arguments:"
    59          valid_args
    60          exit 1
    61          ;;
    62  esac
    63  
    64  if [[ -n "$OUTPUT" ]]
    65  then
    66      echo -n "$OUTPUT"
    67  else
    68      echo "Error, empty output for info: '$1'" > /dev/stderr
    69      exit 2
    70  fi