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