From 9d5f0dbb0bad75fc4e9e8ccd14c61a35aae71db6 Mon Sep 17 00:00:00 2001 From: solidnerd Date: Fri, 23 Nov 2018 21:28:10 +0100 Subject: [PATCH] Fix various shellcheck warnings and errors Signed-off-by: solidnerd --- assets/build/install.sh | 14 +++++++------- entrypoint.sh | 10 +++++++--- hooks/build | 4 ++-- kubernetes/deploy.sh | 4 +++- kubernetes/teardown.sh | 4 +++- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/assets/build/install.sh b/assets/build/install.sh index 2216a698..bd0e1124 100755 --- a/assets/build/install.sh +++ b/assets/build/install.sh @@ -27,8 +27,8 @@ BUILD_DEPENDENCIES="gcc g++ make patch pkg-config cmake paxctl \ ## Execute a command as GITLAB_USER exec_as_git() { - if [[ $(whoami) == ${GITLAB_USER} ]]; then - $@ + if [[ $(whoami) == "${GITLAB_USER}" ]]; then + "$@" else sudo -HEu ${GITLAB_USER} "$@" fi @@ -42,9 +42,9 @@ DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y ${BUIL # Applying the mark late here does make the build usable on PaX kernels, but # still the build itself must be executed on a non-PaX kernel. It's done here # only for simplicity. -paxctl -Cm `which ruby${RUBY_VERSION}` +paxctl -Cm "$(command -v ruby${RUBY_VERSION})" # https://en.wikibooks.org/wiki/Grsecurity/Application-specific_Settings#Node.js -paxctl -Cm `which nodejs` +paxctl -Cm "$(command -v nodejs)" # remove the host keys generated during openssh-server installation rm -rf /etc/ssh/ssh_host_*_key /etc/ssh/ssh_host_*_key.pub @@ -134,8 +134,8 @@ rm -rf ${GITLAB_GITALY_BUILD_DIR} rm -rf ${GITLAB_BUILD_DIR}/go${GOLANG_VERSION}.linux-amd64.tar.gz ${GOROOT} # Fix for rebase in forks -echo "Linking $(which gitaly-ssh) to /" -ln -s $(which gitaly-ssh) / +echo "Linking $(command -v gitaly-ssh) to /" +ln -s "$(command -v gitaly-ssh)" / # remove HSTS config from the default headers, we configure it in nginx exec_as_git sed -i "/headers\['Strict-Transport-Security'\]/d" ${GITLAB_INSTALL_DIR}/app/controllers/application_controller.rb @@ -151,7 +151,7 @@ if [[ -d ${GEM_CACHE_DIR} ]]; then chown -R ${GITLAB_USER}: ${GITLAB_INSTALL_DIR}/vendor/cache fi -exec_as_git bundle install -j$(nproc) --deployment --without development test aws +exec_as_git bundle install -j"$(nproc)" --deployment --without development test aws # make sure everything in ${GITLAB_HOME} is owned by ${GITLAB_USER} user chown -R ${GITLAB_USER}: ${GITLAB_HOME} diff --git a/entrypoint.sh b/entrypoint.sh index 7773ae70..dee9f20e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,8 @@ #!/bin/bash set -e -source ${GITLAB_RUNTIME_DIR}/functions +set -o pipefail + +source "${GITLAB_RUNTIME_DIR}/functions" [[ $DEBUG == true ]] && set -x @@ -19,7 +21,9 @@ case ${1} in SUPERVISOR_PID=$! migrate_database kill -15 $SUPERVISOR_PID - ps h -p $SUPERVISOR_PID > /dev/null && wait $SUPERVISOR_PID || true + if ps h -p $SUPERVISOR_PID > /dev/null ; then + wait $SUPERVISOR_PID || true + fi rm -rf /var/run/supervisor.sock exec /usr/bin/supervisord -nc /etc/supervisor/supervisord.conf ;; @@ -31,7 +35,7 @@ case ${1} in ;; app:rake) shift 1 - execute_raketask $@ + execute_raketask "$@" ;; esac ;; diff --git a/hooks/build b/hooks/build index 0372272d..ca490f82 100644 --- a/hooks/build +++ b/hooks/build @@ -7,6 +7,6 @@ docker build \ --pull \ --cache-from=${IMAGE_NAME} \ --build-arg=BUILD_DATE="$(date +"%Y-%m-%d %H:%M:%S%:z")" \ - --build-arg=VCS_REF=$(git rev-parse --short HEAD) \ - --build-arg=VERSION=$(cat VERSION) \ + --build-arg=VCS_REF="$(git rev-parse --short HEAD)" \ + --build-arg=VERSION="$(cat VERSION)" \ -t ${IMAGE_NAME} . diff --git a/kubernetes/deploy.sh b/kubernetes/deploy.sh index 2e4982d2..315c6b16 100755 --- a/kubernetes/deploy.sh +++ b/kubernetes/deploy.sh @@ -1,6 +1,8 @@ #!/bin/bash +set -e +set -o pipefail -if ! which kubectl > /dev/null; then +if ! command -v kubectl > /dev/null; then echo "kubectl command not installed" exit 1 fi diff --git a/kubernetes/teardown.sh b/kubernetes/teardown.sh index 3ee820fb..c4b3be9e 100755 --- a/kubernetes/teardown.sh +++ b/kubernetes/teardown.sh @@ -1,6 +1,8 @@ #!/bin/bash +set -e +set -o pipefail -if ! which kubectl > /dev/null; then +if ! command -v kubectl > /dev/null; then echo "kubectl command not installed" exit 1 fi