Difference between
modified post 7d0b by Anonymous on Tue 19th Sep 2023 17:07
original post a9d38b by Anonymous on Fri 15th Sep 2023 16:48
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 | 71 | cp etc_netconfig /cygdrive/c/etc/netconfig | |
| 72 | 72 | cp ms-nfs41-idmap.conf /cygdrive/c/etc/. | |
| 73 | 73 | ||
| 74 | 74 | bcdedit /set testsigning on | |
| 75 | 75 | regtool -s set '/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Tcpip/Parameters/Domain' 'GLOBAL.LOC' | |
| 76 | 76 | ||
| 77 | 77 | sc query Dfsc | |
| 78 | 78 | sc stop Dfsc || true | |
| 79 | 79 | sc config Dfsc start=disabled | |
| 80 | 80 | ||
| 81 | 81 | sc query nfs41_driver | |
| 82 | 82 | domainname | |
| 83 | 83 | ||
| 84 | 84 | # check whether the driver really has been installed | |
| 85 | 85 | md5sum \ | |
| 86 | 86 | "$PWD/nfs41_driver.sys" \ | |
| 87 | - | /cygdrive/c/Windows/System32/drivers/nfs41_driver.sys | |
| 87 | + | '/cygdrive/c/Windows/System32/drivers/nfs41_driver.sys' | |
| 88 | 88 | ||
| 89 | 89 | return 0 | |
| 90 | 90 | } | |
| 91 | 91 | ||
| 92 | 92 | function nfsclient_rundeamon | |
| 93 | 93 | { | |
| 94 | 94 | set -o xtrace | |
| 95 | 95 | set -o nounset | |
| 96 | 96 | ||
| 97 | - | nfsd_debug -d 0 --noldap --gid 1616 --uid 1616 | |
| 97 | + | nfsd_debug -d 2 --noldap --gid 1616 --uid 1616 | |
| 98 | 98 | return $? | |
| 99 | 99 | } | |
| 100 | 100 | ||
| 101 | 101 | function nfsclient_system_rundeamon | |
| 102 | 102 | { | |
| 103 | 103 | set -o xtrace | |
| 104 | 104 | set -o nounset | |
| 105 | 105 | ||
| 106 | - | su_system nfsd_debug -d 0 --noldap --gid 1616 --uid 1616 | |
| 106 | + | su_system nfsd_debug -d 2 --noldap --gid 1616 --uid 1616 | |
| 107 | 107 | return $? | |
| 108 | 108 | } | |
| 109 | 109 | ||
| 110 | 110 | function nfsclient_mount_homedir | |
| 111 | 111 | { | |
| 112 | 112 | set -o xtrace | |
| 113 | 113 | set -o nounset | |
| 114 | 114 | set -o errexit | |
| 115 | 115 | ||
| 116 | 116 | nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz' | |
| 117 | - | mkdir -p /home/rmainz | |
| 117 | + | mkdir -p '/home/rmainz' | |
| 118 | - | mount -o bind,posix=1 /cygdrive/h /home/rmainz | |
| 118 | + | mount -o bind,posix=1 '/cygdrive/h' '/home/rmainz' | |
| 119 | 119 | return $? | |
| 120 | 120 | } | |
| 121 | 121 | ||
| 122 | 122 | function nfsclient_system_mount_homedir | |
| 123 | 123 | { | |
| 124 | 124 | set -o xtrace | |
| 125 | 125 | set -o nounset | |
| 126 | 126 | set -o errexit | |
| 127 | 127 | ||
| 128 | 128 | su_system nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz' | |
| 129 | 129 | ||
| 130 | 130 | return $? | |
| 131 | 131 | } | |
| 132 | 132 | ||
| 133 | 133 | function nfsclient_umount_homedir | |
| 134 | 134 | { | |
| 135 | 135 | set -o xtrace | |
| 136 | 136 | set -o nounset | |
| 137 | 137 | typeset -i res | |
| 138 | 138 | ||
| 139 | 139 | nfs_mount -d H | |
| 140 | 140 | (( res=$? )) | |
| 141 | 141 | ||
| 142 | 142 | if (( res == 0 )) ; then | |
| 143 | 143 | # remove bind mount | |
| 144 | - | umount /home/rmainz | |
| 144 | + | umount '/home/rmainz' && rmdir '/home/rmainz' | |
| 145 | 145 | fi | |
| 146 | 146 | ||
| 147 | 147 | return $res | |
| 148 | 148 | } | |
| 149 | 149 | ||
| 150 | 150 | function require_cmd | |
| 151 | 151 | { | |
| 152 | 152 | typeset cmd="$1" | |
| 153 | 153 | ||
| 154 | 154 | if ! which "$cmd" >'/dev/null' 2>&1 ; then | |
| 155 | 155 | printf $"%s: %q not found in %q\n" "$0" "$cmd" "$PWD" 1>&2 | |
| 156 | 156 | return 1 | |
| 157 | 157 | fi | |
| 158 | 158 | return 0 | |
| 159 | 159 | } | |
| 160 | 160 | ||
| 161 | 161 | # execute cmd as Windows user "SYSTEM" | |
| 162 | 162 | function su_system | |
| 163 | 163 | { | |
| 164 | 164 | typeset cmd="$1" | |
| 165 | 165 | shift | |
| 166 | 166 | ||
| 167 | 167 | typeset abspath_cmd="$(which "$cmd")" | |
| 168 | 168 | if [[ ! -x "$abspath_cmd" ]] ; then | |
| 169 | 169 | printf "%s: Command %q not found." $"su_system" "$abspath_cmd" 1>&2 | |
| 170 | 170 | return 127 | |
| 171 | 171 | fi | |
| 172 | 172 | ||
| 173 | 173 | PsExec \ | |
| 174 | 174 | -accepteula -nobanner \ | |
| 175 | 175 | -s \ | |
| 176 | 176 | -w "$(cygpath -w "$PWD")" \ | |
| 177 | 177 | "$(cygpath -w "$abspath_cmd")" "$@" | |
| 178 | 178 | } | |
| 179 | 179 | ||
| 180 | 180 | function main | |
| 181 | 181 | { | |
| 182 | 182 | typeset cmd="$1" | |
| 183 | 183 | ||
| 184 | 184 | # "$PATH:/usr/bin:/bin" is used for PsExec where $PATH might be empty | |
| 185 | 185 | export PATH="$PWD:$PATH:/usr/bin:/bin" | |
| 186 | 186 | ||
| 187 | 187 | # my own path to pstools | |
| 188 | 188 | PATH+=':/home/roland_mainz/work/win_pstools/' | |
| 189 | 189 | ||
| 190 | 190 | case "$cmd" in | |
| 191 | 191 | 'install') | |
| 192 | 192 | nfsclient_install | |
| 193 | 193 | return $? | |
| 194 | 194 | ;; | |
| 195 | 195 | 'run_deamon' | 'run_daemon') | |
| 196 | 196 | require_cmd 'nfsd.exe' || return 1 | |
| 197 | 197 | require_cmd 'nfsd_debug.exe' || return 1 | |
| 198 | 198 | require_cmd 'nfs_mount.exe' || return 1 | |
| 199 | 199 | nfsclient_rundeamon | |
| 200 | 200 | return $? | |
| 201 | 201 | ;; | |
| 202 | 202 | 'sys_run_deamon' | 'sys_run_daemon') | |
| 203 | 203 | require_cmd 'PsExec.exe' || return 1 | |
| 204 | 204 | require_cmd 'nfsd.exe' || return 1 | |
| 205 | 205 | require_cmd 'nfsd_debug.exe' || return 1 | |
| 206 | 206 | require_cmd 'nfs_mount.exe' || return 1 | |
| 207 | 207 | is_windows_admin_account || return 1 | |
| 208 | 208 | nfsclient_system_rundeamon | |
| 209 | 209 | return $? | |
| 210 | 210 | ;; | |
| 211 | 211 | 'sys_mount_homedir') | |
| 212 | 212 | require_cmd 'nfs_mount.exe' || return 1 | |
| 213 | 213 | is_windows_admin_account || return 1 | |
| 214 | 214 | nfsclient_system_mount_homedir | |
| 215 | 215 | return $? | |
| 216 | 216 | ;; | |
| 217 | 217 | 'mount_homedir') | |
| 218 | 218 | require_cmd 'nfs_mount.exe' || return 1 | |
| 219 | 219 | nfsclient_mount_homedir | |
| 220 | 220 | return $? | |
| 221 | 221 | ;; | |
| 222 | 222 | 'umount_homedir') | |
| 223 | 223 | require_cmd 'nfs_mount.exe' || return 1 | |
| 224 | 224 | nfsclient_umount_homedir | |
| 225 | 225 | return $? | |
| 226 | 226 | ;; | |
| 227 | 227 | *) | |
| 228 | 228 | printf $"%s: Unknown cmd %q\n" "$0" "$cmd" 1>&2 | |
| 229 | 229 | return 1 | |
| 230 | 230 | ;; | |
| 231 | 231 | esac | |
| 232 | 232 | return 1 | |
| 233 | 233 | } | |
| 234 | 234 | ||
| 235 | + | ||
| 235 | 236 | # | |
| 236 | 237 | # main | |
| 237 | 238 | # | |
| 238 | 239 | main "$@" | |
| 239 | 240 | exit $? | |
| 240 | 241 | ||
| 241 | 242 | # EOF. | |
| 242 | 243 |
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