consul/build-support/scripts/release.sh

131 lines
3.5 KiB
Bash
Raw Normal View History

#!/bin/bash
SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})"
pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null
SCRIPT_DIR=$(pwd)
pushd ../.. > /dev/null
SOURCE_DIR=$(pwd)
popd > /dev/null
pushd ../functions > /dev/null
FN_DIR=$(pwd)
popd > /dev/null
popd > /dev/null
source "${SCRIPT_DIR}/functions.sh"
function usage {
cat <<-EOF
Usage: ${SCRIPT_NAME} [<options ...>]
Options:
-s | --source DIR Path to source to build.
Defaults to "${SOURCE_DIR}"
-t | --tag BOOL Whether to add a release commit and tag the build
Defaults to 1.
-b | --build BOOL Whether to perform the build of the ui's, assetfs and
binaries. Defaults to 1.
-S | --sign BOOL Whether to sign the generated SHA256SUMS file.
Defaults to 1.
-g | --gpg-key KEY Alternative GPG key to use for signing operations.
Defaults to ${HASHICORP_GPG_KEY}
-v | --version VERSION The version of Consul to be built. If not specified
the version will be parsed from the source.
-d | --date DATE The release date. Defaults to today.
-h | --help Print this help text.
EOF
}
function err_usage {
err "$1"
err ""
err "$(usage)"
}
function ensure_arg {
if test -z "$2"
then
err_usage "ERROR: option $1 requires an argument"
return 1
fi
return 0
}
function main {
declare sdir="${SOURCE_DIR}"
declare -i do_tag=1
declare -i do_build=1
declare -i do_sign=1
declare gpg_key="${HASHICORP_GPG_KEY}"
declare version=""
declare release_date=$(date +"%B %d, %Y")
while test $# -gt 0
do
case "$1" in
-h | --help )
usage
return 0
;;
-s | --source )
ensure_arg "-s/--source" "$2" || return 1
if ! test -d "$2"
then
err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source"
return 1
fi
sdir="$2"
shift 2
;;
-t | --tag )
ensure_arg "-t/--tag" "$2" || return 1
do_tag="$2"
shift 2
;;
-b | --build )
ensure_arg "-b/--build" "$2" || return 1
do_build="$2"
shift 2
;;
-S | --sign )
ensure_arg "-s/--sign" "$2" || return 1
do_sign="$2"
shift 2
;;
-g | --gpg-key )
ensure_arg "-g/--gpg-key" "$2" || return 1
gpg_key="$2"
shift 2
;;
-v | --version )
ensure_arg "-v/--version" "$2" || return 1
version="$2"
shift 2
;;
-d | --date)
ensure_arg "-d/--date" "$2" || return 1
release_date="$2"
shift 2
;;
*)
err_usage "ERROR: Unknown argument: '$1'"
return 1
;;
esac
done
build_release "${sdir}" "${do_tag}" "${do_build}" "${do_sign}" "${version}" "${release_date}" "${gpg_key}"
return $?
}
main $@
exit $?