#!/bin/sh
which portmap >/dev/null 2>&1 && dracut_install portmap
which rpcbind >/dev/null 2>&1 && dracut_install rpcbind

dracut_install rpc.statd mount.nfs mount.nfs4 umount 
[ -f /etc/netconfig ] && dracut_install /etc/netconfig 
dracut_install /etc/services 
dracut_install /etc/nsswitch.conf /etc/rpc /etc/protocols
dracut_install rpc.idmapd /etc/idmapd.conf
if ldd $(which rpc.idmapd) |grep -q lib64; then
    LIBDIR="/lib64"
else
    LIBDIR="/lib"
fi

dracut_install $(ls {/usr,}$LIBDIR/libnfsidmap_nsswitch.so* 2>/dev/null )
#dracut_install $(ls {/usr,}$LIBDIR/libnfsidmap*.so* 2>/dev/null )

nsslibs=$(for j in $(for i in \
                         $(egrep -v '^#.*' /etc/nsswitch.conf|cut -f2 -d :\
                          |fgrep -v NOTFOUND); do \
                         echo "libnss_${i}.so";\
                     done|sort -u); do \
              echo -n "|$j";\
          done)
nsslibs=${nsslibs##|}

dracut_install $(for i in $(ls {/usr,}$LIBDIR/libnss*.so 2>/dev/null); do echo $i;done | egrep "$nsslibs")

inst_hook cmdline 90 "$moddir/parse-nfsroot.sh"
inst_hook pre-pivot 70 "$moddir/nfsroot-cleanup.sh"
inst "$moddir/nfsroot" "/sbin/nfsroot"
mkdir -p "$initdir/var/lib/nfs/rpc_pipefs"
mkdir -p "$initdir/var/lib/rpcbind"
mkdir -p "$initdir/var/lib/nfs/statd/sm"

# Rather than copy the passwd file in, just set a user for rpcbind
# We'll save the state and restart the daemon from the root anyway
egrep '^nobody:' /etc/passwd >> "$initdir/etc/passwd"
egrep '^nfsnobody:' /etc/passwd >> "$initdir/etc/passwd"
egrep '^rpc:' /etc/passwd >> "$initdir/etc/passwd"
egrep '^rpcuser:' /etc/passwd >> "$initdir/etc/passwd"
#which nologin >/dev/null 2>&1 && dracut_install nologin

# rpc user needs to be able to write to this directory to save the warmstart
# file
chmod 777 "$initdir/var/lib/rpcbind"
