Skip to content

Commit

Permalink
Improving syntax for bash scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
rlenferink committed Jan 18, 2019
1 parent 31e4ece commit a5d0616
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 89 deletions.
2 changes: 1 addition & 1 deletion hack/gen-swagger-doc/gen-swagger-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ top_level_models=$(grep '&[A-Za-z]*{},' /register.go | sed 's/.*&//;s/{},//')
# check if the top level models exist in the definitions.adoc. If they exist,
# their name will be <version>.<model_name>
VERSION="${1#*_}"
for m in $top_level_models
for m in ${top_level_models}
do
if grep -xq "=== ${VERSION}.$m" ./definitions.adoc
then
Expand Down
2 changes: 1 addition & 1 deletion hack/ginkgo-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ if [[ "${KUBERNETES_PROVIDER}" == "gce" ]]; then
set_num_migs
NODE_INSTANCE_GROUP=""
for ((i=1; i<=${NUM_MIGS}; i++)); do
if [[ $i == ${NUM_MIGS} ]]; then
if [[ ${i} == ${NUM_MIGS} ]]; then
# We are assigning the same mig names as create-nodes function from cluster/gce/util.sh.
NODE_INSTANCE_GROUP="${NODE_INSTANCE_GROUP}${NODE_INSTANCE_PREFIX}-group"
else
Expand Down
2 changes: 1 addition & 1 deletion hack/jenkins/benchmark-dockerized.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ set -o xtrace

retry() {
for i in {1..5}; do
"$@" && return 0 || sleep $i
"$@" && return 0 || sleep "${i}"
done
"$@"
}
Expand Down
2 changes: 1 addition & 1 deletion hack/jenkins/test-dockerized.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ set -o xtrace

