pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client.bash - simple Cygwin frontent for the msnfsv41 NFSv4.1 filesystem driver
Posted by Anonymous on Fri 15th Sep 2023 14:47
raw | new post
view followups (newest first): msnfs41client.bash - simple Cygwin frontent for the msnfsv41 NFSv4.1 filesystem driver by Anonymous
modification of post by Anonymous (view diff)

  1. #!/bin/bash
  2.  
  3. #
  4. # msnfs41client.bash - simple Cygwin frontent for the msnfsv41
  5. # NFSv4.1 filesystem driver
  6. #
  7.  
  8. #
  9. # Written by Roland Mainz <roland.mainz@nrubsig.org>
  10. #
  11.  
  12. #
  13. # Examples:
  14. #
  15. # 2. Mount for all users:
  16. # (requires PsExec from https://download.sysinternals.com/files/PSTools.zip
  17. # in /home/roland_mainz/work/win_pstools/)
  18. # Shell1: cd /cygdrive/c/Users/roland_mainz/Downloads/ms-nfs41-client-x64/ms-nfs41-client-x64 && /home/roland_mainz/work/win_pstools/PsExec -s -w $(cygpath -w "$PWD") $(cygpath -w /usr/bin/bash) "$PWD/../msnfs41client.bash" run_deamon
  19. # Shell2: (cd /cygdrive/c/Users/roland_mainz/Downloads/ms-nfs41-client-x64/ms-nfs41-client-x64 && /home/roland_mainz/work/win_pstools/PsExec -s -w $(cygpath -w "$PWD") $(cygpath -w /usr/bin/bash) "$PWD/../msnfs41client.bash" mount_homedir)
  20. #
  21.  
  22. function nfsclient_install
  23. {
  24.         set -o nounset
  25.         set -o xtrace
  26.         set -o errexit
  27.  
  28.         #
  29.         # Test whether we have the Windows permissions to install DLLs
  30.         # and the kernel module
  31.         #
  32.         # Usually Windows Adminstrator rights are indicated by the
  33.         # membership in group "544(Administratoren)" (Cygwin maps
  34.         # "SID S-1-5-32-544" to GID 544)
  35.         #
  36.         if ! [[ "$(id -G)" =~ (^|[[:space:]]+)544([[:space:]]+|$) ]] ; then
  37.                 printf $"%s: Install requires Windows Adminstator permissions.\n" "$0"
  38.                 return 1
  39.         fi
  40.  
  41.         # make sure all binaries are executable, Windows cmd does
  42.         # not care, but Cygwin&bash do.
  43.         # If *.ddl are not executable nfs*.exe fail with 0xc0000022
  44.         chmod a+x *.exe *.dll
  45.  
  46.         if false ; then
  47.                 # install.bat needs PATH to include $PWD
  48.                 PATH="$PWD:$PATH" cmd /c install.bat
  49.         else
  50.                 nfs_install
  51.                 rundll32 setupapi.dll,InstallHinfSection DefaultInstall 132 ./nfs41rdr.inf
  52.         fi
  53.  
  54.         cp etc_netconfig /cygdrive/c/etc/netconfig
  55.         cp ms-nfs41-idmap.conf /cygdrive/c/etc/.
  56.  
  57.         bcdedit /set testsigning on
  58.         regtool -s set '/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Tcpip/Parameters/Domain' 'GLOBAL.LOC'
  59.  
  60.         sc query Dfsc
  61.         sc stop Dfsc || true
  62.         sc config Dfsc start=disabled
  63.  
  64.         sc query nfs41_driver
  65.         domainname
  66.  
  67.         # check whether the driver really has been installed
  68.         md5sum \
  69.                 "$PWD/nfs41_driver.sys" \
  70.                 /cygdrive/c/Windows/System32/drivers/nfs41_driver.sys
  71.  
  72.         return 0
  73. }
  74.  
  75. function nfsclient_rundeamon
  76. {
  77.         set -o xtrace
  78.         set -o nounset
  79.  
  80.         nfsd_debug -d 2 --noldap --gid 1616 --uid 1616
  81.         return $?
  82. }
  83.  
  84. function nfsclient_mount_homedir
  85. {
  86.         set -o xtrace
  87.         set -o nounset
  88.         set -o errexit
  89.  
  90.         nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz'
  91.         mkdir -p /home/rmainz
  92.         mount -o bind,posix=1 /cygdrive/h /home/rmainz
  93.         return $?
  94. }
  95.  
  96. function nfsclient_umount_homedir
  97. {
  98.         set -o xtrace
  99.         set -o nounset
  100.         typeset -i res
  101.  
  102.         nfs_mount -d H
  103.         (( res=$? ))
  104.  
  105.         if (( res == 0 )) ; then
  106.                 # remove bind mount
  107.                 umount /home/rmainz
  108.         fi
  109.  
  110.         return $res
  111. }
  112.  
  113. function main
  114. {
  115.         typeset cmd="$1"
  116.  
  117.         # "$PATH:/usr/bin:/bin" is used for PsExec where $PATH might be empty
  118.         export PATH="$PWD:$PATH:/usr/bin:/bin"
  119.  
  120.         if [[ "$cmd" != 'install' ]] ; then
  121.                 if ! which 'nfsd.exe' >/dev/null 2>&1 ; then
  122.                         printf $"%s: nfsd not found in %q\n" "$0" "$PWD" 1>&2
  123.                         return 1
  124.                 fi
  125.                 if ! which 'nfs_mount.exe' >/dev/null 2>&1 ; then
  126.                         printf $"%s: nfs_mount not found in %q\n" "$0" "$PWD" 1>&2
  127.                         return 1
  128.                 fi
  129.         fi
  130.  
  131.         case "$cmd" in
  132.                 'install')
  133.                         nfsclient_install
  134.                         return $?
  135.                         ;;
  136.                 'run_deamon' | 'run_daemon')
  137.                         nfsclient_rundeamon
  138.                         return $?
  139.                         ;;
  140.                 'mount_homedir')
  141.                         nfsclient_mount_homedir
  142.                         return $?
  143.                         ;;
  144.                 'umount_homedir')
  145.                         nfsclient_umount_homedir
  146.                         return $?
  147.                         ;;
  148.                 *)
  149.                         printf $"%s: Unknown cmd %q\n" "$0" "$cmd" 1>&2
  150.                         return 1
  151.                         ;;
  152.         esac
  153.         return 1
  154. }
  155.  
  156. main "$@"
  157. exit $?
  158.  
  159. # EOF.

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at