*) 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
}
# root=nfs4:[<server-ip>:]<root-dir>[:<nfs-options>]
nfsroot_to_var() {
# strip nfs[4]:
- local arg="$@:"
+ local arg="$*:"
nfs="${arg%%:*}"
arg="${arg##$nfs:}"
options="${path#*:/}"
path="/${options%%:*}"
server="${1#*nfs:}"
- if str_starts $server '['; then
+ if str_starts "$server" '['; then
server="${server%:/*}"
options="${options#*:*}"
else
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
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}
&& 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"
}
[ -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
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
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
# 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