From 0f3e66084251a13e759d9c48116d568bdade68b9 Mon Sep 17 00:00:00 2001
From: Jan-Tarek Butt <tarek@ring0.de>
Date: Sat, 24 Sep 2016 17:34:14 +0200
Subject: [PATCH] scripts: improve variable escaping

---
 scripts/patch.sh          |  6 +++---
 scripts/sha512sum.sh      |  2 +-
 scripts/update-patches.sh |  8 ++++----
 scripts/update.sh         | 12 ++++++------
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/scripts/patch.sh b/scripts/patch.sh
index 2b0aa29e0..7dfb30613 100755
--- a/scripts/patch.sh
+++ b/scripts/patch.sh
@@ -15,14 +15,14 @@ trap 'rm -rf "$PATCHDIR"' EXIT
 for module in $GLUON_MODULES; do
 	echo "--- Patching module '$module' ---"
 
-	git clone -s -b base --single-branch "$GLUONDIR"/$module "$PATCHDIR" 2>/dev/null
+	git clone -s -b base --single-branch "$GLUONDIR/$module" "$PATCHDIR" 2>/dev/null
 
 	cd "$PATCHDIR"
-	for patch in "$GLUONDIR"/patches/$module/*.patch; do
+	for patch in "$GLUONDIR/patches/$module"/*.patch; do
 		git -c user.name='Gluon Patch Manager' -c user.email='gluon@void.example.com' -c commit.gpgsign=false am --whitespace=nowarn --committer-date-is-author-date "$patch"
 	done
 
-	cd "$GLUONDIR"/$module
+	cd "$GLUONDIR/$module"
 	git fetch "$PATCHDIR" 2>/dev/null
 	git checkout -B patched FETCH_HEAD
 	git submodule update --init --recursive
diff --git a/scripts/sha512sum.sh b/scripts/sha512sum.sh
index 921e5c6c6..de08b0b8b 100755
--- a/scripts/sha512sum.sh
+++ b/scripts/sha512sum.sh
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 check_command() {
-	which $1 >/dev/null 2>&1
+	which "$1" >/dev/null 2>&1
 }
 
 if check_command sha512sum; then
diff --git a/scripts/update-patches.sh b/scripts/update-patches.sh
index f8b92025f..62d5bf78b 100755
--- a/scripts/update-patches.sh
+++ b/scripts/update-patches.sh
@@ -8,14 +8,14 @@ shopt -s nullglob
 for module in $GLUON_MODULES; do
 	echo "--- Updating patches for module '$module' ---"
 
-	rm -f "$GLUONDIR"/patches/$module/*.patch
-	mkdir -p "$GLUONDIR"/patches/$module
+	rm -f "$GLUONDIR"/patches/"$module"/*.patch
+	mkdir -p "$GLUONDIR"/patches/"$module"
 
-	cd "$GLUONDIR"/$module
+	cd "$GLUONDIR"/"$module"
 
 	n=0
 	for commit in $(git rev-list --reverse --no-merges base..patched); do
 		let n=n+1
-		git show --pretty=format:'From: %an <%ae>%nDate: %aD%nSubject: %B' --no-renames $commit > "$GLUONDIR"/patches/$module/"$(printf '%04u' $n)-$(git show -s --pretty=format:%f $commit).patch"
+		git show --pretty=format:'From: %an <%ae>%nDate: %aD%nSubject: %B' --no-renames "$commit" > "$GLUONDIR/patches/$module/$(printf '%04u' $n)-$(git show -s --pretty=format:%f "$commit").patch"
 	done
 done
diff --git a/scripts/update.sh b/scripts/update.sh
index 1c750f693..ae3368cb8 100755
--- a/scripts/update.sh
+++ b/scripts/update.sh
@@ -6,17 +6,17 @@ set -e
 
 for module in $GLUON_MODULES; do
 	echo "--- Updating module '$module' ---"
-	var=$(echo $module | tr '[:lower:]/' '[:upper:]_')
+	var=$(echo "$module" | tr '[:lower:]/' '[:upper:]_')
 	eval repo=\${${var}_REPO}
 	eval branch=\${${var}_BRANCH}
 	eval commit=\${${var}_COMMIT}
 
-	mkdir -p "$GLUONDIR"/$module
-	cd "$GLUONDIR"/$module
+	mkdir -p "$GLUONDIR/$module"
+	cd "$GLUONDIR/$module"
 	git init
 
-	if ! git branch -f base $commit 2>/dev/null; then
-		git fetch $repo $branch
-		git branch -f base $commit 2>/dev/null
+	if ! git branch -f base "$commit" 2>/dev/null; then
+		git fetch "$repo" "$branch"
+		git branch -f base "$commit" 2>/dev/null
 	fi
 done
-- 
GitLab