retry() {
for i in {1..5}; do
"$@" && return 0 || sleep $i
"$@" && return 0 || sleep "${i}"
done
"$@"
}
Expand Down
6 changes: 3 additions & 3 deletions hack/lib/etcd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ 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
if [[ $(kube::etcd::version ${ETCD_VERSION}) -gt $(kube::etcd::version ${version}) ]]; then
export PATH=${KUBE_ROOT}/third_party/etcd:$PATH
hash etcd
echo $PATH
version=$(etcd --version | head -n 1 | cut -d " " -f 3)
if [[ $(kube::etcd::version $ETCD_VERSION) -gt $(kube::etcd::version $version) ]]; then
if [[ $(kube::etcd::version ${ETCD_VERSION}) -gt $(kube::etcd::version ${version}) ]]; then
kube::log::usage "etcd version ${ETCD_VERSION} or greater required."
kube::log::info "You can use 'hack/install-etcd.sh' to install a copy in third_party/."
exit 1
Expand Down
6 changes: 3 additions & 3 deletions hack/lib/golang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,11 @@ kube::golang::build_binaries_for_platform() {

for binary in "${binaries[@]}"; do
if [[ "${binary}" =~ ".test"$ ]]; then
tests+=($binary)
tests+=(${binary})
elif kube::golang::is_statically_linked_library "${binary}"; then
statics+=($binary)
statics+=(${binary})
else
nonstatics+=($binary)
nonstatics+=(${binary})
fi
done

Expand Down
10 changes: 5 additions & 5 deletions hack/lib/logging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ kube::log::install_errexit() {
kube::log::stack() {
local stack_skip=${1:-0}
stack_skip=$((stack_skip + 1))
if [[ ${#FUNCNAME[@]} -gt $stack_skip ]]; then
if [[ ${#FUNCNAME[@]} -gt ${stack_skip} ]]; then
echo "Call stack:" >&2
local i
for ((i=1 ; i <= ${#FUNCNAME[@]} - $stack_skip ; i++))
for ((i=1 ; i <= ${#FUNCNAME[@]} - ${stack_skip} ; i++))
do
local frame_no=$((i - 1 + stack_skip))
local source_file=${BASH_SOURCE[$frame_no]}
Expand Down Expand Up @@ -90,7 +90,7 @@ kube::log::error_exit() {
echo " ${1}" >&2
}

kube::log::stack $stack_skip
kube::log::stack ${stack_skip}

echo "Exiting with status ${code}" >&2
fi
Expand Down Expand Up @@ -130,7 +130,7 @@ kube::log::usage_from_stdin() {
# Print out some info that isn't a top level status line
kube::log::info() {
local V="${V:-0}"
if [[ $KUBE_VERBOSE < $V ]]; then
if [[ ${KUBE_VERBOSE} < ${V} ]]; then
return
fi

Expand Down Expand Up @@ -158,7 +158,7 @@ kube::log::info_from_stdin() {
# Print a status line. Formatted to show up in a stream of output.
kube::log::status() {
local V="${V:-0}"
if [[ $KUBE_VERBOSE < $V ]]; then
if [[ ${KUBE_VERBOSE} < ${V} ]]; then
return
fi

Expand Down
2 changes: 1 addition & 1 deletion hack/lib/protoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function kube::protoc::format() {
function kube::protoc::diff() {
local ret=0
diff -I "gzipped FileDescriptorProto" -I "0x" -Naupr ${1} ${2} || ret=$?
if [[ $ret -ne 0 ]]; then
if [[ ${ret} -ne 0 ]]; then
echo ${3}
exit 1
fi
Expand Down
26 changes: 13 additions & 13 deletions hack/local-up-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function guess_built_binary_path {
GO_OUT=${GO_OUT:-}
while getopts "ho:O" OPTION
do
case $OPTION in
case ${OPTION} in
o)
echo "skipping build"
GO_OUT="$OPTARG"
Expand Down Expand Up @@ -263,20 +263,20 @@ function test_apiserver_off {
# For the common local scenario, fail fast if server is already running.
# this can happen if you run local-up-cluster.sh twice and kill etcd in between.
if [[ "${API_PORT}" -gt "0" ]]; then
curl --silent -g $API_HOST:$API_PORT
curl --silent -g ${API_HOST}:${API_PORT}
if [ ! $? -eq 0 ]; then
echo "API SERVER insecure port is free, proceeding..."
else
echo "ERROR starting API SERVER, exiting. Some process on $API_HOST is serving already on $API_PORT"
echo "ERROR starting API SERVER, exiting. Some process on ${API_HOST} is serving already on ${API_PORT}"
exit 1
fi
fi

curl --silent -k -g $API_HOST:$API_SECURE_PORT
curl --silent -k -g ${API_HOST}:${API_SECURE_PORT}
if [ ! $? -eq 0 ]; then
echo "API SERVER secure port is free, proceeding..."
else
echo "ERROR starting API SERVER, exiting. Some process on $API_HOST is serving already on $API_SECURE_PORT"
echo "ERROR starting API SERVER, exiting. Some process on ${API_HOST} is serving already on ${API_SECURE_PORT}"
exit 1
fi
}
Expand Down Expand Up @@ -335,9 +335,9 @@ function detect_binary {

cleanup_dockerized_kubelet()
{
if [[ -e $KUBELET_CIDFILE ]]; then
docker kill $(<$KUBELET_CIDFILE) > /dev/null
rm -f $KUBELET_CIDFILE
if [[ -e ${KUBELET_CIDFILE} ]]; then
docker kill $(<${KUBELET_CIDFILE}) > /dev/null
rm -f ${KUBELET_CIDFILE}

# Save the docker logs
if [[ -f /var/log/docker.log ]]; then
Expand Down Expand Up @@ -841,7 +841,7 @@ function start_kubelet {
--pid=host \
--privileged=true \
-i \
--cidfile=$KUBELET_CIDFILE \
--cidfile=${KUBELET_CIDFILE} \
"${KUBELET_IMAGE}" \
/kubelet "${all_kubelet_flags[@]}" >"${KUBELET_LOG}" 2>&1 &
# Get PID of kubelet container.
Expand All @@ -858,7 +858,7 @@ function start_kubelet {
done
fi
# Quick check that kubelet is running.
if [ -n "$KUBELET_PID" ] && ps -p $KUBELET_PID > /dev/null; then
if [ -n "$KUBELET_PID" ] && ps -p ${KUBELET_PID} > /dev/null; then
echo "kubelet ( $KUBELET_PID ) is running."
else
cat ${KUBELET_LOG} ; exit 1
Expand All @@ -882,7 +882,7 @@ EOF
# foo: true
# bar: false
for gate in $(echo ${FEATURE_GATES} | tr ',' ' '); do
echo $gate | ${SED} -e 's/\(.*\)=\(.*\)/ \1: \2/'
echo ${gate} | ${SED} -e 's/\(.*\)=\(.*\)/ \1: \2/'
done
fi >>/tmp/kube-proxy.yaml

Expand Down Expand Up @@ -953,9 +953,9 @@ function create_storage_class {
CLASS_FILE=${KUBE_ROOT}/cluster/addons/storage-class/${CLOUD_PROVIDER}/default.yaml
fi

if [ -e $CLASS_FILE ]; then
if [ -e ${CLASS_FILE} ]; then
echo "Create default storage class for $CLOUD_PROVIDER"
${KUBECTL} --kubeconfig="${CERT_DIR}/admin.kubeconfig" create -f $CLASS_FILE
${KUBECTL} --kubeconfig="${CERT_DIR}/admin.kubeconfig" create -f ${CLASS_FILE}
else
echo "No storage class available for $CLOUD_PROVIDER."
fi
Expand Down
12 changes: 6 additions & 6 deletions hack/make-rules/make-help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ CMD_FLAG=false
PLUGIN_CMD_FLAG=false

echo "--------------------------------------------------------------------------------"
for tar in $ALL_TARGETS; do
for cmdtar in $CMD_TARGETS; do
if [ $tar = $cmdtar ]; then
if [ $CMD_FLAG = true ]; then
for tar in ${ALL_TARGETS}; do
for cmdtar in ${CMD_TARGETS}; do
if [ ${tar} = ${cmdtar} ]; then
if [ ${CMD_FLAG} = true ]; then
continue 2;
fi

echo -e "${red}${CMD_TARGETS}${reset}"
make -C "${KUBE_ROOT}" $tar PRINT_HELP=y
make -C "${KUBE_ROOT}" ${tar} PRINT_HELP=y
echo "---------------------------------------------------------------------------------"

CMD_FLAG=true
Expand All @@ -45,6 +45,6 @@ for tar in $ALL_TARGETS; do
done

echo -e "${red}${tar}${reset}"
make -C "${KUBE_ROOT}" $tar PRINT_HELP=y
make -C "${KUBE_ROOT}" ${tar} PRINT_HELP=y
echo "---------------------------------------------------------------------------------"
done
Loading

0 comments on commit a5d0616

Please sign in to comment.