[LEDE-DEV] [patch master 01/15 v2] Double quote to prevent globbing and word splitting

Jan-Tarek Butt tarek at ring0.de
Sat Oct 1 07:07:17 PDT 2016


---
 scripts/arm-magic.sh             | 11 ++++++-----
 scripts/clean-package.sh         |  2 +-
 scripts/combined-ext-image.sh    | 10 +++++-----
 scripts/combined-image.sh        |  2 +-
 scripts/deptest.sh               | 12 ++++++------
 scripts/ext-toolchain.sh         | 15 ++++++++-------
 scripts/flashing/flash.sh        | 10 +++++-----
 scripts/gen-dependencies.sh      | 14 +++++++-------
 scripts/get_source_date_epoch.sh |  2 +-
 scripts/getver.sh                | 10 +++++-----
 scripts/ipkg-make-index.sh       | 14 +++++++-------
 scripts/mkits.sh                 |  6 +++---
 scripts/om-fwupgradecfg-gen.sh   | 16 ++++++++--------
 scripts/patch-kernel.sh          |  6 +++---
 scripts/relink-lib.sh            |  4 ++--
 scripts/rstrip.sh                | 12 ++++++------
 scripts/strip-kmod.sh            |  7 ++++---
 scripts/sysupgrade-tar.sh        |  2 +-
 scripts/ubinize-image.sh         |  8 ++++----
 19 files changed, 83 insertions(+), 80 deletions(-)

diff --git a/scripts/arm-magic.sh b/scripts/arm-magic.sh
index 29ec88a..d5c49b1 100755
--- a/scripts/arm-magic.sh
+++ b/scripts/arm-magic.sh
@@ -24,19 +24,20 @@
 # list of supported boards, in "boardname machtypeid" format
 for board in "avila 526" "gateway7001 731" "nslu2 597" "nas100d 865" "wg302v1 889" "wg302v2 890" "pronghorn 928" "pronghornmetro 1040" "compex 1273" "wrt300nv2 1077" "loft 849" "dsmg600 964" "fsg3 1091" "ap1000 1543" "tw2662 1658" "tw5334 1664" "ixdpg425 604" "cambria 1468" "sidewinder 1041" "ap42x 4418"
 do
+  # shellcheck disable=SC2086
   set -- $board
-  hexid=$(printf %x\\n $2)
+  hexid=$(printf %x\\n "$2")
   if [ "$2" -lt "256" ]; then
     # we have a low machtypeid, we just need a "mov" (e3a)
-    printf "\xe3\xa0\x10\x$hexid" > $BIN_DIR/$IMG_PREFIX-$1-zImage
+    printf "\xe3\xa0\x10\x$hexid" > "$BIN_DIR/$IMG_PREFIX-$1-zImage"
   else
     # we have a high machtypeid, we need a "mov" (e3a) and an "orr" (e38)
     if [ "$2" -lt "4096" ]; then
-      printf "\xe3\xa0\x10\x$(echo $hexid|cut -b "2 3")\xe3\x81\x1c\x$(echo $hexid|cut -b 1)" > $BIN_DIR/$IMG_PREFIX-$1-zImage
+      printf "\xe3\xa0\x10\x$(echo "$hexid" | cut -b "2 3")\xe3\x81\x1c\x$(echo "$hexid" | cut -b 1)" > "$BIN_DIR/$IMG_PREFIX-$1-zImage"
     else
-      printf "\xe3\xa0\x10\x$(echo $hexid|cut -b "3 4")\xe3\x81\x1c\x$(echo $hexid|cut -b "1 2")" > $BIN_DIR/$IMG_PREFIX-$1-zImage
+      printf "\xe3\xa0\x10\x$(echo "$hexid" | cut -b "3 4")\xe3\x81\x1c\x$(echo "$hexid" | cut -b "1 2")" > "$BIN_DIR/$IMG_PREFIX-$1-zImage"
     fi
   fi
     # generate the image
-    cat $BIN_DIR/$IMG_PREFIX-zImage >> $BIN_DIR/$IMG_PREFIX-$1-zImage
+    cat "$BIN_DIR/$IMG_PREFIX-zImage" >> "$BIN_DIR/$IMG_PREFIX-$1-zImage"
 done
