From b18bc2ea79462faa8ca1aaaff5a69a72b735b9bd Mon Sep 17 00:00:00 2001 From: Roy Lenferink Date: Mon, 21 Jan 2019 23:11:58 +0100 Subject: [PATCH] Improved some more bash script variable definitions --- hack/lib/etcd.sh | 4 ++-- hack/lib/golang.sh | 22 +++++++++++----------- hack/lib/init.sh | 18 +++++++++--------- hack/lib/logging.sh | 26 +++++++++++++------------- hack/lib/swagger.sh | 14 +++++++------- hack/lib/test.sh | 4 ++-- hack/lib/util.sh | 10 +++++----- hack/local-up-cluster.sh | 4 ++-- hack/make-rules/test-e2e-node.sh | 2 +- hack/make-rules/test.sh | 24 ++++++++++++------------ hack/make-rules/update.sh | 10 +++++----- hack/make-rules/verify.sh | 6 +++--- 12 files changed, 72 insertions(+), 72 deletions(-) diff --git a/hack/lib/etcd.sh b/hack/lib/etcd.sh index dc8d246e16..e807e199e9 100755 --- a/hack/lib/etcd.sh +++ b/hack/lib/etcd.sh @@ -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." diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh index 9b5ba67474..41004ced12 100755 --- a/hack/lib/golang.sh +++ b/hack/lib/golang.sh @@ -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 ` 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). diff --git a/hack/lib/init.sh b/hack/lib/init.sh index 64849d3af4..f0b520fb1b 100755 --- a/hack/lib/init.sh +++ b/hack/lib/init.sh @@ -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}" } diff --git a/hack/lib/logging.sh b/hack/lib/logging.sh index c2e193e5a3..7d78478ff3 100644 --- a/hack/lib/logging.sh +++ b/hack/lib/logging.sh @@ -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 } diff --git a/hack/lib/swagger.sh b/hack/lib/swagger.sh index b4a210dac1..6865ad35b4 100644 --- a/hack/lib/swagger.sh +++ b/hack/lib/swagger.sh @@ -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" < "${TMPFILE}" + echo "package ${group_version##*/}" >> "${TMPFILE}" + cat >> "${TMPFILE}" <> "$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" } diff --git a/hack/lib/test.sh b/hack/lib/test.sh index 085eabd739..87beca114e 100644 --- a/hack/lib/test.sh +++ b/hack/lib/test.sh @@ -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}" } diff --git a/hack/lib/util.sh b/hack/lib/util.sh index 762ae5d154..af9a576a4a 100755 --- a/hack/lib/util.sh +++ b/hack/lib/util.sh @@ -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) diff --git a/hack/local-up-cluster.sh b/hack/local-up-cluster.sh index 2175774c23..c3b83ae96d 100755 --- a/hack/local-up-cluster.sh +++ b/hack/local-up-cluster.sh @@ -965,9 +965,9 @@ create_csi_crd() { echo "create_csi_crd $1" YAML_FILE=${KUBE_ROOT}/cluster/addons/storage-crds/$1.yaml - if [ -e $YAML_FILE ]; then + if [ -e "${YAML_FILE}" ]; then echo "Create $1 crd" - ${KUBECTL} --kubeconfig="${CERT_DIR}/admin.kubeconfig" create -f $YAML_FILE + ${KUBECTL} --kubeconfig="${CERT_DIR}/admin.kubeconfig" create -f ${YAML_FILE} else echo "No $1 available." fi diff --git a/hack/make-rules/test-e2e-node.sh b/hack/make-rules/test-e2e-node.sh index 3831a6f482..3b6a2a2e15 100755 --- a/hack/make-rules/test-e2e-node.sh +++ b/hack/make-rules/test-e2e-node.sh @@ -169,7 +169,7 @@ else # Test using the host the script was run on # Provided for backwards compatibility go run test/e2e_node/runner/local/run_local.go \ - --system-spec-name="$system_spec_name" --ginkgo-flags="$ginkgoflags" \ + --system-spec-name="${system_spec_name}" --ginkgo-flags="${ginkgoflags}" \ --test-flags="--container-runtime=${runtime} \ --alsologtostderr --v 4 --report-dir=${artifacts} --node-name $(hostname) \ ${test_args}" --build-dependencies=true 2>&1 | tee -i "${artifacts}/build-log.txt" diff --git a/hack/make-rules/test.sh b/hack/make-rules/test.sh index 1bd113b318..4d380c3409 100755 --- a/hack/make-rules/test.sh +++ b/hack/make-rules/test.sh @@ -149,7 +149,7 @@ while getopts "hp:i:" opt ; do exit 0 ;; p) - PARALLEL="$OPTARG" + PARALLEL="${OPTARG}" if ! isnum "${PARALLEL}" || [[ "${PARALLEL}" -le 0 ]]; then kube::log::usage "'$0': argument to -p must be numeric and greater than 0" kube::test::usage @@ -166,7 +166,7 @@ while getopts "hp:i:" opt ; do exit 1 ;; :) - kube::log::usage "Option -$OPTARG " + kube::log::usage "Option -${OPTARG} " kube::test::usage exit 1 ;; @@ -223,15 +223,15 @@ verifyAndSuggestPackagePath() { local original_package_path="$3" local suggestion_package_path="$4" - if ! [ -d "$specified_package_path" ]; then + if ! [ -d "${specified_package_path}" ]; then # Because k8s sets a localized $GOPATH for testing, seeing the actual # directory can be confusing. Instead, just show $GOPATH if it exists in the # $specified_package_path. - local printable_package_path=$(echo "$specified_package_path" | sed "s|$GOPATH|\$GOPATH|") - kube::log::error "specified test path '$printable_package_path' does not exist" + local printable_package_path=$(echo "${specified_package_path}" | sed "s|${GOPATH}|\${GOPATH}|") + kube::log::error "specified test path '${printable_package_path}' does not exist" - if [ -d "$alternative_package_path" ]; then - kube::log::info "try changing \"$original_package_path\" to \"$suggestion_package_path\"" + if [ -d "${alternative_package_path}" ]; then + kube::log::info "try changing \"${original_package_path}\" to \"${suggestion_package_path}\"" fi exit 1 fi @@ -241,13 +241,13 @@ verifyPathsToPackagesUnderTest() { local packages_under_test=($@) for package_path in "${packages_under_test[@]}"; do - local local_package_path="$package_path" - local go_package_path="$GOPATH/src/$package_path" + local local_package_path="${package_path}" + local go_package_path="${GOPATH}/src/${package_path}" if [[ "${package_path:0:2}" == "./" ]] ; then - verifyAndSuggestPackagePath "$local_package_path" "$go_package_path" "$package_path" "${package_path:2}" + verifyAndSuggestPackagePath "${local_package_path}" "${go_package_path}" "${package_path}" "${package_path:2}" else - verifyAndSuggestPackagePath "$go_package_path" "$local_package_path" "$package_path" "./$package_path" + verifyAndSuggestPackagePath "${go_package_path}" "${local_package_path}" "${package_path}" "./${package_path}" fi done } @@ -317,7 +317,7 @@ runTests() { # https://github.com/golang/go/issues/16540 cover_ignore_dirs="vendor/k8s.io/code-generator/cmd/generator|vendor/k8s.io/client-go/1.4/rest" for path in $(echo ${cover_ignore_dirs} | sed 's/|/ /g'); do - echo -e "skipped\tk8s.io/kubernetes/$path" + echo -e "skipped\tk8s.io/kubernetes/${path}" done printf "%s\n" "${@}" \ diff --git a/hack/make-rules/update.sh b/hack/make-rules/update.sh index ebcfe43a98..035af3a15a 100755 --- a/hack/make-rules/update.sh +++ b/hack/make-rules/update.sh @@ -61,17 +61,17 @@ BASH_TARGETS=" update-bazel" for t in ${BASH_TARGETS}; do - echo -e "${color_yellow}Running $t${color_norm}" + echo -e "${color_yellow}Running ${t}${color_norm}" if ${SILENT} ; then - if ! bash "${KUBE_ROOT}/hack/$t.sh" 1> /dev/null; then - echo -e "${color_red}Running $t FAILED${color_norm}" + if ! bash "${KUBE_ROOT}/hack/${t}.sh" 1> /dev/null; then + echo -e "${color_red}Running ${t} FAILED${color_norm}" if ! ${ALL}; then exit 1 fi fi else - if ! bash "${KUBE_ROOT}/hack/$t.sh"; then - echo -e "${color_red}Running $t FAILED${color_norm}" + if ! bash "${KUBE_ROOT}/hack/${t}.sh"; then + echo -e "${color_red}Running ${t} FAILED${color_norm}" if ! ${ALL}; then exit 1 fi diff --git a/hack/make-rules/verify.sh b/hack/make-rules/verify.sh index 7ee6f3f616..3eb6ff7c9f 100755 --- a/hack/make-rules/verify.sh +++ b/hack/make-rules/verify.sh @@ -86,7 +86,7 @@ QUICK_CHECKS=$(ls ${QUICK_PATTERNS[@]/#/${KUBE_ROOT}\/hack\/} 2>/dev/null || tru function is-excluded { for e in ${EXCLUDED_CHECKS[@]}; do - if [[ $1 -ef "$e" ]]; then + if [[ $1 -ef "${e}" ]]; then return fi done @@ -95,7 +95,7 @@ function is-excluded { function is-quick { for e in ${QUICK_CHECKS[@]}; do - if [[ $1 -ef "$e" ]]; then + if [[ $1 -ef "${e}" ]]; then return fi done @@ -106,7 +106,7 @@ function is-explicitly-chosen { local name="${1#verify-}" name="${name%.*}" for e in ${WHAT}; do - if [[ $e == "$name" ]]; then + if [[ "${e}" == "${name}" ]]; then return fi done