Difference between
modified post a9d38b by Anonymous on Fri 15th Sep 2023 16:48
original post 9b7ceecb8 by Anonymous on Fri 15th Sep 2023 14:47
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 | + | # 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 | - | # 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 | |
| 18 | + | # * Usage: | |
| 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) | |
| 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 | |
| 20 | 21 | # | |
| 22 | + | # 2. Mount for all users: | |
| 21 | 30 | ||
| 22 | - | function nfsclient_install | |
| 31 | + | function is_windows_admin_account | |
| 23 | 32 | { | |
| 28 | 33 | # | |
| 29 | 34 | # Test whether we have the Windows permissions to install DLLs | |
| 30 | 35 | # and the kernel module | |
| 31 | 36 | # | |
| 32 | 37 | # Usually Windows Adminstrator rights are indicated by the | |
| 33 | 38 | # membership in group "544(Administratoren)" (Cygwin maps | |
| 34 | 39 | # "SID S-1-5-32-544" to GID 544) | |
| 35 | 40 | # | |
| 36 | - | if ! [[ "$(id -G)" =~ (^|[[:space:]]+)544([[:space:]]+|$) ]] ; then | |
| 41 | + | if [[ "$(id -G)" =~ (^|[[:space:]]+)544([[:space:]]+|$) ]] ; then | |
| 37 | - | printf $"%s: Install requires Windows Adminstator permissions.\n" "$0" | |
| 42 | + | return 0 | |
| 39 | 43 | fi | |
| 44 | + | return 1 | |
| 40 | 46 | ||
| 41 | - | # make sure all binaries are executable, Windows cmd does | |
| 47 | + | function nfsclient_install | |
| 42 | - | # not care, but Cygwin&bash do. | |
| 48 | + | { | |
| 43 | - | # If *.ddl are not executable nfs*.exe fail with 0xc0000022 | |
| 49 | + | set -o nounset | |
| 44 | - | chmod a+x *.exe *.dll | |
| 50 | + | set -o xtrace | |
| 51 | + | set -o errexit | |
| 45 | 52 | ||
| 46 | - | if false ; then | |
| 53 | + | if ! is_windows_admin_account ; then | |
| 47 | - | # install.bat needs PATH to include $PWD | |
| 54 | + | printf $"%s: Install requires Windows Adminstator permissions.\n" "$0" | |
| 48 | - | PATH="$PWD:$PATH" cmd /c install.bat | |
| 55 | + | return 1 | |
| 52 | 56 | fi | |
| 53 | 57 | ||
| 54 | - | cp etc_netconfig /cygdrive/c/etc/netconfig | |
| 58 | + | # make sure all binaries are executable, Windows cmd does | |
| 55 | - | cp ms-nfs41-idmap.conf /cygdrive/c/etc/. | |
| 59 | + | # not care, but Cygwin&bash do. | |
| 60 | + | # If *.ddl are not executable nfs*.exe fail with 0xc0000022 | |
| 56 | 62 | ||
| 57 | - | bcdedit /set testsigning on | |
| 63 | + | if false ; then | |
| 58 | - | regtool -s set '/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Tcpip/Parameters/Domain' 'GLOBAL.LOC' | |
| 64 | + | # install.bat needs PATH to include $PWD | |
| 65 | + | PATH="$PWD:$PATH" cmd /c install.bat | |
| 59 | 70 | ||
| 71 | + | cp etc_netconfig /cygdrive/c/etc/netconfig | |
| 63 | 73 | ||
| 74 | + | bcdedit /set testsigning on | |
| 66 | 76 | ||
| 77 | + | sc query Dfsc | |
| 71 | 80 | ||
| 81 | + | sc query nfs41_driver | |
| 74 | 83 | ||
| 84 | + | # check whether the driver really has been installed | |
| 79 | 88 | ||
| 80 | - | nfsd_debug -d 2 --noldap --gid 1616 --uid 1616 | |
| 89 | + | return 0 | |
| 82 | 90 | } | |
| 83 | 91 | ||
| 84 | - | function nfsclient_mount_homedir | |
| 92 | + | function nfsclient_rundeamon | |
| 85 | 93 | { | |
| 86 | 94 | set -o xtrace | |
| 87 | 95 | set -o nounset | |
| 89 | 96 | ||
| 90 | - | nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz' | |
| 97 | + | nfsd_debug -d 0 --noldap --gid 1616 --uid 1616 | |
| 93 | 98 | return $? | |
| 94 | 99 | } | |
| 95 | 100 | ||
| 96 | - | function nfsclient_umount_homedir | |
| 101 | + | function nfsclient_system_rundeamon | |
| 97 | 102 | { | |
| 98 | 103 | set -o xtrace | |
| 99 | 104 | set -o nounset | |
| 101 | 105 | ||
| 102 | - | nfs_mount -d H | |
| 106 | + | su_system nfsd_debug -d 0 --noldap --gid 1616 --uid 1616 | |
| 103 | - | (( res=$? )) | |
| 107 | + | return $? | |
| 108 | + | } | |
| 104 | 109 | ||
| 105 | - | if (( res == 0 )) ; then | |
| 110 | + | function nfsclient_mount_homedir | |
| 111 | + | { | |
| 109 | 115 | ||
| 110 | - | return $res | |
| 116 | + | nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz' | |
| 117 | + | mkdir -p /home/rmainz | |
| 111 | 120 | } | |
| 112 | 121 | ||
| 113 | - | function main | |
| 122 | + | function nfsclient_system_mount_homedir | |
| 114 | 123 | { | |
| 115 | - | typeset cmd="$1" | |
| 124 | + | set -o xtrace | |
| 125 | + | set -o nounset | |
| 116 | 127 | ||
| 117 | - | # "$PATH:/usr/bin:/bin" is used for PsExec where $PATH might be empty | |
| 128 | + | su_system nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz' | |
| 119 | 129 | ||
| 120 | - | if [[ "$cmd" != 'install' ]] ; then | |
| 130 | + | return $? | |
| 121 | - | if ! which 'nfsd.exe' >/dev/null 2>&1 ; then | |
| 131 | + | } | |
| 130 | 132 | ||
| 131 | - | case "$cmd" in | |
| 133 | + | function nfsclient_umount_homedir | |
| 132 | - | 'install') | |
| 134 | + | { | |
| 133 | - | nfsclient_install | |
| 135 | + | set -o xtrace | |
| 134 | - | return $? | |
| 136 | + | set -o nounset | |
| 135 | - | ;; | |
| 137 | + | typeset -i res | |
| 136 | - | 'run_deamon' | 'run_daemon') | |
| 138 | + | ||
| 137 | - | nfsclient_rundeamon | |
| 139 | + | nfs_mount -d H | |
| 138 | - | return $? | |
| 140 | + | (( res=$? )) | |
| 139 | - | ;; | |
| 141 | + | ||
| 140 | - | 'mount_homedir') | |
| 142 | + | if (( res == 0 )) ; then | |
| 141 | - | nfsclient_mount_homedir | |
| 143 | + | # remove bind mount | |
| 142 | - | return $? | |
| 144 | + | umount /home/rmainz | |
| 143 | - | ;; | |
| 145 | + | fi | |
| 144 | - | 'umount_homedir') | |
| 146 | + | ||
| 145 | - | nfsclient_umount_homedir | |
| 147 | + | return $res | |
| 154 | 148 | } | |
| 155 | 149 | ||
| 156 | - | main "$@" | |
| 150 | + | function require_cmd | |
| 157 | - | exit $? | |
| 151 | + | { | |
| 152 | + | typeset cmd="$1" | |
| 158 | 153 | ||
| 159 | - | # EOF. | |
| 154 | + | if ! which "$cmd" >'/dev/null' 2>&1 ; then | |
| 160 | - | ||
| 155 | + | printf $"%s: %q not found in %q\n" "$0" "$cmd" "$PWD" 1>&2 | |
| 161 | - | ||
| 156 | + | return 1 | |
| 162 | - | ||
| 157 | + | fi | |
| 163 | - | ||
| 158 | + | return 0 | |
| 164 | - | ||
| 159 | + | } | |
| 165 | 160 | ||
| 166 | - | ||
| 161 | + | # execute cmd as Windows user "SYSTEM" | |
| 167 | - | ||
| 162 | + | function su_system | |
| 168 | - | ||
| 163 | + | { | |
| 169 | - | ||
| 164 | + | typeset cmd="$1" | |
| 170 | - | ||
| 165 | + | shift | |
| 171 | 166 | ||
| 172 | - | ||
| 167 | + | typeset abspath_cmd="$(which "$cmd")" | |
| 173 | - | ||
| 168 | + | if [[ ! -x "$abspath_cmd" ]] ; then | |
| 174 | - | ||
| 169 | + | printf "%s: Command %q not found." $"su_system" "$abspath_cmd" 1>&2 | |
| 175 | - | ||
| 170 | + | return 127 | |
| 176 | - | ||
| 171 | + | fi | |
| 177 | 172 | ||
| 178 | - | ||
| 173 | + | PsExec \ | |
| 179 | - | ||
| 174 | + | -accepteula -nobanner \ | |
| 180 | - | ||
| 175 | + | -s \ | |
| 181 | - | ||
| 176 | + | -w "$(cygpath -w "$PWD")" \ | |
| 182 | - | ||
| 177 | + | "$(cygpath -w "$abspath_cmd")" "$@" | |
| 183 | - | ||
| 178 | + | } | |
| 184 | 179 | ||
| 185 | - | ||
| 180 | + | function main | |
| 186 | - | ||
| 181 | + | { | |
| 187 | - | ||
| 182 | + | typeset cmd="$1" | |
| 188 | 183 | ||
| 189 | - | ||
| 184 | + | # "$PATH:/usr/bin:/bin" is used for PsExec where $PATH might be empty | |
| 190 | - | ||
| 185 | + | export PATH="$PWD:$PATH:/usr/bin:/bin" | |
| 191 | 186 | ||
| 192 | - | ||
| 187 | + | # my own path to pstools | |
| 193 | - | ||
| 188 | + | PATH+=':/home/roland_mainz/work/win_pstools/' | |
| 194 | 189 | ||
| 195 | - | ||
| 190 | + | case "$cmd" in | |
| 196 | - | ||
| 191 | + | 'install') | |
| 197 | - | ||
| 192 | + | nfsclient_install | |
| 198 | - | ||
| 193 | + | return $? | |
| 199 | - | ||
| 194 | + | ;; | |
| 200 | - | ||
| 195 | + | 'run_deamon' | 'run_daemon') | |
| 201 | - | ||
| 196 | + | require_cmd 'nfsd.exe' || return 1 | |
| 202 | - | ||
| 197 | + | require_cmd 'nfsd_debug.exe' || return 1 | |
| 203 | - | ||
| 198 | + | require_cmd 'nfs_mount.exe' || return 1 | |
| 204 | - | ||
| 199 | + | nfsclient_rundeamon | |
| 205 | - | ||
| 200 | + | return $? | |
| 206 | - | ||
| 201 | + | ;; | |
| 207 | - | ||
| 202 | + | 'sys_run_deamon' | 'sys_run_daemon') | |
| 208 | - | ||
| 203 | + | require_cmd 'PsExec.exe' || return 1 | |
| 209 | - | ||
| 204 | + | require_cmd 'nfsd.exe' || return 1 | |
| 210 | - | ||
| 205 | + | require_cmd 'nfsd_debug.exe' || return 1 | |
| 211 | - | ||
| 206 | + | require_cmd 'nfs_mount.exe' || return 1 | |
| 212 | - | ||
| 207 | + | is_windows_admin_account || return 1 | |
| 213 | - | ||
| 208 | + | nfsclient_system_rundeamon | |
| 214 | - | ||
| 209 | + | return $? | |
| 215 | - | ||
| 210 | + | ;; | |
| 216 | - | ||
| 211 | + | 'sys_mount_homedir') | |
| 217 | - | ||
| 212 | + | require_cmd 'nfs_mount.exe' || return 1 | |
| 218 | - | ||
| 213 | + | is_windows_admin_account || return 1 | |
| 219 | - | ||
| 214 | + | nfsclient_system_mount_homedir | |
| 220 | - | ||
| 215 | + | return $? | |
| 221 | - | ||
| 216 | + | ;; | |
| 222 | - | ||
| 217 | + | 'mount_homedir') | |
| 223 | - | ||
| 218 | + | require_cmd 'nfs_mount.exe' || return 1 | |
| 224 | - | ||
| 219 | + | nfsclient_mount_homedir | |
| 225 | - | ||
| 220 | + | return $? | |
| 226 | - | ||
| 221 | + | ;; | |
| 227 | - | ||
| 222 | + | 'umount_homedir') | |
| 228 | - | ||
| 223 | + | require_cmd 'nfs_mount.exe' || return 1 | |
| 229 | - | ||
| 224 | + | nfsclient_umount_homedir | |
| 230 | - | ||
| 225 | + | return $? | |
| 231 | - | ||
| 226 | + | ;; | |
| 232 | - | ||
| 227 | + | *) | |
| 233 | - | ||
| 228 | + | printf $"%s: Unknown cmd %q\n" "$0" "$cmd" 1>&2 | |
| 234 | - | ||
| 229 | + | return 1 | |
| 235 | - | ||
| 230 | + | ;; | |
| 236 | - | ||
| 231 | + | esac | |
| 237 | - | ||
| 232 | + | return 1 | |
| 238 | - | ||
| 233 | + | } | |
| 239 | 234 | ||
| 240 | - | ||
| 235 | + | # | |
| 241 | - | ||
| 236 | + | # main | |
| 242 | - | ||
| 237 | + | # | |
| 243 | - | ||
| 238 | + | main "$@" | |
| 244 | - | ||
| 239 | + | exit $? | |
| 245 | 240 | ||
| 246 | - | ||
| 241 | + | # EOF. | |
| 247 | 242 |
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