Improved some more bash script variable definitions

This commit is contained in:
Roy Lenferink
2019-01-21 23:11:58 +01:00
parent f788854e98
commit b18bc2ea79
12 changed files with 72 additions and 72 deletions

View File

@@ -48,9 +48,9 @@ kube::etcd::validate() {
# validate installed version is at least equal to minimum
version=$(etcd --version | tail -n +1 | head -n 1 | cut -d " " -f 3)
if [[ $(kube::etcd::version ${ETCD_VERSION}) -gt $(kube::etcd::version ${version}) ]]; then
export PATH=${KUBE_ROOT}/third_party/etcd:$PATH
export PATH=${KUBE_ROOT}/third_party/etcd:${PATH}
hash etcd
echo $PATH
echo "${PATH}"
version=$(etcd --version | head -n 1 | cut -d " " -f 3)
if [[ $(kube::etcd::version ${ETCD_VERSION}) -gt $(kube::etcd::version ${version}) ]]; then
kube::log::usage "etcd version ${ETCD_VERSION} or greater required."

View File

@@ -88,10 +88,10 @@ readonly KUBE_NODE_BINARIES=("${KUBE_NODE_TARGETS[@]##*/}")
readonly KUBE_NODE_BINARIES_WIN=("${KUBE_NODE_BINARIES[@]/%/.exe}")
if [[ -n "${KUBE_BUILD_PLATFORMS:-}" ]]; then
IFS=" " read -ra KUBE_SERVER_PLATFORMS <<< "$KUBE_BUILD_PLATFORMS"
IFS=" " read -ra KUBE_NODE_PLATFORMS <<< "$KUBE_BUILD_PLATFORMS"
IFS=" " read -ra KUBE_TEST_PLATFORMS <<< "$KUBE_BUILD_PLATFORMS"
IFS=" " read -ra KUBE_CLIENT_PLATFORMS <<< "$KUBE_BUILD_PLATFORMS"
IFS=" " read -ra KUBE_SERVER_PLATFORMS <<< "${KUBE_BUILD_PLATFORMS}"
IFS=" " read -ra KUBE_NODE_PLATFORMS <<< "${KUBE_BUILD_PLATFORMS}"
IFS=" " read -ra KUBE_TEST_PLATFORMS <<< "${KUBE_BUILD_PLATFORMS}"
IFS=" " read -ra KUBE_CLIENT_PLATFORMS <<< "${KUBE_BUILD_PLATFORMS}"
readonly KUBE_SERVER_PLATFORMS
readonly KUBE_NODE_PLATFORMS
readonly KUBE_TEST_PLATFORMS
@@ -268,11 +268,11 @@ kube::golang::is_statically_linked_library() {
[[ "$(go env GOHOSTOS)" == "darwin" && "$(go env GOOS)" == "darwin" &&
"$1" == *"/kubectl" ]] && return 1
if [[ -n "${KUBE_CGO_OVERRIDES:+x}" ]]; then
for e in "${KUBE_CGO_OVERRIDES[@]}"; do [[ "$1" == *"/$e" ]] && return 1; done;
for e in "${KUBE_CGO_OVERRIDES[@]}"; do [[ "${1}" == *"/${e}" ]] && return 1; done;
fi
for e in "${KUBE_STATIC_LIBRARIES[@]}"; do [[ "$1" == *"/$e" ]] && return 0; done;
for e in "${KUBE_STATIC_LIBRARIES[@]}"; do [[ "${1}" == *"/${e}" ]] && return 0; done;
if [[ -n "${KUBE_STATIC_OVERRIDES:+x}" ]]; then
for e in "${KUBE_STATIC_OVERRIDES[@]}"; do [[ "$1" == *"/$e" ]] && return 0; done;
for e in "${KUBE_STATIC_OVERRIDES[@]}"; do [[ "${1}" == *"/${e}" ]] && return 0; done;
fi
return 1;
}
@@ -426,7 +426,7 @@ kube::golang::setup_env() {
# resultant binaries. Go will not let us use GOBIN with `go install` and
# cross-compiling, and `go install -o <file>` only works for a single pkg.
local subdir
subdir=$(kube::realpath . | sed "s|$KUBE_ROOT||")
subdir=$(kube::realpath . | sed "s|${KUBE_ROOT}||")
cd "${KUBE_GOPATH}/src/${KUBE_GO_PACKAGE}/${subdir}"
# Set GOROOT so binaries that parse code can work properly.
@@ -458,7 +458,7 @@ kube::golang::place_bins() {
# The substitution on platform_src below will replace all slashes with
# underscores. It'll transform darwin/amd64 -> darwin_amd64.
local platform_src="/${platform//\//_}"
if [[ "$platform" == "$host_platform" ]]; then
if [[ "${platform}" == "${host_platform}" ]]; then
platform_src=""
rm -f "${THIS_PLATFORM_BIN}"
ln -s "${KUBE_OUTPUT_BINPATH}/${platform}" "${THIS_PLATFORM_BIN}"
@@ -479,7 +479,7 @@ kube::golang::outfile_for_binary() {
local binary=$1
local platform=$2
local output_path="${KUBE_GOPATH}/bin"
if [[ "$platform" != "$host_platform" ]]; then
if [[ "${platform}" != "${host_platform}" ]]; then
output_path="${output_path}/${platform//\//_}"
fi
local bin=$(basename "${binary}")
@@ -502,7 +502,7 @@ kube::golang::path_for_coverage_dummy_test() {
local package="$1"
local path="${KUBE_GOPATH}/src/${package}"
local name=$(basename "${package}")
echo "$path/zz_generated_${name}_test.go"
echo "${path}/zz_generated_${name}_test.go"
}
# Argument: the name of a Kubernetes package (e.g. k8s.io/kubernetes/cmd/kube-scheduler).

View File

@@ -132,15 +132,15 @@ KUBE_NONSERVER_GROUP_VERSIONS="
function kube::readlinkdashf {
# run in a subshell for simpler 'cd'
(
if [[ -d "$1" ]]; then # This also catch symlinks to dirs.
cd "$1"
if [[ -d "${1}" ]]; then # This also catch symlinks to dirs.
cd "${1}"
pwd -P
else
cd "$(dirname "$1")"
cd "$(dirname "${1}")"
local f
f=$(basename "$1")
if [[ -L "$f" ]]; then
readlink "$f"
f=$(basename "${1}")
if [[ -L "${f}" ]]; then
readlink "${f}"
else
echo "$(pwd -P)/${f}"
fi
@@ -176,9 +176,9 @@ function kube::readlinkdashf {
# testone $T/linkdir/linkfile
# testone $T/linkdir/linkdir
kube::realpath() {
if [[ ! -e "$1" ]]; then
echo "$1: No such file or directory" >&2
if [[ ! -e "${1}" ]]; then
echo "${1}: No such file or directory" >&2
return 1
fi
kube::readlinkdashf "$1"
kube::readlinkdashf "${1}"
}

View File

@@ -37,7 +37,7 @@ kube::log::errexit() {
kube::log::error " ${i}: ${BASH_SOURCE[${i}+1]}:${BASH_LINENO[${i}]} ${FUNCNAME[${i}]}(...)"
done
fi
kube::log::error_exit "Error in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}. '${BASH_COMMAND}' exited with status $err" "${1:-1}" 1
kube::log::error_exit "Error in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}. '${BASH_COMMAND}' exited with status ${err}" "${1:-1}" 1
}
kube::log::install_errexit() {
@@ -63,9 +63,9 @@ kube::log::stack() {
for ((i=1 ; i <= ${#FUNCNAME[@]} - ${stack_skip} ; i++))
do
local frame_no=$((i - 1 + stack_skip))
local source_file=${BASH_SOURCE[$frame_no]}
local source_file=${BASH_SOURCE[${frame_no}]}
local source_lineno=${BASH_LINENO[$((frame_no - 1))]}
local funcname=${FUNCNAME[$frame_no]}
local funcname=${FUNCNAME[${frame_no}]}
echo " ${i}: ${source_file}:${source_lineno} ${funcname}(...)" >&2
done
fi
@@ -83,7 +83,7 @@ kube::log::error_exit() {
stack_skip=$((stack_skip + 1))
if [[ ${KUBE_VERBOSE} -ge 4 ]]; then
local source_file=${BASH_SOURCE[$stack_skip]}
local source_file=${BASH_SOURCE[${stack_skip}]}
local source_line=${BASH_LINENO[$((stack_skip - 1))]}
echo "!!! Error in ${source_file}:${source_line}" >&2
[[ -z ${1-} ]] || {
@@ -101,10 +101,10 @@ kube::log::error_exit() {
# Log an error but keep going. Don't dump the stack or exit.
kube::log::error() {
timestamp=$(date +"[%m%d %H:%M:%S]")
echo "!!! $timestamp ${1-}" >&2
echo "!!! ${timestamp} ${1-}" >&2
shift
for message; do
echo " $message" >&2
echo " ${message}" >&2
done
}
@@ -113,7 +113,7 @@ kube::log::usage() {
echo >&2
local message
for message; do
echo "$message" >&2
echo "${message}" >&2
done
echo >&2
}
@@ -121,7 +121,7 @@ kube::log::usage() {
kube::log::usage_from_stdin() {
local messages=()
while read -r line; do
messages+=("$line")
messages+=("${line}")
done
kube::log::usage "${messages[@]}"
@@ -135,21 +135,21 @@ kube::log::info() {
fi
for message; do
echo "$message"
echo "${message}"
done
}
# Just like kube::log::info, but no \n, so you can make a progress bar
kube::log::progress() {
for message; do
echo -e -n "$message"
echo -e -n "${message}"
done
}
kube::log::info_from_stdin() {
local messages=()
while read -r line; do
messages+=("$line")
messages+=("${line}")
done
kube::log::info "${messages[@]}"
@@ -163,9 +163,9 @@ kube::log::status() {
fi
timestamp=$(date +"[%m%d %H:%M:%S]")
echo "+++ $timestamp $1"
echo "+++ ${timestamp} ${1}"
shift
for message; do
echo " $message"
echo " ${message}"
done
}

View File

@@ -34,9 +34,9 @@ kube::swagger::gen_types_swagger_doc() {
echo "Generating swagger type docs for ${group_version} at ${gv_dir}"
echo -e "$(cat hack/boilerplate/boilerplate.generatego.txt)\n" > "$TMPFILE"
echo "package ${group_version##*/}" >> "$TMPFILE"
cat >> "$TMPFILE" <<EOF
echo -e "$(cat hack/boilerplate/boilerplate.generatego.txt)\n" > "${TMPFILE}"
echo "package ${group_version##*/}" >> "${TMPFILE}"
cat >> "${TMPFILE}" <<EOF
// This file contains a collection of methods that can be used from go-restful to
// generate Swagger API documentation for its models. Please read this PR for more
@@ -54,10 +54,10 @@ EOF
go run cmd/genswaggertypedocs/swagger_type_docs.go -s \
"${gv_dir}/types.go" \
-f - \
>> "$TMPFILE"
>> "${TMPFILE}"
echo "// AUTO-GENERATED FUNCTIONS END HERE" >> "$TMPFILE"
echo "// AUTO-GENERATED FUNCTIONS END HERE" >> "${TMPFILE}"
gofmt -w -s "$TMPFILE"
mv "$TMPFILE" ""${gv_dir}"/types_swagger_doc_generated.go"
gofmt -w -s "${TMPFILE}"
mv "${TMPFILE}" ""${gv_dir}"/types_swagger_doc_generated.go"
}

View File

@@ -35,8 +35,8 @@ kube::test::clear_all() {
# Defaults to 2 levels so you can call this to find your own caller
kube::test::get_caller() {
local levels=${1:-2}
local caller_file="${BASH_SOURCE[$levels]}"
local caller_line="${BASH_LINENO[$levels-1]}"
local caller_file="${BASH_SOURCE[${levels}]}"
local caller_line="${BASH_LINENO[${levels}-1]}"
echo "$(basename "${caller_file}"):${caller_line}"
}

View File

@@ -45,9 +45,9 @@ kube::util::wait_for_url() {
}
local i
for i in $(seq 1 "$times"); do
for i in $(seq 1 "${times}"); do
local out
if out=$(curl --max-time "$maxtime" -gkfs "$url" 2>/dev/null); then
if out=$(curl --max-time "${maxtime}" -gkfs "${url}" 2>/dev/null); then
kube::log::status "On try ${i}, ${prefix}: ${out}"
return 0
fi
@@ -441,11 +441,11 @@ kube::util::ensure_no_staging_repos_in_gopath() {
kube::util::ensure_single_dir_gopath
local error=0
for repo_file in "${KUBE_ROOT}"/staging/src/k8s.io/*; do
if [[ ! -d "$repo_file" ]]; then
if [[ ! -d "${repo_file}" ]]; then
# not a directory or there were no files
continue;
fi
repo="$(basename "$repo_file")"
repo="$(basename "${repo_file}")"
if [ -e "${GOPATH}/src/k8s.io/${repo}" ]; then
echo "k8s.io/${repo} exists in GOPATH. Remove before running godep-save.sh." 1>&2
error=1
@@ -722,7 +722,7 @@ function kube::util::ensure-cfssl {
mkdir -p "${cfssldir}"
pushd "${cfssldir}" > /dev/null
echo "Unable to successfully run 'cfssl' from $PATH; downloading instead..."
echo "Unable to successfully run 'cfssl' from ${PATH}; downloading instead..."
kernel=$(uname -s)
case "${kernel}" in
Linux)