[OS-BUILD PATCHv3 1/3] process_configs.sh: Fix syntax flagged by shellcheck

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Ben Crocker <bcrocker@xxxxxxxxxx>

• SC2006: Use $(...) notation instead of legacy backticked `...`.
• SC2034: <variable> appears unused. Verify use (or export if used externally).
• SC2045: Iterating over ls output is fragile. Use globs.
• SC2046: Quote this to prevent word splitting.
• SC2086: Double quote to prevent globbing and word splitting.
• SC2231: Quote expansions in this for-loop glob to prevent wordsplitting, e.g. "$dir"/*.txt .

Ignore:
• SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

Signed-off-by: Ben Crocker <bcrocker@xxxxxxxxxx>
---
 redhat/configs/process_configs.sh | 69 ++++++++++++++++---------------
 1 file changed, 35 insertions(+), 34 deletions(-)

diff --git a/redhat/configs/process_configs.sh b/redhat/configs/process_configs.sh
index 14773fef2410..86d8f805418c 100755
--- a/redhat/configs/process_configs.sh
+++ b/redhat/configs/process_configs.sh
@@ -3,6 +3,8 @@
 # This script takes the merged config files and processes them through oldconfig
 # and listnewconfig
 #
+# Globally disable suggestion of appending '|| exit' or '|| return' to cd/pushd/popd commands
+# shellcheck disable=SC2164
 
 usage()
 {
@@ -30,11 +32,11 @@ switch_to_toplevel()
 	path="$(pwd)"
 	while test -n "$path"
 	do
-		test -e $path/MAINTAINERS && \
-			test -d $path/drivers && \
+		test -e "$path"/MAINTAINERS && \
+			test -d "$path"/drivers && \
 			break
 
-		path="$(dirname $path)"
+		path="$(dirname "$path")"
 	done
 
 	test -n "$path"  || die "Can't find toplevel"
@@ -65,7 +67,7 @@ checkoptions()
 					 print "Found "a[1]"="a[2]" after generation, had " a[1]"="configs[a[1]]" in Source tree";
 			}
 		}
-	' $1 $2 > .mismatches
+	' "$1" "$2" > .mismatches
 
 	if test -s .mismatches
 	then
@@ -84,7 +86,7 @@ parsenewconfigs()
 	# and puts it into CONFIG_FOO files. Using the output of
 	# listnewconfig is much easier to ensure we get the default
 	# output.
-        /usr/bin/awk -v BASE=$tmpdir '
+        /usr/bin/awk -v BASE="$tmpdir" '
                 /is not set/ {
                         split ($0, a, "#");
                         split(a[2], b);
@@ -109,7 +111,7 @@ parsenewconfigs()
 	# each CONFIG_FOO file. Because of how awk works
 	# there's a lot of moving files around and catting to
 	# get what we need.
-        /usr/bin/awk -v BASE=$tmpdir '
+        /usr/bin/awk -v BASE="$tmpdir" '
                 BEGIN { inpatch=0;
 			outfile="none";
                         symbol="none"; }
@@ -141,28 +143,28 @@ parsenewconfigs()
 
         ' .helpnewconfig
 
-	pushd $tmpdir &> /dev/null
+	pushd "$tmpdir" &> /dev/null
 	rm fake_*
 	popd &> /dev/null
-	for f in `ls $tmpdir`; do
-		[[ -e "$tmpdir/$f" ]] || break
-		cp $tmpdir/$f $SCRIPT_DIR/pending"$FLAVOR"/generic/
+	for f in "$tmpdir"/*; do
+		[[ -e "$f" ]] || break
+		cp "$f" "$SCRIPT_DIR"/pending"$FLAVOR"/generic/
 	done
 
-	rm -rf $tmpdir
+	rm -rf "$tmpdir"
 }
 
 function commit_new_configs()
 {
 	# assume we are in $source_tree/configs, need to get to top level
-	pushd $(switch_to_toplevel) &>/dev/null
+	pushd "$(switch_to_toplevel)" &>/dev/null
 
-	for cfg in $SCRIPT_DIR/${PACKAGE_NAME}${KVERREL}${SUBARCH}*.config
+	for cfg in "$SCRIPT_DIR"/"${PACKAGE_NAME}""${KVERREL}""${SUBARCH}"*.config
 	do
-		arch=$(head -1 $cfg | cut -b 3-)
+		arch=$(head -1 "$cfg" | cut -b 3-)
 		cfgtmp="${cfg}.tmp"
 		cfgorig="${cfg}.orig"
-		cat $cfg > $cfgorig
+		cat "$cfg" > "$cfgorig"
 
 		if [ "$arch" = "EMPTY" ]
 		then
@@ -171,32 +173,32 @@ function commit_new_configs()
 		fi
 		echo -n "Checking for new configs in $cfg ... "
 
-		make ARCH=$arch KCONFIG_CONFIG=$cfgorig listnewconfig >& .listnewconfig
+		make ARCH="$arch" KCONFIG_CONFIG="$cfgorig" listnewconfig >& .listnewconfig
 		grep -E 'CONFIG_' .listnewconfig > .newoptions
 		if test -s .newoptions
 		then
-			make ARCH=$arch KCONFIG_CONFIG=$cfgorig helpnewconfig >& .helpnewconfig
+			make ARCH="$arch" KCONFIG_CONFIG="$cfgorig" helpnewconfig >& .helpnewconfig
 			parsenewconfigs
 		fi
 		rm .newoptions
 		echo "done"
 	done
 
-	git add $SCRIPT_DIR/pending"$FLAVOR"
+	git add "$SCRIPT_DIR"/pending"$FLAVOR"
 	git commit -m "[redhat] AUTOMATIC: New configs"
 }
 
 function process_configs()
 {
 	# assume we are in $source_tree/configs, need to get to top level
-	pushd $(switch_to_toplevel) &>/dev/null
+	pushd "$(switch_to_toplevel)" &>/dev/null
 
-	for cfg in $SCRIPT_DIR/${PACKAGE_NAME}${KVERREL}${SUBARCH}*.config
+	for cfg in "$SCRIPT_DIR"/"${PACKAGE_NAME}""${KVERREL}""${SUBARCH}"*.config
 	do
-		arch=$(head -1 $cfg | cut -b 3-)
+		arch=$(head -1 "$cfg" | cut -b 3-)
 		cfgtmp="${cfg}.tmp"
 		cfgorig="${cfg}.orig"
-		cat $cfg > $cfgorig
+		cat "$cfg" > "$cfgorig"
 
 		if [ "$arch" = "EMPTY" ]
 		then
@@ -205,7 +207,7 @@ function process_configs()
 		fi
 		echo -n "Processing $cfg ... "
 
-		make ARCH=$arch KCONFIG_CONFIG=$cfgorig listnewconfig >& .listnewconfig
+		make ARCH="$arch" KCONFIG_CONFIG="$cfgorig" listnewconfig >& .listnewconfig
 		grep -E 'CONFIG_' .listnewconfig > .newoptions
 		if test -n "$NEWOPTIONS" && test -s .newoptions
 		then
@@ -230,21 +232,21 @@ function process_configs()
 
 		rm .listnewconfig
 
-		make ARCH=$arch KCONFIG_CONFIG=$cfgorig olddefconfig > /dev/null || exit 1
-		echo "# $arch" > ${cfgtmp}
-		cat "${cfgorig}" >> ${cfgtmp}
+		make ARCH="$arch" KCONFIG_CONFIG="$cfgorig" olddefconfig > /dev/null || exit 1
+		echo "# $arch" > "${cfgtmp}"
+		cat "${cfgorig}" >> "${cfgtmp}"
 		if test -n "$CHECKOPTIONS"
 		then
-			checkoptions $cfg $cfgtmp
+			checkoptions "$cfg" "$cfgtmp"
 		fi
 		# if test run, don't overwrite original
 		if test -n "$TESTRUN"
 		then
-			rm ${cfgtmp}
+			rm "${cfgtmp}"
 		else
-			mv ${cfgtmp} ${cfg}
+			mv "${cfgtmp}" "${cfg}"
 		fi
-		rm ${cfgorig}
+		rm "${cfgorig}"
 		echo "done"
 	done
 	rm "$SCRIPT_DIR"/*.config*.old
@@ -302,9 +304,8 @@ PACKAGE_NAME="${1:-kernel}" # defines the package name used
 KVERREL="$(test -n "$2" && echo "-$2" || echo "")"
 SUBARCH="$(test -n "$3" && echo "-$3" || echo "")"
 FLAVOR="$(test -n "$4" && echo "-$4" || echo "-common")"
-SCRIPT="$(readlink -f $0)"
-OUTPUT_DIR="$PWD"
-SCRIPT_DIR="$(dirname $SCRIPT)"
+SCRIPT="$(readlink -f "$0")"
+SCRIPT_DIR="$(dirname "$SCRIPT")"
 
 # Most RHEL options are options we want in Fedora so RHEL pending settings head
 # to common/
@@ -314,7 +315,7 @@ then
 fi
 
 # to handle this script being a symlink
-cd $SCRIPT_DIR
+cd "$SCRIPT_DIR"
 
 if test -n "$COMMITNEWCONFIGS"; then
 	commit_new_configs
-- 
GitLab
_______________________________________________
kernel mailing list -- kernel@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to kernel-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/kernel@xxxxxxxxxxxxxxxxxxxxxxx




[Index of Archives]     [Fedora General Discussion]     [Older Fedora Users Archive]     [Fedora Advisory Board]     [Fedora Security]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Mentors]     [Fedora Package Announce]     [Fedora Package Review]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Coolkey]     [Yum Users]     [Tux]     [Yosemite News]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [USB]     [Asterisk PBX]

  Powered by Linux