diff --git a/scripts/clean-package.sh b/scripts/clean-package.sh
index d1a2578..5cae341 100755
--- a/scripts/clean-package.sh
+++ b/scripts/clean-package.sh
@@ -11,7 +11,7 @@ cat "$1" | (
 	cd "$2"
 	while read entry; do
 		[ -n "$entry" ] || break
-		[ -f "$entry" ] && rm -f $entry
+		[ -f "$entry" ] && rm -f "$entry"
 	done
 )
 cat "$1" | (
diff --git a/scripts/combined-ext-image.sh b/scripts/combined-ext-image.sh
index 374fe6e..e54ae3a 100755
--- a/scripts/combined-ext-image.sh
+++ b/scripts/combined-ext-image.sh
@@ -38,7 +38,7 @@ IMG_OUT=$1; shift
 FILE_NUM=$(($# / 2))
 FILES=""
 
-printf "CE%02x%-32s%02x" $CE_VERSION "$IMG_TYPE" $FILE_NUM > $IMG_OUT
+printf "CE%02x%-32s%02x" "$CE_VERSION" "$IMG_TYPE" "$FILE_NUM" > "$IMG_OUT"
 
 while [ "$#" -gt 1 ]
    do
@@ -48,14 +48,14 @@ while [ "$#" -gt 1 ]
       [ ! -f "$file" ] && echo "$ME: Not a valid file: $file" && usage
       FILES="$FILES $file"
       md5=$(cat "$file" | md5sum -)
-      printf "%-32s%08x%32s" "$filename" $(stat -c "%s" "$file") "${md5%% *}" >> $IMG_OUT
+      printf "%-32s%08x%32s" "$filename" $(stat -c "%s" "$file") "${md5%% *}" >> "$IMG_OUT"
       shift 2
    done
 
 [ "$#" -eq 1 ] && echo "$ME: Filename not specified: $1" && usage
 
-mv $IMG_OUT $IMG_OUT.tmp
+mv "$IMG_OUT" "$IMG_OUT".tmp
 dd if="$IMG_OUT.tmp" of="$IMG_OUT" bs=65536 conv=sync 2>/dev/null
-rm $IMG_OUT.tmp
+rm "$IMG_OUT".tmp
 
-cat $FILES >> $IMG_OUT
+cat "$FILES" >> "$IMG_OUT"
diff --git a/scripts/combined-image.sh b/scripts/combined-image.sh
index 5472b2c..1eb0d95 100644
--- a/scripts/combined-image.sh
+++ b/scripts/combined-image.sh
@@ -28,7 +28,7 @@ md5=$(cat "$kern" "$root" | md5sum -)
 	$(stat -c "%s" "$kern") $(stat -c "%s" "$root") "${md5%% *}" | \
 	dd bs=$BLKSZ conv=sync;
   cat "$kern" "$root"
-) > ${IMAGE} 2>/dev/null
+) > "${IMAGE}" 2>/dev/null
 
 # Clean up.
 rm -f "$kern" "$root"
diff --git a/scripts/deptest.sh b/scripts/deptest.sh
index 03da9f5..d7be99d 100755
--- a/scripts/deptest.sh
+++ b/scripts/deptest.sh
@@ -52,7 +52,7 @@ deptest_make()
 	shift
 	local logfile="$1"
 	shift
-	make -j$nrjobs "$target" \
+	make -j"$nrjobs" "$target" \
 		BUILD_DIR="$BUILD_DIR" \
 		BUILD_DIR_HOST="$BUILD_DIR_HOST" \
 		KERNEL_BUILD_DIR="$KERNEL_BUILD_DIR" \
@@ -93,13 +93,13 @@ test_package() # $1=pkgname
 	local STAMP_FAILED="$STAMP_DIR_FAILED/$pkg"
 	local STAMP_BLACKLIST="$STAMP_DIR_BLACKLIST/$pkg"
 	rm -f "$STAMP_FAILED"
-	stamp_exists "$STAMP_SUCCESS" && [ $force -eq 0 ] && return
+	stamp_exists "$STAMP_SUCCESS" && [ "$force" -eq 0 ] && return
 	rm -f "$STAMP_SUCCESS"
 	[ -n "$SELECTED" ] || {
 		echo "Package $pkg is not selected"
 		return
 	}
-	stamp_exists "$STAMP_BLACKLIST" && [ $force -eq 0 ] && {
+	stamp_exists "$STAMP_BLACKLIST" && [ "$force" -eq 0 ] && {
 		echo "Package $pkg is blacklisted"
 		return
 	}
@@ -107,12 +107,12 @@ test_package() # $1=pkgname
 	rm -rf "$STAGING_DIR" "$STAGING_DIR_HOST"
 	mkdir -p "$STAGING_DIR"
 	cp -al "$STAGING_DIR_HOST_TMPL" "$STAGING_DIR_HOST"
-	[ $lean_test -eq 0 ] && {
+	[ "$lean_test" -eq 0 ] && {
 		rm -rf "$BUILD_DIR" "$BUILD_DIR_HOST"
 		clean_kernel_build_dir
 	}
 	mkdir -p "$BUILD_DIR" "$BUILD_DIR_HOST"
-	local logfile="$(basename $pkg).log"
+	local logfile="$(basename "$pkg").log"
 	deptest_make "package/$pkg/compile" "$logfile"
 	if [ $? -eq 0 ]; then
 		( cd "$STAMP_DIR_SUCCESS"; ln -s "../$LOG_DIR_NAME/$logfile" "./$pkg" )
@@ -179,7 +179,7 @@ bootstrap_native_make()
 	shift
 	local logfile="bootstrap-native-$(echo "$target" | tr / -).log"
 	echo "make $target"
-	make -j$nrjobs "$target" \
+	make -j"$nrjobs" "$target" \
 		V=99 "$@" >"$LOG_DIR/$logfile" 2>&1 || \
 		die "make $target failed, please check $logfile"
 }
diff --git a/scripts/ext-toolchain.sh b/scripts/ext-toolchain.sh
index 09390c5..047bc24 100755
--- a/scripts/ext-toolchain.sh
+++ b/scripts/ext-toolchain.sh
@@ -156,8 +156,8 @@ find_libs() {
 		done
 
 		local pattern
-		for pattern in $(eval echo $spec); do
-			find $libdirs -name "$pattern.so*" | sort -u
+		for pattern in $(eval echo "$spec"); do
+			find "$libdirs" -name "$pattern.so*" | sort -u
 		done
 
 		return 0
@@ -186,8 +186,8 @@ find_bins() {
 		done
 
 		local pattern
-		for pattern in $(eval echo $spec); do
-			find $bindirs -name "$pattern" | sort -u
+		for pattern in $(eval "echo $spec"); do
+			find "$bindirs" -name "$pattern" | sort -u
 		done
 
 		return 0
@@ -305,7 +305,7 @@ print_config() {
 
 		if [ -n "$mktargets" ]; then
 			echo "Available targets:"                               >&2
-			echo $mktargets                                         >&2
+			echo "$mktargets"                                       >&2
 		else
 			echo -e "Could not find a suitable OpenWrt target for " >&2
 			echo -e "CPU architecture '$cpuarch' - you need to "    >&2
@@ -488,6 +488,7 @@ while [ -n "$1" ]; do
 
 		--print-target)
 			if probe_cc; then
+				# shellcheck disable=SC2086
 				exec "$CC" $CFLAGS -dumpmachine
 			fi
 			echo "No C compiler found in '$TOOLCHAIN'." >&2
@@ -573,9 +574,9 @@ while [ -n "$1" ]; do
 
 		*)
 			echo "Unknown argument '$arg'" >&2
-			exec $0 --help
+			exec "$0" --help
 		;;
 	esac
 done
 
-exec $0 --help
+exec "$0" --help
diff --git a/scripts/flashing/flash.sh b/scripts/flashing/flash.sh
index 3499581..7f2cdf5 100755
--- a/scripts/flashing/flash.sh
+++ b/scripts/flashing/flash.sh
@@ -20,8 +20,8 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
 
-if [ -z "$1" ] || [ ! -f $1 ] || [ -z $2 ]; then
-    echo Usage: $0 firmware vendor
+if [ -z "$1" ] || [ ! -f "$1" ] || [ -z "$2" ]; then
+    echo Usage: "$0" firmware vendor
 cat << EOF
 IMPORTANT:
 Notes for Linksys / Asus WL500gx router: 
@@ -52,15 +52,15 @@ fi
 if [ "$2" = "asus" ]; then
 echo Confirming IP address setting...
 echo -en "get ASUSSPACELINK\x01\x01\xa8\xc0 /dev/null\nquit\n" | tftp 192.168.1.1
-echo Flashing 192.168.1.1 using $1...
+echo Flashing 192.168.1.1 using "$1"...
 echo -en "binary\nput $1 ASUSSPACELINK\nquit\n" | tftp 192.168.1.1
 echo Please wait until leds stops flashing. 
 elif [ "$2" = "linksys" ]; then
-echo Flashing 192.168.1.1 using $1...
+echo Flashing 192.168.1.1 using "$1"...
 echo -en "rexmt 1\ntrace\nbinary\nput $1\nquit\n" | tftp 192.168.1.1
 echo Please wait until power led stops flashing. Do not poweroff! Then you can login via telnet 192.168.1.1.
 elif [ "$2" = "toshiba" ]; then
-echo Flashing 192.168.10.1 using $1...
+echo Flashing 192.168.10.1 using "$1"...
 echo -en "rexmt 1\ntrace\nbinary\nput $1\nquit\n" | tftp 192.168.10.1
 echo Unit will automatically reboot within 5 minutes.  Do not power off.  Then you can login via telnet 192.168.10.1.
 fi
diff --git a/scripts/gen-dependencies.sh b/scripts/gen-dependencies.sh
index c6b6f75..c77b5e4 100755
--- a/scripts/gen-dependencies.sh
+++ b/scripts/gen-dependencies.sh
@@ -18,16 +18,16 @@ XARGS="${XARGS:-xargs -r}"
   exit 1
 }
 
-find $TARGETS -type f -a -exec file {} \; | \
+find "$TARGETS" -type f -a -exec file {} \; | \
   sed -n -e 's/^\(.*\):.*ELF.*\(executable\|shared object\).*,.* stripped/\1/p' | \
-  $XARGS -n1 $READELF -d | \
+  $XARGS -n1 "$READELF" -d | \
   awk '$2 ~ /NEEDED/ && $NF !~ /interpreter/ && $NF ~ /^\[?lib.*\.so/ { gsub(/[\[\]]/, "", $NF); print $NF }' | \
   sort -u
 
-tmp=`mktemp $TMP_DIR/dep.XXXXXXXX`
-for kmod in `find $TARGETS -type f -name \*.ko`; do
-	$OBJCOPY -O binary -j .modinfo $kmod $tmp
-	sed -e 's,\x00,\n,g' $tmp | \
+tmp=`mktemp "$TMP_DIR"/dep.XXXXXXXX`
+for kmod in `find "$TARGETS" -type f -name \*.ko`; do
+	$OBJCOPY -O binary -j .modinfo "$kmod" "$tmp"
+	sed -e 's,\x00,\n,g' "$tmp" | \
 		sed -ne '/^depends=.\+/ { s/^depends=//; s/,/.ko\n/g; s/$/.ko/p; q }'
 done | sort -u
-rm -f $tmp
+rm -f "$tmp"
diff --git a/scripts/get_source_date_epoch.sh b/scripts/get_source_date_epoch.sh
index ea8d930..1bec45f 100755
--- a/scripts/get_source_date_epoch.sh
+++ b/scripts/get_source_date_epoch.sh
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 export LANG=C
 export LC_ALL=C
-[ -n "$TOPDIR" ] && cd $TOPDIR
+[ -n "$TOPDIR" ] && cd "$TOPDIR"
 
 try_version() {
 	[ -f version.date ] || return 1
diff --git a/scripts/getver.sh b/scripts/getver.sh
index e718485..7127eb2 100755
--- a/scripts/getver.sh
+++ b/scripts/getver.sh
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 export LANG=C
 export LC_ALL=C
-[ -n "$TOPDIR" ] && cd $TOPDIR
+[ -n "$TOPDIR" ] && cd "$TOPDIR"
 
 GET_REV=$1
 
@@ -25,13 +25,13 @@ try_git() {
 		;;
 	*)
 		BRANCH="$(git rev-parse --abbrev-ref HEAD)"
-		ORIGIN="$(git rev-parse --verify --symbolic-full-name ${BRANCH}@{u} 2>/dev/null)"
+		ORIGIN="$(git rev-parse --verify --symbolic-full-name "${BRANCH}"@{u} 2>/dev/null)"
 		[ -n "$ORIGIN" ] || ORIGIN="$(git rev-parse --verify --symbolic-full-name master@{u} 2>/dev/null)"
-		REV="$(git rev-list ${REBOOT}..$GET_REV | wc -l | awk '{print $1}')"
+		REV="$(git rev-list ${REBOOT}.."$GET_REV" | wc -l | awk '{print $1}')"
 
 		if [ -n "$ORIGIN" ]; then
-			UPSTREAM_BASE="$(git merge-base $GET_REV $ORIGIN)"
-			UPSTREAM_REV="$(git rev-list ${REBOOT}..$UPSTREAM_BASE | wc -l | awk '{print $1}')"
+			UPSTREAM_BASE="$(git merge-base "$GET_REV" "$ORIGIN")"
+			UPSTREAM_REV="$(git rev-list ${REBOOT}.."$UPSTREAM_BASE" | wc -l | awk '{print $1}')"
 		else
 			UPSTREAM_REV=$REV
 		fi
diff --git a/scripts/ipkg-make-index.sh b/scripts/ipkg-make-index.sh
index 1822227..e1ecf87 100755
--- a/scripts/ipkg-make-index.sh
+++ b/scripts/ipkg-make-index.sh
@@ -3,7 +3,7 @@ set -e
 
 pkg_dir=$1
 
-if [ -z $pkg_dir ] || [ ! -d $pkg_dir ]; then
+if [ -z "$pkg_dir" ] || [ ! -d "$pkg_dir" ]; then
 	echo "Usage: ipkg-make-index <package_directory>" >&2
 	exit 1
 fi
@@ -11,19 +11,19 @@ fi
 which md5sum >/dev/null 2>&1 || alias md5sum=md5
 empty=1
 
-for pkg in `find $pkg_dir -name '*.ipk' | sort`; do
+for pkg in `find "$pkg_dir" -name '*.ipk' | sort`; do
 	empty=
 	name="${pkg##*/}"
 	name="${name%%_*}"
 	[[ "$name" = "kernel" ]] && continue
 	[[ "$name" = "libc" ]] && continue
 	echo "Generating index for package $pkg" >&2
-	file_size=$(ls -l $pkg | awk '{print $5}')
-	md5sum=$(md5sum $pkg | awk '{print $1}')
-	sha256sum=$(openssl dgst -sha256 $pkg | awk '{print $2}')
+	file_size=$(ls -l "$pkg" | awk '{print $5}')
+	md5sum=$(md5sum "$pkg" | awk '{print $1}')
+	sha256sum=$(openssl dgst -sha256 "$pkg" | awk '{print $2}')
 	# Take pains to make variable value sed-safe
-	sed_safe_pkg=`echo $pkg | sed -e 's/^\.\///g' -e 's/\\//\\\\\\//g'`
-	tar -xzOf $pkg ./control.tar.gz | tar xzOf - ./control | sed -e "s/^Description:/Filename: $sed_safe_pkg\\
+	sed_safe_pkg=`echo "$pkg" | sed -e 's/^\.\///g' -e 's/\\//\\\\\\//g'`
+	tar -xzOf "$pkg" ./control.tar.gz | tar xzOf - ./control | sed -e "s/^Description:/Filename: $sed_safe_pkg\\
 Size: $file_size\\
 MD5Sum: $md5sum\\
 SHA256sum: $sha256sum\\
diff --git a/scripts/mkits.sh b/scripts/mkits.sh
index 8857996..3e75e8d 100755
--- a/scripts/mkits.sh
+++ b/scripts/mkits.sh
@@ -15,7 +15,7 @@
 #
 
 usage() {
-	echo "Usage: `basename $0` -A arch -C comp -a addr -e entry" \
+	echo "Usage: `basename "$0"` -A arch -C comp -a addr -e entry" \
 		"-v version -k kernel [-D name -d dtb] -o its_file"
 	echo -e "\t-A ==> set architecture to 'arch'"
 	echo -e "\t-C ==> set compression type 'comp'"
@@ -53,7 +53,7 @@ if [ -z "${ARCH}" ] || [ -z "${COMPRESS}" ] || [ -z "${LOAD_ADDR}" ] || \
 	usage
 fi
 
-ARCH_UPPER=`echo $ARCH | tr '[:lower:]' '[:upper:]'`
+ARCH_UPPER=`echo "$ARCH" | tr '[:lower:]' '[:upper:]'`
 
 # Conditionally create fdt information
 if [ -n "${DTB}" ]; then
@@ -114,4 +114,4 @@ ${FDT}
 };"
 
 # Write .its file to disk
-echo "$DATA" > ${OUTPUT}
+echo "$DATA" > "${OUTPUT}"
diff --git a/scripts/om-fwupgradecfg-gen.sh b/scripts/om-fwupgradecfg-gen.sh
index 6c3b74c..b200584 100644
--- a/scripts/om-fwupgradecfg-gen.sh
+++ b/scripts/om-fwupgradecfg-gen.sh
@@ -8,7 +8,7 @@
 
 usage() {
 	echo "Usage: $0 <OM2P|OM5P|OM5PAC|MR600|MR900|MR1750> <out file path> <kernel path> <rootfs path>"
-	rm -f $CFG_OUT
+	rm -f "$CFG_OUT"
 	exit 1
 }
 
@@ -41,20 +41,20 @@ esac
 CHECK_BS=65536
 
 KERNEL_SIZE=$(stat -c%s "$KERNEL_PATH")
-KERNEL_MD5=$(md5=$(md5sum $KERNEL_PATH); echo ${md5%% *})
-KERNEL_SHA256=$(openssl dgst -sha256 $KERNEL_PATH | awk '{print $2}')
-KERNEL_PART_SIZE=$(size=$(($KERNEL_SIZE / $FLASH_BS)); [ $(($size * $FLASH_BS)) -lt $KERNEL_SIZE ] && size=$(($size + 1)); echo $(($size * $FLASH_BS / 1024)))
+KERNEL_MD5=$(md5=$(md5sum "$KERNEL_PATH"); echo "${md5%% *}")
+KERNEL_SHA256=$(openssl dgst -sha256 "$KERNEL_PATH" | awk '{print $2}')
+KERNEL_PART_SIZE=$(size=$(($KERNEL_SIZE / $FLASH_BS)); [ $(($size * $FLASH_BS)) -lt "$KERNEL_SIZE" ] && size=$(($size + 1)); echo $(($size * $FLASH_BS / 1024)))
 
 ROOTFS_FLASH_ADDR=$(addr=$(($KERNEL_FLASH_ADDR + ($KERNEL_PART_SIZE * 1024))); printf "0x%x" $addr)
 ROOTFS_SIZE=$(stat -c%s "$ROOTFS_PATH")
 ROOTFS_CHECK_BLOCKS=$((($ROOTFS_SIZE / $CHECK_BS) - $MD5_SKIP_BLOCKS))
-ROOTFS_MD5=$(md5=$(dd if=$ROOTFS_PATH bs=$CHECK_BS count=$ROOTFS_CHECK_BLOCKS 2>&- | md5sum); echo ${md5%% *})
-ROOTFS_MD5_FULL=$(md5=$(md5sum $ROOTFS_PATH); echo ${md5%% *})
-ROOTFS_SHA256_FULL=$(openssl dgst -sha256 $ROOTFS_PATH | awk '{print $2}')
+ROOTFS_MD5=$(md5=$(dd if="$ROOTFS_PATH" bs=$CHECK_BS count=$ROOTFS_CHECK_BLOCKS 2>&- | md5sum); echo "${md5%% *}")
+ROOTFS_MD5_FULL=$(md5=$(md5sum "$ROOTFS_PATH"); echo "${md5%% *}")
+ROOTFS_SHA256_FULL=$(openssl dgst -sha256 "$ROOTFS_PATH" | awk '{print $2}')
 ROOTFS_CHECK_SIZE=$(printf '0x%x' $(($ROOTFS_CHECK_BLOCKS * $CHECK_BS)))
 ROOTFS_PART_SIZE=$(($MAX_PART_SIZE - $KERNEL_PART_SIZE))
 
-cat << EOF > $CFG_OUT
+cat << EOF > "$CFG_OUT"
 [vmlinux]
 filename=kernel
 md5sum=$KERNEL_MD5
diff --git a/scripts/patch-kernel.sh b/scripts/patch-kernel.sh
index c2b7e72..f0f294e 100755
--- a/scripts/patch-kernel.sh
+++ b/scripts/patch-kernel.sh
@@ -37,7 +37,7 @@ for i in ${patchdir}/${patchpattern} ; do
     [ -d "${i}" ] && echo "Ignoring subdirectory ${i}" && continue	
     echo ""
     echo "Applying ${i} using ${type}: " 
-    ${uncomp} ${i} | ${PATCH:-patch} -f -p1 -d ${targetdir}
+    ${uncomp} "${i}" | ${PATCH:-patch} -f -p1 -d "${targetdir}"
     if [ $? != 0 ] ; then
         echo "Patch failed!  Please fix $i!"
 	exit 1
@@ -45,10 +45,10 @@ for i in ${patchdir}/${patchpattern} ; do
 done
 
 # Check for rejects...
-if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
+if [ "`find "$targetdir"/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
     echo "Aborting.  Reject files found."
     exit 1
 fi
 
 # Remove backup files
-find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
+find "$targetdir"/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
diff --git a/scripts/relink-lib.sh b/scripts/relink-lib.sh
index 5367b70..25ce5d9 100755
--- a/scripts/relink-lib.sh
+++ b/scripts/relink-lib.sh
@@ -9,6 +9,6 @@ ref="$1"; shift
 pic="$1"; shift
 dest="$1"; shift
 
-SYMBOLS="$(${cross}nm "$ref" | grep -E '........ [TW] ' | awk '$3 {printf "-u%s ", $3}')"
+SYMBOLS="$("${cross}"nm "$ref" | grep -E '........ [TW] ' | awk '$3 {printf "-u%s ", $3}')"
 set -x
-${cross}gcc -nostdlib -nostartfiles -shared -Wl,--gc-sections -o "$dest" $SYMBOLS "$pic" "$@"
+"${cross}"gcc -nostdlib -nostartfiles -shared -Wl,--gc-sections -o "$dest" "$SYMBOLS" "$pic" "$@"
diff --git a/scripts/rstrip.sh b/scripts/rstrip.sh
index 4e4232d..5c8a5aa 100755
--- a/scripts/rstrip.sh
+++ b/scripts/rstrip.sh
@@ -20,7 +20,7 @@ TARGETS=$*
   exit 1
 }
 
-find $TARGETS -type f -a -exec file {} \; | \
+find "$TARGETS" -type f -a -exec file {} \; | \
   sed -n -e 's/^\(.*\):.*ELF.*\(executable\|relocatable\|shared object\).*,.* stripped/\1:\2/p' | \
 (
   IFS=":"
@@ -29,20 +29,20 @@ find $TARGETS -type f -a -exec file {} \; | \
 	[ "${S}" = "relocatable" ] && {
 		eval "$STRIP_KMOD $F"
 	} || {
-		b=$(stat -c '%a' $F)
+		b=$(stat -c '%a' "$F")
 		[ -z "$PATCHELF" ] || [ -z "$TOPDIR" ] || {
-			old_rpath="$($PATCHELF --print-rpath $F)"; new_rpath=""
+			old_rpath="$($PATCHELF --print-rpath "$F")"; new_rpath=""
 			for path in $old_rpath; do
 				case "$path" in
 					/lib/[^/]*|/usr/lib/[^/]*|\$ORIGIN/*) new_rpath="${new_rpath:+$new_rpath:}$path" ;;
 					*) echo "$SELF: $F: removing rpath $path" ;;
 				esac
 			done
-			[ "$new_rpath" = "$old_rpath" ] || $PATCHELF --set-rpath "$new_rpath" $F
+			[ "$new_rpath" = "$old_rpath" ] || $PATCHELF --set-rpath "$new_rpath" "$F"
 		}
 		eval "$STRIP $F"
-		a=$(stat -c '%a' $F)
-		[ "$a" = "$b" ] || chmod $b $F
+		a=$(stat -c '%a' "$F")
+		[ "$a" = "$b" ] || chmod "$b" "$F"
 	}
   done
   true
diff --git a/scripts/strip-kmod.sh b/scripts/strip-kmod.sh
index 313015b..5a43ed5 100755
--- a/scripts/strip-kmod.sh
+++ b/scripts/strip-kmod.sh
@@ -22,7 +22,8 @@ if [ -z "$KEEP_BUILD_ID" ]; then
     ARGS="$ARGS -R .note.gnu.build-id"
 fi
 
-${CROSS}objcopy \
+# shellcheck disable=SC2086
+"${CROSS}"objcopy \
 	-R .comment \
 	-R .pdr \
 	-R .mdebug.abi32 \
@@ -38,7 +39,7 @@ ${CROSS}objcopy \
 	exit 0
 }
 
-${CROSS}nm "$MODULE.tmp" | awk '
+"${CROSS}"nm "$MODULE.tmp" | awk '
 BEGIN {
 	n = 0
 }
@@ -50,6 +51,6 @@ $3 && $2 ~ /[brtd]/ && $3 !~ /\$LC/ && !def[$3] {
 }
 ' > "$MODULE.tmp1"
 
-${CROSS}objcopy `cat ${MODULE}.tmp1` ${MODULE}.tmp ${MODULE}.out
+"${CROSS}"objcopy `cat "${MODULE}".tmp1` "${MODULE}".tmp "${MODULE}".out
 mv "${MODULE}.out" "${MODULE}"
 rm -f "${MODULE}".t*
diff --git a/scripts/sysupgrade-tar.sh b/scripts/sysupgrade-tar.sh
index 45b17da..9995b7c 100755
--- a/scripts/sysupgrade-tar.sh
+++ b/scripts/sysupgrade-tar.sh
@@ -61,7 +61,7 @@ if [ -n "$SOURCE_DATE_EPOCH" ]; then
 	mtime="--mtime=@${SOURCE_DATE_EPOCH}"
 fi
 
-(cd "$tmpdir"; tar cvf sysupgrade.tar sysupgrade-${board} ${mtime})
+(cd "$tmpdir"; tar cvf sysupgrade.tar sysupgrade-"${board}" "${mtime}")
 err="$?"
 if [ -e "$tmpdir/sysupgrade.tar" ]; then
 	cp "$tmpdir/sysupgrade.tar" "$outfile"
diff --git a/scripts/ubinize-image.sh b/scripts/ubinize-image.sh
index 09a00b1..1117e5b 100755
--- a/scripts/ubinize-image.sh
+++ b/scripts/ubinize-image.sh
@@ -9,11 +9,11 @@ outfile=""
 err=""
 
 get_magic_word() {
-	dd if=$1 bs=2 count=1 2>/dev/null | hexdump -v -n 2 -e '1/1 "%02x"'
+	dd if="$1" bs=2 count=1 2>/dev/null | hexdump -v -n 2 -e '1/1 "%02x"'
 }
 
 is_ubifs() {
-	if [ "$( get_magic_word $1 )" = "3118" ]; then
+	if [ "$( get_magic_word "$1" )" = "3118" ]; then
 		echo "1"
 	fi
 }
@@ -69,7 +69,7 @@ ubilayout() {
 		ubivol $vol_id kernel "$3"
 		vol_id=$(( $vol_id + 1 ))
 	fi
-	ubivol $vol_id rootfs "$2" $root_is_ubifs
+	ubivol $vol_id rootfs "$2" "$root_is_ubifs"
 	vol_id=$(( $vol_id + 1 ))
 	[ "$root_is_ubifs" ] || ubivol $vol_id rootfs_data "" 1
 }
@@ -131,7 +131,7 @@ fi
 ubilayout "$ubootenv" "$rootfs" "$kernel" > "$ubinizecfg"
 
 cat "$ubinizecfg"
-ubinize -o "$outfile" $ubinize_param "$ubinizecfg"
+ubinize -o "$outfile" "$ubinize_param" "$ubinizecfg"
 err="$?"
 [ ! -e "$outfile" ] && err=2
 rm "$ubinizecfg"
-- 
2.10.0




More information about the Lede-dev mailing list