pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client.bash - simple Cygwin frontent for the msnfsv41 NFSv4.1 filesystem driver
Posted by Anonymous on Thu 28th Sep 2023 14:28
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. # 1. Mount for current users:
  16. # (requires PsExec from https://download.sysinternals.com/files/PSTools.zip
  17. # in /home/roland_mainz/work/win_pstools/)
  18. # * Usage:
  19. # Shell1: cd /cygdrive/c/Users/roland_mainz/Downloads/ms-nfs41-client-x64/ms-nfs41-client-x64 && bash ../msnfs41client.bash run_deamon
  20. # Shell2: cd /cygdrive/c/Users/roland_mainz/Downloads/ms-nfs41-client-x64/ms-nfs41-client-x64 && bash ../msnfs41client.bash mount_homedir
  21. #
  22. # 2. Mount for all users:
  23. # * Requires:
  24. # - Windows admin rights (Cygwin --> Run terminal as Adminstrator)
  25. # - PsExec from https://download.sysinternals.com/files/PSTools.zip in /home/roland_mainz/work/win_pstools/)
  26. # * Usage:
  27. # Shell1: cd /cygdrive/c/Users/roland_mainz/Downloads/ms-nfs41-client-x64/ms-nfs41-client-x64 && bash ../msnfs41client.bash sys_run_deamon
  28. # Shell2: cd /cygdrive/c/Users/roland_mainz/Downloads/ms-nfs41-client-x64/ms-nfs41-client-x64 && bash ../msnfs41client.bash sys_mount_homedir
  29. #
  30.  
  31. function is_windows_admin_account
  32. {
  33.         #
  34.         # Test whether we have the Windows permissions to install DLLs
  35.         # and the kernel module
  36.         #
  37.         # Usually Windows Adminstrator rights are indicated by the
  38.         # membership in group "544(Administratoren)" (Cygwin maps
  39.         # "SID S-1-5-32-544" to GID 544)
  40.         #
  41.         if [[ "$(id -G)" =~ (^|[[:space:]]+)544([[:space:]]+|$) ]] ; then
  42.                 return 0
  43.         fi
  44.         return 1
  45. }
  46.  
  47. function nfsclient_install
  48. {
  49.         set -o nounset
  50.         set -o xtrace
  51.         set -o errexit
  52.  
  53.         if ! is_windows_admin_account ; then
  54.                 printf $"%s: Install requires Windows Adminstator permissions.\n" "$0"
  55.                 return 1
  56.         fi
  57.  
  58.         # make sure all binaries are executable, Windows cmd does
  59.         # not care, but Cygwin&bash do.
  60.         # If *.ddl are not executable nfs*.exe fail with 0xc0000022
  61.         chmod a+x *.exe *.dll
  62.  
  63.         if false ; then
  64.                 # install.bat needs PATH to include $PWD
  65.                 PATH="$PWD:$PATH" cmd /c install.bat
  66.         else
  67.                 nfs_install
  68.                 rundll32 setupapi.dll,InstallHinfSection DefaultInstall 132 ./nfs41rdr.inf
  69.         fi
  70.  
  71.         cp etc_netconfig /cygdrive/c/etc/netconfig
  72.         cp ms-nfs41-idmap.conf /cygdrive/c/etc/.
  73.  
  74.         bcdedit /set testsigning on
  75.         regtool -s set '/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Tcpip/Parameters/Domain' 'GLOBAL.LOC'
  76.  
  77.         sc query Dfsc
  78.         sc stop Dfsc || true
  79.         sc config Dfsc start=disabled
  80.  
  81.         sc query nfs41_driver
  82.         domainname
  83.  
  84.         # check whether the driver really has been installed
  85.         md5sum \
  86.                 "$PWD/nfs41_driver.sys" \
  87.                 '/cygdrive/c/Windows/System32/drivers/nfs41_driver.sys'
  88.  
  89.         return 0
  90. }
  91.  
  92. function nfsclient_rundeamon
  93. {
  94.         set -o xtrace
  95.         set -o nounset
  96.  
  97.         nfsd_debug -d 0 --noldap --gid 1616 --uid 1616
  98.         return $?
  99. }
  100.  
  101. function nfsclient_system_rundeamon
  102. {
  103.         set -o xtrace
  104.         set -o nounset
  105.  
  106.         su_system nfsd_debug -d 0 --noldap --gid 1616 --uid 1616
  107.         return $?
  108. }
  109.  
  110. function nfsclient_mount_homedir
  111. {
  112.         set -o xtrace
  113.         set -o nounset
  114.         set -o errexit
  115.  
  116.         #nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz'
  117.         # fixme: Specifying IPv6 addresses do not work yet, as soon as
  118.         # they come as UNC paths (e.g.
  119.         # $ cd '//[fe80::219:99ff:feae:73ce]@2049/nfs4/export/home/rmainz' #
  120.         # they get corrupted once they arrive in nfsd_debug.exe)
  121.         #nfs_mount -p -o sec=sys H '[fe80::219:99ff:feae:73ce]:/export/home/rmainz'
  122.         nfs_mount -p -o sec=sys H 'derfwpc5131_ipv6:/export/home/rmainz'
  123.         mkdir -p '/home/rmainz'
  124.         mount -o bind,posix=1 '/cygdrive/h' '/home/rmainz'
  125.         return $?
  126. }
  127.  
  128. function nfsclient_system_mount_homedir
  129. {
  130.         set -o xtrace
  131.         set -o nounset
  132.         set -o errexit
  133.  
  134.         #su_system nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz'
  135.         # fixme: Specifying IPv6 addresses do not work yet, as soon as
  136.         # they come as UNC paths (e.g.
  137.         # $ cd '//[fe80::219:99ff:feae:73ce]@2049/nfs4/export/home/rmainz' #
  138.         # they get corrupted once they arrive in nfsd_debug.exe)
  139.         #su_system nfs_mount -p -o sec=sys H '[fe80::219:99ff:feae:73ce]:/export/home/rmainz'
  140.         su_system nfs_mount -p -o sec=sys H 'derfwpc5131_ipv6:/export/home/rmainz'
  141.  
  142.         return $?
  143. }
  144.  
  145. function nfsclient_umount_homedir
  146. {
  147.         set -o xtrace
  148.         set -o nounset
  149.         typeset -i res
  150.  
  151.         nfs_mount -d H
  152.         (( res=$? ))
  153.  
  154.         if (( res == 0 )) ; then
  155.                 # remove bind mount
  156.                 umount '/home/rmainz' && rmdir '/home/rmainz'
  157.         fi
  158.  
  159.         return $res
  160. }
  161.  
  162. function require_cmd
  163. {
  164.         typeset cmd="$1"
  165.  
  166.         if ! which "$cmd" >'/dev/null' 2>&1 ; then
  167.                 printf $"%s: %q not found in %q\n" "$0" "$cmd" "$PWD" 1>&2
  168.                 return 1
  169.         fi
  170.         return 0
  171. }
  172.  
  173. # execute cmd as Windows user "SYSTEM"
  174. function su_system
  175. {
  176.         typeset cmd="$1"
  177.         shift
  178.        
  179.         typeset abspath_cmd="$(which "$cmd")"
  180.         if [[ ! -x "$abspath_cmd" ]] ; then
  181.                 printf "%s: Command %q not found." $"su_system" "$abspath_cmd" 1>&2
  182.                 return 127
  183.         fi
  184.  
  185.         PsExec \
  186.                 -accepteula -nobanner \
  187.                 -s \
  188.                 -w "$(cygpath -w "$PWD")" \
  189.                 "$(cygpath -w "$abspath_cmd")" "$@"
  190. }
  191.  
  192. function sys_terminal
  193. {
  194.         # su_system does not work, mintty requires PsExec -i
  195.         PsExec -accepteula -nobanner \
  196.                 -i \
  197.                 -s -w "$(cygpath -w "$PWD")" \
  198.                 'C:\cygwin64\bin\mintty.exe'
  199. }
  200.  
  201. function main
  202. {
  203.         typeset cmd="$1"
  204.  
  205.         # "$PATH:/usr/bin:/bin" is used for PsExec where $PATH might be empty
  206.         export PATH="$PWD:$PATH:/usr/bin:/bin"
  207.        
  208.         # my own path to pstools
  209.         PATH+=':/home/roland_mainz/work/win_pstools/'
  210.  
  211.         case "$cmd" in
  212.                 'install')
  213.                         nfsclient_install
  214.                         return $?
  215.                         ;;
  216.                 'run_deamon' | 'run_daemon')
  217.                         require_cmd 'nfsd.exe' || return 1
  218.                         require_cmd 'nfsd_debug.exe' || return 1
  219.                         require_cmd 'nfs_mount.exe' || return 1
  220.                         nfsclient_rundeamon
  221.                         return $?
  222.                         ;;
  223.                 'sys_run_deamon' | 'sys_run_daemon')
  224.                         require_cmd 'PsExec.exe' || return 1
  225.                         require_cmd 'nfsd.exe' || return 1
  226.                         require_cmd 'nfsd_debug.exe' || return 1
  227.                         require_cmd 'nfs_mount.exe' || return 1
  228.                         if ! is_windows_admin_account ; then
  229.                                 printf $"%s: %q requires Windows Adminstator permissions.\n" "$0" "$cmd"
  230.                                 return 1
  231.                         fi
  232.                         nfsclient_system_rundeamon
  233.                         return $?
  234.                         ;;
  235.                 'sys_mount_homedir')
  236.                         require_cmd 'nfs_mount.exe' || return 1
  237.                         if ! is_windows_admin_account ; then
  238.                                 printf $"%s: %q requires Windows Adminstator permissions.\n" "$0" "$cmd"
  239.                                 return 1
  240.                         fi
  241.                         nfsclient_system_mount_homedir
  242.                         return $?
  243.                         ;;
  244.                 'mount_homedir')
  245.                         require_cmd 'nfs_mount.exe' || return 1
  246.                         nfsclient_mount_homedir
  247.                         return $?
  248.                         ;;
  249.                 'umount_homedir')
  250.                         require_cmd 'nfs_mount.exe' || return 1
  251.                         nfsclient_umount_homedir
  252.                         return $?
  253.                         ;;
  254.                 # misc
  255.                 'sys_terminal')
  256.                         require_cmd 'mintty.exe' || return 1
  257.                         if ! is_windows_admin_account ; then
  258.                                 printf $"%s: %q requires Windows Adminstator permissions.\n" "$0" "$cmd"
  259.                                 return 1
  260.                         fi
  261.                         sys_terminal
  262.                         return $?
  263.                         ;;
  264.                 *)
  265.                         printf $"%s: Unknown cmd %q\n" "$0" "$cmd" 1>&2
  266.                         return 1
  267.                         ;;
  268.         esac
  269.         return 1
  270. }
  271.  
  272.  
  273. #
  274. # main
  275. #
  276. main "$@"
  277. exit $?
  278.  
  279. # 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