From ef25a9b0d816c3703a710de30e5693fa3ab01708 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 1 Jul 2023 03:48:45 -0400 Subject: [PATCH] refactor: standardize on shorthand for redirecting all output to /dev/null The shorthand is more prevalent in this codebase, and is something that bash supports, so we should just use the same thing everywhere. Note that we do not use shorthand redirect in Makefile as shell parsing is a bit different in Make and the shorthand redirect doesn't seem to be properly supported, causing CI errors. --- bootstrap.sh | 2 +- contrib/dokku_client.sh | 4 ++-- docs/development/plugin-creation.md | 2 +- docs/development/plugin-triggers.md | 2 +- dokku | 2 +- plugins/20_events/install | 2 +- plugins/builder-herokuish/builder-build | 2 +- plugins/builder-herokuish/post-app-rename-setup | 2 +- plugins/common/functions | 2 +- plugins/git/functions | 8 ++++---- plugins/git/internal-functions | 6 +++--- plugins/nginx-vhosts/functions | 4 ++-- plugins/scheduler-docker-local/core-post-deploy | 2 +- plugins/scheduler-docker-local/internal-functions | 6 +++--- plugins/scheduler-docker-local/scheduler-deploy | 2 +- plugins/scheduler-docker-local/scheduler-logs-failed | 2 +- plugins/scheduler-docker-local/scheduler-stop | 2 +- tests.mk | 4 ++-- tests/ci/setup.sh | 2 +- tests/unit/test_helper.bash | 2 +- 20 files changed, 30 insertions(+), 30 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index 04e4cd8cb..d5de53341 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -28,7 +28,7 @@ ensure-environment() { echo "Preparing to install $DOKKU_TAG from $DOKKU_REPO..." fi - hostname -f >/dev/null 2>&1 || { + hostname -f &>/dev/null || { log-fail "This installation script requires that you have a hostname set for the instance. Please set a hostname for 127.0.0.1 in your /etc/hosts" } diff --git a/contrib/dokku_client.sh b/contrib/dokku_client.sh index e0b3ffd4c..590d3d0dc 100755 --- a/contrib/dokku_client.sh +++ b/contrib/dokku_client.sh @@ -49,7 +49,7 @@ fn-dokku-host() { declare DOKKU_GIT_REMOTE="$1" DOKKU_HOST="$2" if [[ -z "$DOKKU_HOST" ]]; then - if [[ -d .git ]] || git rev-parse --git-dir >/dev/null 2>&1; then + if [[ -d .git ]] || git rev-parse --git-dir &>/dev/null; then DOKKU_HOST=$(git remote -v 2>/dev/null | grep -Ei "^${DOKKU_GIT_REMOTE}\s" | head -n 1 | cut -f1 -d' ' | cut -f2 -d '@' | cut -f1 -d':' 2>/dev/null || true) fi fi @@ -109,7 +109,7 @@ main() { fi if [[ -z "$APP" ]]; then - if [[ -d .git ]] || git rev-parse --git-dir >/dev/null 2>&1; then + if [[ -d .git ]] || git rev-parse --git-dir &>/dev/null; then set +e APP=$(git remote -v 2>/dev/null | grep -Ei "^${DOKKU_GIT_REMOTE}\s" | grep -Ei "dokku@$DOKKU_REMOTE_HOST" | head -n 1 | cut -f2 -d'@' | cut -f1 -d' ' | cut -f2 -d':' 2>/dev/null) set -e diff --git a/docs/development/plugin-creation.md b/docs/development/plugin-creation.md index 6cbd9b627..edebfc649 100644 --- a/docs/development/plugin-creation.md +++ b/docs/development/plugin-creation.md @@ -103,7 +103,7 @@ if ! command -v "nginx" &>/dev/null; then fi # `which` example -if ! which nginx >/dev/null 2>&1; then +if ! which nginx &>/dev/null; then dokku_log_fail "Missing nginx, install it" fi ``` diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index 796dcae93..a141b115f 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -1715,7 +1715,7 @@ APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) dokku_log_info1 "Installing GraphicsMagick..." CMD="cat > gm && \ - dpkg -s graphicsmagick >/dev/null 2>&1 || \ + dpkg -s graphicsmagick &>/dev/null || \ (apt-get update -qq && apt-get -qq -y --no-install-recommends install graphicsmagick && apt-get clean)" CID=$(docker run $DOKKU_GLOBAL_RUN_ARGS -i -a stdin $IMAGE /bin/bash -c "$CMD") diff --git a/dokku b/dokku index 7e37af297..0a2086471 100755 --- a/dokku +++ b/dokku @@ -31,7 +31,7 @@ export DOKKU_HOST_ROOT=${DOKKU_HOST_ROOT:=$DOKKU_ROOT} export DOKKU_DISTRO DOKKU_DISTRO=$( - . /etc/os-release >/dev/null 2>&1 || true + . /etc/os-release &>/dev/null || true echo "$ID" ) diff --git a/plugins/20_events/install b/plugins/20_events/install index 003a1e89d..9a352e198 100755 --- a/plugins/20_events/install +++ b/plugins/20_events/install @@ -63,7 +63,7 @@ $DOKKU_LOGS_DIR/*.log { compress delaycompress postrotate - reload rsyslog >/dev/null 2>&1 || true + reload rsyslog &>/dev/null || true endscript create 664 syslog dokku } diff --git a/plugins/builder-herokuish/builder-build b/plugins/builder-herokuish/builder-build index 7505a992d..8ebc672bf 100755 --- a/plugins/builder-herokuish/builder-build +++ b/plugins/builder-herokuish/builder-build @@ -8,7 +8,7 @@ fn-builder-herokuish-ensure-cache() { existing_cache="$("$DOCKER_BIN" volume ls --quiet --filter label=com.dokku.app-name=test --filter label=com.dokku.builder-type=herokuish)" if [[ "$existing_cache" != "cache-$APP" ]]; then - "$DOCKER_BIN" volume rm "cache-$APP" >/dev/null 2>&1 || true + "$DOCKER_BIN" volume rm "cache-$APP" &>/dev/null || true "$DOCKER_BIN" volume create "--label=org.label-schema.schema-version=1.0" "--label=org.label-schema.vendor=dokku" "--label=com.dokku.app-name=$APP" "--label=com.dokku.builder-type=herokuish" "cache-$APP" >/dev/null fi } diff --git a/plugins/builder-herokuish/post-app-rename-setup b/plugins/builder-herokuish/post-app-rename-setup index 2c96153a8..26c5a6dbb 100755 --- a/plugins/builder-herokuish/post-app-rename-setup +++ b/plugins/builder-herokuish/post-app-rename-setup @@ -12,7 +12,7 @@ trigger-builder-herokuish-post-app-clone-setup() { local OLD_CACHE_DIR="$DOKKU_ROOT/$OLD_APP/cache" local OLD_CACHE_HOST_DIR="$DOKKU_HOST_ROOT/$OLD_APP/cache" - if [[ -d "$OLD_CACHE_DIR" ]] && ! rmdir "$OLD_CACHE_DIR" >/dev/null 2>&1; then + if [[ -d "$OLD_CACHE_DIR" ]] && ! rmdir "$OLD_CACHE_DIR" &>/dev/null; then local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$NEW_APP" "$DOCKER_BIN" container run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --rm --volume "$OLD_CACHE_HOST_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache fi diff --git a/plugins/common/functions b/plugins/common/functions index e3887fc48..f1f49bc83 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -480,7 +480,7 @@ copy_from_image() { fi TMP_FILE_COMMAND_OUTPUT=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX") - trap "rm -rf '$TMP_FILE_COMMAND_OUTPUT' >/dev/null 2>&1 || true" RETURN + trap "rm -rf '$TMP_FILE_COMMAND_OUTPUT' &>/dev/null || true" RETURN local CID=$("$DOCKER_BIN" container create "${DOCKER_CREATE_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS "$IMAGE") "$DOCKER_BIN" container cp "$CID:$SRC_FILE" "$TMP_FILE_COMMAND_OUTPUT" 2>/dev/null || true diff --git a/plugins/git/functions b/plugins/git/functions index 6773e320f..c19c8397e 100755 --- a/plugins/git/functions +++ b/plugins/git/functions @@ -20,7 +20,7 @@ git_build_app_repo() { chmod 755 "$GIT_BUILD_APP_REPO_TMP_WORK_DIR" unset GIT_DIR GIT_QUARANTINE_PATH GIT_WORK_TREE - ! plugn trigger app-exists "$APP" >/dev/null 2>&1 && plugn trigger app-maybe-create "$APP" + ! plugn trigger app-exists "$APP" &>/dev/null && plugn trigger app-maybe-create "$APP" fn-git-setup-build-dir "$APP" "$GIT_BUILD_APP_REPO_TMP_WORK_DIR" "$REV" pushd "$GIT_BUILD_APP_REPO_TMP_WORK_DIR" >/dev/null @@ -79,7 +79,7 @@ cmd-git-hook() { plugn trigger app-exists "$APP" 2>/dev/null || is_valid_app_name "$APP" DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")" - if ! git check-ref-format --branch "$DOKKU_DEPLOY_BRANCH" >/dev/null 2>&1; then + if ! git check-ref-format --branch "$DOKKU_DEPLOY_BRANCH" &>/dev/null; then echo $'\e[1G\e[K'"-----> WARNING: Invalid branch name '$DOKKU_DEPLOY_BRANCH' specified via deploy-branch setting." echo $'\e[1G\e[K'"-----> For more details, please see the man page for 'git-check-ref-format.'" return @@ -165,7 +165,7 @@ cmd-git-upload-pack() { APP="$(echo "$APP" | perl -pe 's/(?/dev/null 2>&1 && plugn trigger app-maybe-create "$APP" + ! plugn trigger app-exists "$APP" &>/dev/null && plugn trigger app-maybe-create "$APP" plugn trigger git-pre-pull "$APP" cat | git-upload-pack "$DOKKU_ROOT/$APP" @@ -180,7 +180,7 @@ cmd-git-glob() { plugn trigger app-exists "$APP" 2>/dev/null || is_valid_app_name "$APP" if [[ $1 == "git-receive-pack" && ! -d "$APP_PATH/refs" ]]; then - ! plugn trigger app-exists "$APP" >/dev/null 2>&1 && plugn trigger app-maybe-create "$APP" + ! plugn trigger app-exists "$APP" &>/dev/null && plugn trigger app-maybe-create "$APP" fn-git-create-hook "$APP" fi diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index 531eb66dd..b84d070a8 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -408,7 +408,7 @@ fn-git-clone() { fn-git-cmd "$APP_CLONE_ROOT" checkout -qq "$GIT_REF" else GIT_TERMINAL_PROMPT=0 suppress_output git clone -n --branch "$GIT_REF" "$GIT_REMOTE" "$APP_CLONE_ROOT" - if fn-git-cmd "$APP_CLONE_ROOT" show-ref --verify "refs/heads/$GIT_REF" >/dev/null 2>&1; then + if fn-git-cmd "$APP_CLONE_ROOT" show-ref --verify "refs/heads/$GIT_REF" &>/dev/null; then dokku_log_verbose "Detected branch, setting deploy-branch to $GIT_REF" fn-plugin-property-write "git" "$APP" "deploy-branch" "$GIT_REF" fi @@ -450,13 +450,13 @@ fn-git-fetch() { fi DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")" - if ! fn-git-cmd "$APP_ROOT" check-ref-format --branch "$DOKKU_DEPLOY_BRANCH" >/dev/null 2>&1; then + if ! fn-git-cmd "$APP_ROOT" check-ref-format --branch "$DOKKU_DEPLOY_BRANCH" &>/dev/null; then dokku_log_warn "Invalid branch name '$DOKKU_DEPLOY_BRANCH' specified via deploy-branch setting." dokku_log_warn "For more details, please see the man page for 'git-check-ref-format.'" return fi - fn-git-cmd "$APP_ROOT" remote rm remote >/dev/null 2>&1 || true + fn-git-cmd "$APP_ROOT" remote rm remote &>/dev/null || true fn-git-cmd "$APP_ROOT" remote add --mirror=fetch --no-tags remote "$GIT_REMOTE" if [[ -z "$GIT_REF" ]]; then GIT_TERMINAL_PROMPT=0 fn-git-cmd "$APP_ROOT" fetch --update-head-ok remote "$DOKKU_DEPLOY_BRANCH" diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index 299e84aab..1e3d2f1e2 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -98,7 +98,7 @@ validate_nginx() { fi set +e - sudo "$NGINX_LOCATION" -t >/dev/null 2>&1 + sudo "$NGINX_LOCATION" -t &>/dev/null EXIT_CODE=$? set -e if [[ "$EXIT_CODE" -eq "0" ]]; then @@ -115,7 +115,7 @@ validate_nginx() { fi set +e - sudo "$NGINX_LOCATION" -t >/dev/null 2>&1 + sudo "$NGINX_LOCATION" -t &>/dev/null EXIT_CODE=$? set -e if [[ "$EXIT_CODE" -eq "0" ]]; then diff --git a/plugins/scheduler-docker-local/core-post-deploy b/plugins/scheduler-docker-local/core-post-deploy index 8f7924ff1..bd02b2d44 100755 --- a/plugins/scheduler-docker-local/core-post-deploy +++ b/plugins/scheduler-docker-local/core-post-deploy @@ -48,7 +48,7 @@ trigger-scheduler-docker-local-core-post-deploy() { if [[ "$PREVIOUS_CONTAINER_STATUS" != "dead" ]]; then local CONTAINER_DATE_NAME="$NAME.$(date +%s)" dokku_log_verbose_quiet "Renaming container ($cid) ${NAME} to $CONTAINER_DATE_NAME" - "$DOCKER_BIN" container rename "$NAME" "$CONTAINER_DATE_NAME" >/dev/null 2>&1 || dokku_log_warn "Unable to rename container" + "$DOCKER_BIN" container rename "$NAME" "$CONTAINER_DATE_NAME" &>/dev/null || dokku_log_warn "Unable to rename container" fi done fi diff --git a/plugins/scheduler-docker-local/internal-functions b/plugins/scheduler-docker-local/internal-functions index de854b4f9..a8985eef2 100755 --- a/plugins/scheduler-docker-local/internal-functions +++ b/plugins/scheduler-docker-local/internal-functions @@ -81,7 +81,7 @@ fn-scheduler-docker-local-retire-container() { [[ $DOKKU_DOCKER_STOP_TIMEOUT ]] && DOCKER_STOP_TIME_ARG="--time=${DOKKU_DOCKER_STOP_TIMEOUT}" if [[ "$STATE" == "restarting" ]]; then - "$DOCKER_BIN" container update --restart=no "$CID" >/dev/null 2>&1 + "$DOCKER_BIN" container update --restart=no "$CID" &>/dev/null fi if [[ "$STATE" != "dead" ]] && [[ "$STATE" != "exited" ]]; then @@ -142,8 +142,8 @@ fn-scheduler-docker-local-retire-containers() { continue fi - "$DOCKER_BIN" container rm --force "$CID" >/dev/null 2>&1 || true - if "$DOCKER_BIN" container inspect "${CID}" >/dev/null 2>&1; then + "$DOCKER_BIN" container rm --force "$CID" &>/dev/null || true + if "$DOCKER_BIN" container inspect "${CID}" &>/dev/null; then dokku_log_warn "Container ${CID} still running" continue fi diff --git a/plugins/scheduler-docker-local/scheduler-deploy b/plugins/scheduler-docker-local/scheduler-deploy index 3f742a01b..0372bf139 100755 --- a/plugins/scheduler-docker-local/scheduler-deploy +++ b/plugins/scheduler-docker-local/scheduler-deploy @@ -79,7 +79,7 @@ trigger-scheduler-docker-local-scheduler-deploy() { trap '' INT HUP sleep "$DOKKU_WAIT_TO_RETIRE" for oldid in $oldids; do - if ! docker container inspect "$oldid" >/dev/null 2>&1; then + if ! docker container inspect "$oldid" &>/dev/null; then continue fi # Disable the container restart policy diff --git a/plugins/scheduler-docker-local/scheduler-logs-failed b/plugins/scheduler-docker-local/scheduler-logs-failed index ed0d45349..d3cc93346 100755 --- a/plugins/scheduler-docker-local/scheduler-logs-failed +++ b/plugins/scheduler-docker-local/scheduler-logs-failed @@ -24,7 +24,7 @@ trigger-scheduler-docker-local-scheduler-logs-failed() { while read -r LINE || [[ -n "$LINE" ]]; do CID="$(echo "$LINE" | cut -d ' ' -f1)" PREFIX="$(echo "$LINE" | cut -d ' ' -f2)" - if "$DOCKER_BIN" container inspect "${CID}" >/dev/null 2>&1; then + if "$DOCKER_BIN" container inspect "${CID}" &>/dev/null; then RUNNING_CONTAINERS+=("$CID") else DEAD_CONTAINERS+=("$CID") diff --git a/plugins/scheduler-docker-local/scheduler-stop b/plugins/scheduler-docker-local/scheduler-stop index a6f2bafd9..88dd43091 100755 --- a/plugins/scheduler-docker-local/scheduler-stop +++ b/plugins/scheduler-docker-local/scheduler-stop @@ -33,7 +33,7 @@ trigger-scheduler-docker-local-scheduler-stop() { plugn trigger scheduler-register-retired "$APP" "$CID" done - "$DOCKER_BIN" container rm --force $DOKKU_APP_CIDS >/dev/null 2>&1 || true + "$DOCKER_BIN" container rm --force $DOKKU_APP_CIDS &>/dev/null || true fi fi } diff --git a/tests.mk b/tests.mk index a1cd915d3..2b57677e5 100644 --- a/tests.mk +++ b/tests.mk @@ -13,7 +13,7 @@ else endif shellcheck: -ifneq ($(shell shellcheck --version >/dev/null 2>&1 ; echo $$?),0) +ifneq ($(shell shellcheck --version >/dev/null 2>&1; echo $$?),0) ifeq ($(SYSTEM),Darwin) brew install shellcheck else @@ -22,7 +22,7 @@ endif endif shfmt: -ifneq ($(shell shfmt --version >/dev/null 2>&1 ; echo $$?),0) +ifneq ($(shell shfmt --version >/dev/null 2>&1; echo $$?),0) ifeq ($(shfmt),Darwin) brew install shfmt else diff --git a/tests/ci/setup.sh b/tests/ci/setup.sh index 46f2a490e..31bdfbaff 100755 --- a/tests/ci/setup.sh +++ b/tests/ci/setup.sh @@ -136,7 +136,7 @@ check_container() { while [ $cnt -lt 100 ]; do echo "$(date) [count: $cnt]: waiting for dokku startup" is_up=$( - docker exec dokku ps -ef | grep "/usr/sbin/sshd -D" >/dev/null 2>&1 + docker exec dokku ps -ef | grep "/usr/sbin/sshd -D" &>/dev/null echo $? ) echo "" && docker logs dokku diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index c3c242807..657567b01 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -344,7 +344,7 @@ setup_test_tls() { local TLS_TYPE="$1" local TLS="/home/dokku/$TEST_APP/tls" - if ! dokku apps:exists "$TEST_APP" >/dev/null 2>&1; then + if ! dokku apps:exists "$TEST_APP" &>/dev/null; then create_app "$TEST_APP" fi mkdir -p "$TLS"