From: Harald Hoyer Date: Fri, 26 Mar 2021 09:29:28 +0000 (+0100) Subject: fix(nfs): shellcheck for modules.d/95nfs X-Git-Tag: 054~203 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=11e82f3eccc0fa419da3971863da49aa9458433e;p=thirdparty%2Fdracut-ng.git fix(nfs): shellcheck for modules.d/95nfs --- diff --git a/modules.d/95nfs/.shchkdir b/modules.d/95nfs/.shchkdir new file mode 100644 index 000000000..e69de29bb diff --git a/modules.d/95nfs/nfs-lib.sh b/modules.d/95nfs/nfs-lib.sh index 1ee62c777..15bc3a30f 100755 --- a/modules.d/95nfs/nfs-lib.sh +++ b/modules.d/95nfs/nfs-lib.sh @@ -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:[:][:] 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" } diff --git a/modules.d/95nfs/nfsroot-cleanup.sh b/modules.d/95nfs/nfsroot-cleanup.sh index 6e65e83f1..95ea26ecc 100755 --- a/modules.d/95nfs/nfsroot-cleanup.sh +++ b/modules.d/95nfs/nfsroot-cleanup.sh @@ -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 diff --git a/modules.d/95nfs/nfsroot.sh b/modules.d/95nfs/nfsroot.sh index c5fa27831..794e0d83a 100755 --- a/modules.d/95nfs/nfsroot.sh +++ b/modules.d/95nfs/nfsroot.sh @@ -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 diff --git a/modules.d/95nfs/parse-nfsroot.sh b/modules.d/95nfs/parse-nfsroot.sh index 765cfa0c5..729bbc218 100755 --- a/modules.d/95nfs/parse-nfsroot.sh +++ b/modules.d/95nfs/parse-nfsroot.sh @@ -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