status-react/scripts/toolversion

46 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
################################################################################
# This tool fetches versions and checksums of build tools from the .TOOLVERSIONS
# file in project root. This is then used by various setup scripts,
# and most importantly by Dockerfiles.
################################################################################
set -e
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
TOOL_VERSIONS_FILE="${GIT_ROOT}/.TOOLVERSIONS"
usage () {
echo "Usage: toolversion [-c] <name>" >&2
echo
echo "This script extracts tooling versions from ${TOOL_VERSIONS_FILE}"
exit 0
}
# some options parsing
while getopts ":ch" opt; do
case $opt in
c) CHECKSUM=1; shift ;;
h) usage;;
\?) echo "Invalid option: -$OPTARG" >&2; exit 1;;
esac
done
# verify the main argument was given
if [[ -z "${1}" ]]; then usage; fi
NAME=${1}
getColumn () {
local value=$(awk -F';' "/^${NAME};/{print \$${1}}" "${TOOL_VERSIONS_FILE}")
[ -z "$value" ] && echo "\nUnexpected missing value for ${NAME} in ${TOOL_VERSIONS_FILE}" && exit 1
echo $value
}
if [[ $CHECKSUM ]]; then
getColumn 3
else
getColumn 2
fi