]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
fix(nfs): shellcheck for modules.d/95nfs
authorHarald Hoyer <harald@redhat.com>
Fri, 26 Mar 2021 09:29:28 +0000 (10:29 +0100)
committerHarald Hoyer <harald@hoyer.xyz>
Mon, 29 Mar 2021 09:40:39 +0000 (11:40 +0200)
modules.d/95nfs/.shchkdir [new file with mode: 0644]
modules.d/95nfs/nfs-lib.sh
modules.d/95nfs/nfsroot-cleanup.sh
modules.d/95nfs/nfsroot.sh
modules.d/95nfs/parse-nfsroot.sh

diff --git a/modules.d/95nfs/.shchkdir b/modules.d/95nfs/.shchkdir
new file mode 100644 (file)
index 0000000..e69de29
index 1ee62c77708f40998fb6704724a349ced66b6830..15bc3a30f3425f7af4c2f1899f3ff410731ac4ec 100755 (executable)
@@ -20,12 +20,12 @@ nfs_to_var() {
         *) nfsroot_to_var "$1" ;;
     esac
     # if anything's missing, try to fill it in from DHCP options
-    if [ -z "$server" ] || [ -z "$path" ]; then nfsroot_from_dhcp $2; fi
+    if [ -z "$server" ] || [ -z "$path" ]; then nfsroot_from_dhcp "$2"; fi
     # if there's a "%s" in the path, replace it with the hostname/IP
     if strstr "$path" "%s"; then
         local node=""
-        read node < /proc/sys/kernel/hostname
-        [ "$node" = "(none)" ] && node=$(get_ip $2)
+        read -r node < /proc/sys/kernel/hostname
+        [ "$node" = "(none)" ] && node=$(get_ip "$2")
         path=${path%%%s*}$node${path#*%s} # replace only the first %s
     fi
 }
