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.
This commit is contained in:
Jose Diaz-Gonzalez
2023-07-01 03:48:45 -04:00
parent dac566e75e
commit ef25a9b0d8
20 changed files with 30 additions and 30 deletions

View File

@@ -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"
}

View File

@@ -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

View File

@@ -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
```

View File

@@ -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")

2
dokku
View File

@@ -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"
)

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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

View File

@@ -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

View File

@@ -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/(?<!\\)'\''//g' | sed 's/\\'\''/'\''/g' | sed 's/^\///g')"
is_valid_app_name "$APP"
! 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"
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

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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")

View File

@@ -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
}

View File

@@ -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

View File

@@ -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

View File

@@ -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"