[OS-BUILD PATCH 1/20] [redhat] scripts/configdiff.sh: Fix syntax flagged by shellcheck

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

 



From: Ben Crocker <bcrocker@xxxxxxxxxx>

SC2001: See if you can use ${variable//search/replace} instead.
SC2045: Iterating over ls output is fragile. Use globs.
SC2046: Quote this (command) to prevent word splitting.
SC2086: Double quote to prevent globbing and word splitting.
SC2162: read without -r will mangle backslashes.
SC2231: Quote expansions in this for loop glob to prevent wordsplitting, e.g. "$dir"/*.txt .

Also, change to #!/bin/bash so bash-isms won't be flagged, e.g.

SC2039: In POSIX sh, [[ ]] is undefined.

Signed-off-by: Ben Crocker <bcrocker@xxxxxxxxxx>
---
 redhat/scripts/configdiff.sh | 49 ++++++++++++++++++------------------
 1 file changed, 25 insertions(+), 24 deletions(-)

diff --git a/redhat/scripts/configdiff.sh b/redhat/scripts/configdiff.sh
index 6c62a3412e94..b9ca2b034e70 100755
--- a/redhat/scripts/configdiff.sh
+++ b/redhat/scripts/configdiff.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#! /bin/bash
 
 RHCP=redhat/configs
 RHCP_RHEL=$RHCP
@@ -20,14 +20,15 @@ get_configarch()
 
     # make dist-configs-prep uses <package-name>-<arch>-<variant>.config
     # the trick is to get the <package-name> and filter it out
-    arch="$(echo "$file" | sed "s/$PACKAGE_NAME-\([^-]*\).*.config/\1/")"
+    arch="${file/$PACKAGE_NAME-/}"
+    arch="${arch/-*/}"
 
     # translate arch
     case $arch in
-        'x86_64')	echo "x86/x86_64" ;;
-        'ppc64le')	echo "powerpc" ;;
-        's390x')	echo "s390x" ;;
-        'aarch64')	echo "arm/aarch64" ;;
+        x86_64 )	echo "x86/x86_64" ;;
+        ppc64le )	echo "powerpc" ;;
+        s390x )		echo "s390x" ;;
+        aarch64 )	echo "arm/aarch64" ;;
         *)		die "Unsupported arch $arch" ;;
     esac
 }
@@ -76,10 +77,10 @@ save_defaults()
     # combine all configs and filter out conflicts, then unique sort them
     # this avoids the duplicate configs from each kernel*.config file.
     # With conflicts filtered out, all files should be new.
-    cat $WORK/kernel*.config | grep -v -f $conflicts | sort -u > $WORK/.configs
-    while read config
+    cat $WORK/kernel*.config | grep -v -f "$conflicts" | sort -u > $WORK/.configs
+    while read -r config
     do
-        file="$(echo $config | cut -f1 -d '=')"
+        file="$(echo "$config" | cut -f1 -d '=')"
         path="$RHCP_RHEL/pending-common/generic/$file"
 
         # translate the =n to 'is not set'
@@ -91,32 +92,32 @@ save_defaults()
         fi
 
         # normal path
-        test ! -e $path && echo "$value" > $path && continue
+        test ! -e "$path": && echo "$value" > "$path" && continue
 
         # Existing files should come from newly invalid config values
         # if so, let's find and overwrite all instances of it
-        paths="$(find $RHCP_RHEL -name $file)"
+        paths="$(find $RHCP_RHEL -name "$file")"
         for path in $paths
         do
             # special case, anything not set, don't overwrite, keep disabled.
             # a disabled config option is never invalid
-            grep -q 'is not set' $path && continue
+            grep -q 'is not set' "$path" && continue
 
-            echo "$value" > $path
+            echo "$value" > "$path"
         done
 
     done < $WORK/.configs
 
     # write conflicting config values to $RHCP_RHEL/pending-common/generic/arch
-    for f in $(ls -1 $WORK/kernel*.config)
+    for f in "$WORK"/kernel*.config
     do
-        grep -f $conflicts $f > $WORK/.configs
+        grep -f "$conflicts" "$f" > $WORK/.configs
         test ! -s $WORK/.configs && continue
-        arch="$(get_configarch $(basename $f))" || die "$arch"
+        arch="$(get_configarch "$(basename "$f")")" || die "$arch"
 
-        while read config
+        while read -r config
         do
-            file="$(echo $config | cut -f1 -d '=')"
+            file="$(echo "$config" | cut -f1 -d '=')"
             path="$RHCP_RHEL/pending-common/generic/$arch/$file"
 
             # translate the =n to 'is not set'
@@ -127,7 +128,7 @@ save_defaults()
                 value="$config"
             fi
 
-            echo "$value" > $path
+            echo "$value" > "$path"
         done < $WORK/.configs
     done
 }
@@ -141,15 +142,15 @@ generate_rh_config()
     # generate the new config options
     # invalid config values are handle inherently here because the kconf tool
     # spits them out as new configs
-    for f in $RHCP/kernel*.config
+    for f in "$RHCP"/kernel*.config
     do
 	echo "Working on $f"
 
-        cp $f .config
-	config="$(basename $f)"
-        arch="$(head -1 $f | cut -b 3-)" || die "$arch"
+        cp "$f" .config
+	config="$(basename "$f")"
+        arch="$(head -1 "$f" | cut -b 3-)" || die "$arch"
 
-        make ARCH=$arch listnewconfig 2>/dev/null | grep -E 'CONFIG_' | cut -d'#' -f1 > $WORK/$config
+        make ARCH="$arch" listnewconfig 2>/dev/null | grep -E 'CONFIG_' | cut -d'#' -f1 > $WORK/"$config"
     done
 
     # check for conflicting default config values
-- 
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