@@ -34,7 +34,7 @@ nfs_to_var() {
 # root=nfs4:[<server-ip>:]<root-dir>[:<nfs-options>]
 nfsroot_to_var() {
     # strip nfs[4]:
-    local arg="$@:"
+    local arg="$*:"
     nfs="${arg%%:*}"
     arg="${arg##$nfs:}"
 
@@ -92,7 +92,7 @@ anaconda_nfsv6_to_var() {
     options="${path#*:/}"
     path="/${options%%:*}"
     server="${1#*nfs:}"
-    if str_starts $server '['; then
+    if str_starts "$server" '['; then
         server="${server%:/*}"
         options="${options#*:*}"
     else
@@ -107,7 +107,8 @@ anaconda_nfsv6_to_var() {
 nfsroot_from_dhcp() {
     local f
     for f in /tmp/net.$1.override /tmp/dhclient.$1.dhcpopts; do
-        [ -f $f ] && . $f
+        # shellcheck disable=SC1090
+        [ -f "$f" ] && . "$f"
     done
     [ -n "$new_root_path" ] && nfsroot_to_var "$nfs:$new_root_path"
     [ -z "$path" ] && [ "$(getarg root=)" = "/dev/nfs" ] && path=/tftpboot/%s
@@ -141,7 +142,7 @@ munge_nfs_options() {
 mount_nfs() {
     local nfsroot="$1" mntdir="$2" netif="$3"
     local nfs="" server="" path="" options=""
-    nfs_to_var "$nfsroot" $netif
+    nfs_to_var "$nfsroot" "$netif"
     munge_nfs_options
     if [ "$nfs" = "nfs4" ]; then
         options=$options${nfslock:+,$nfslock}
@@ -152,5 +153,5 @@ mount_nfs() {
             && warn "Locks unsupported on NFSv{2,3}, using nolock" 1>&2
         options=$options,nolock
     fi
-    mount -t $nfs -o$options "$server:$path" "$mntdir"
+    mount -t "$nfs" -o"$options" "$server:$path" "$mntdir"
 }
index 6e65e83f16c81b76ba0061b4001b2da71229f111..95ea26ecca80075324e9f3f19a21af4bacbebee0 100755 (executable)
@@ -6,22 +6,22 @@ type incol2 > /dev/null 2>&1 || . /lib/dracut-lib.sh
 [ -z "$rpcpipefspath" ] && rpcpipefspath=var/lib/nfs/rpc_pipefs
 
 pid=$(pidof rpc.statd)
-[ -n "$pid" ] && kill $pid
+[ -n "$pid" ] && kill "$pid"
 
 pid=$(pidof rpc.idmapd)
-[ -n "$pid" ] && kill $pid
+[ -n "$pid" ] && kill "$pid"
 
 pid=$(pidof rpcbind)
-[ -n "$pid" ] && kill $pid
+[ -n "$pid" ] && kill "$pid"
 
 if incol2 /proc/mounts /var/lib/nfs/rpc_pipefs; then
     # try to create the destination directory
-    [ -d $NEWROOT/$rpcpipefspath ] \
-        || mkdir -m 0755 -p $NEWROOT/$rpcpipefspath 2> /dev/null
+    [ -d "$NEWROOT"/$rpcpipefspath ] \
+        || mkdir -m 0755 -p "$NEWROOT"/$rpcpipefspath 2> /dev/null
 
-    if [ -d $NEWROOT/$rpcpipefspath ]; then
+    if [ -d "$NEWROOT"/$rpcpipefspath ]; then
         # mount --move does not seem to work???
-        mount --bind /var/lib/nfs/rpc_pipefs $NEWROOT/$rpcpipefspath
+        mount --bind /var/lib/nfs/rpc_pipefs "$NEWROOT"/$rpcpipefspath
         umount /var/lib/nfs/rpc_pipefs 2> /dev/null
     else
         umount /var/lib/nfs/rpc_pipefs 2> /dev/null
index c5fa27831162bece5ab53998bd7522dfa2c84374..794e0d83a09a8f5d62961a4f7e3eca8d110a69e4 100755 (executable)
@@ -11,19 +11,20 @@ netif="$1"
 root="$2"
 NEWROOT="$3"
 
-nfs_to_var $root $netif
+nfs_to_var "$root" "$netif"
 [ -z "$server" ] && die "Required parameter 'server' is missing"
 
-mount_nfs $root $NEWROOT $netif && {
+mount_nfs "$root" "$NEWROOT" "$netif" && {
     [ -e /dev/root ] || ln -s null /dev/root
     [ -e /dev/nfs ] || ln -s null /dev/nfs
 }
 
-[ -f $NEWROOT/etc/fstab ] && cat $NEWROOT/etc/fstab > /dev/null
+[ -f "$NEWROOT"/etc/fstab ] && cat "$NEWROOT"/etc/fstab > /dev/null
 
 # inject new exit_if_exists
-echo 'settle_exit_if_exists="--exit-if-exists=/dev/root"; rm -- "$job"' > $hookdir/initqueue/nfs.sh
+# shellcheck disable=SC2016
+echo 'settle_exit_if_exists="--exit-if-exists=/dev/root"; rm -- "$job"' > "$hookdir"/initqueue/nfs.sh
 # force udevsettle to break
-> $hookdir/initqueue/work
+: > "$hookdir"/initqueue/work
 
 need_shutdown
index 765cfa0c5bbec79f604739f7f99a8da5ff3a4638..729bbc2181dfa820f87c49bfd06fcd624b9f8b7b 100755 (executable)
@@ -97,7 +97,7 @@ if nfsdomain=$(getarg rd.nfs.domain -d rd_NFS_DOMAIN); then
     echo "Domain = $nfsdomain" >> /etc/idmapd.conf
 fi
 
-nfsroot_to_var $netroot
+nfsroot_to_var "$netroot"
 [ "$path" = "error" ] && die "Argument nfsroot must contain a valid path!"
 
 # Set fstype, might help somewhere
@@ -108,17 +108,20 @@ netroot="$fstype:$server:$path:$options"
 
 # If we don't have a server, we need dhcp
 if [ -z "$server" ]; then
+    # shellcheck disable=SC2034
     DHCPORSERVER="1"
 fi
 
 # Done, all good!
+# shellcheck disable=SC2034
 rootok=1
 
 # Shut up init error check or make sure that block parser wont get
 # confused by having /dev/nfs[4]
 root="$fstype"
 
-echo '[ -e $NEWROOT/proc ]' > $hookdir/initqueue/finished/nfsroot.sh
+# shellcheck disable=SC2016
+echo '[ -e $NEWROOT/proc ]' > "$hookdir"/initqueue/finished/nfsroot.sh
 
 mkdir -p /var/lib/rpcbind
 chown rpc:rpc /var/lib/rpcbind