#!/bin/bash
#
#NFSD=utils/nfsd/nfsd
#NFSDCTL=utils/nfsdctl/nfsdctl
NFSD=/usr/sbin/rpc.nfsd
NFSDCTL=/usr/sbin/nfsdctl
NFSDRES=$(mktemp /tmp/nfsd.XXXXXX)
NFSDCTLRES=$(mktemp /tmp/nfsdctl.XXXXXX)

cleanup()
{
	reset
	rm -f $NFSDRES $NFSDCTLRES
}

reset()
{
	$NFSDCTL threads 0
	echo "+3 +4 +4.0 +4.1 +4.2" >/proc/fs/nfsd/versions
}

check()
{
	$NFSDCTL threads 0
	$NFSD 16
	$NFSDCTL version >$NFSDRES
	$NFSDCTL threads 0
	$NFSDCTL autostart
	$NFSDCTL version >$NFSDCTLRES
	echo
	echo "/etc/nfs.conf:"
	cat /etc/nfs.conf
	echo
	echo -n "nfsd:    "
	cat $NFSDRES
	echo -n "nfsdctl: "
	cat $NFSDCTLRES
	if ! diff -q $NFSDRES $NFSDCTLRES; then
		exit 1
	fi
	echo
}

trap cleanup EXIT INT

i=0
for c3 in \  \#; do
  for v3 in n y; do
    for c4 in \  \#; do
      for v4 in n y; do
        for c40 in \  \#; do
          for v40 in n y; do
            for c41 in \  \#; do
              for v41 in n y; do
                for c42 in \  \#; do
                  for v42 in n y; do
                    (( i++ ))
                    echo -e "test $i: ${c3}vers3=$v3 ${c4}vers4=$v4 ${c40}vers4.0=$v40 ${c41}vers4.1=$v41 ${c42}vers4.2=$v42"
                    echo -e "[nfsd]\n${c3}vers3=$v3\n${c4}vers4=$v4\n${c40}vers4.0=$v40\n${c41}vers4.1=$v41\n${c42}vers4.2=$v42" >/etc/nfs.conf
		    reset
                    check
		  done
		done
              done
	    done
	  done
	done
      done
    done
  done
done
