From 208eed8048f661873c46bd63f1397ceca7140805 Mon Sep 17 00:00:00 2001 From: Christian Hennevogl Date: Mon, 18 Dec 2023 10:58:13 +0100 Subject: [PATCH] fix(dc-ops): ensure proper quoting in script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Quote variables in `dirname` to prevent word splitting - Use quotes around `$LINE` in `grep` to handle spaces - Quote `cd` paths to handle directories with spaces - Quote `docker compose` file argument to handle file names with spaces 🤖 --- dc-ops | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dc-ops b/dc-ops index 6e642dd..e2e0f24 100755 --- a/dc-ops +++ b/dc-ops @@ -9,27 +9,27 @@ h1() { echo "* $*"; } msg() { echo "$*"; } -BASEDIR=$(dirname $0) +BASEDIR=$(dirname "$0") # use list from file or passed parameters -STACKLIST=$(cat $BASEDIR/stacklist 2>/dev/null) +STACKLIST=$(cat "$BASEDIR/stacklist" 2>/dev/null) [[ $# -gt 0 ]] && STACKLIST=$* # iterate list for LINE in $STACKLIST; do - grep -q "^[[:space:]]*#" <<<$LINE && continue # skip comments + grep -q "^[[:space:]]*#" <<<"$LINE" && continue # skip comments # determine if passed a directory or a file STACKDIR=$LINE if [[ -f $LINE ]]; then - STACKDIR=$(dirname $LINE) + STACKDIR=$(dirname "$LINE") COMPOSEFILE=$LINE fi h1 "processing $STACKDIR" # skip if directroy not found - cd $STACKDIR || continue + cd "$STACKDIR" || continue # fetch from repo and check for new commits git fetch --quiet @@ -40,5 +40,5 @@ for LINE in $STACKLIST; do # pull new commits and run docker compose git pull - docker compose --file ${COMPOSEFILE:=docker-compose.yml} up --build --detach --remove-orphans + docker compose --file "${COMPOSEFILE:=docker-compose.yml}" up --build --detach --remove-orphans done -- 2.45.2