pastebin - collaborative debugging tool
rovema.kpaste.net RSS

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

    
11
#!/bin/bash
22
33
#
44
# msnfs41client.bash - simple Cygwin frontent for the msnfsv41
55
# NFSv4.1 filesystem driver
66
#
77
88
#
99
# Written by Roland Mainz <roland.mainz@nrubsig.org>
1010
#
1111
1212
#
1313
# Examples:
1414
#
1515
# 1. Mount for current users:
1616
# (requires PsExec from https://download.sysinternals.com/files/PSTools.zip
1717
# in /home/roland_mainz/work/win_pstools/)
1818
# * Usage:
1919
# Shell1: cd /cygdrive/c/Users/roland_mainz/Downloads/ms-nfs41-client-x64/ms-nfs41-client-x64 && bash ../msnfs41client.bash run_deamon
2020
# Shell2: cd /cygdrive/c/Users/roland_mainz/Downloads/ms-nfs41-client-x64/ms-nfs41-client-x64 && bash ../msnfs41client.bash mount_homedir
2121
#
2222
# 2. Mount for all users:
2323
# * Requires:
2424
# - Windows admin rights (Cygwin --> Run terminal as Adminstrator)
2525
# - PsExec from https://download.sysinternals.com/files/PSTools.zip in /home/roland_mainz/work/win_pstools/)
2626
# * Usage:
2727
# Shell1: cd /cygdrive/c/Users/roland_mainz/Downloads/ms-nfs41-client-x64/ms-nfs41-client-x64 && bash ../msnfs41client.bash sys_run_deamon
2828
# Shell2: cd /cygdrive/c/Users/roland_mainz/Downloads/ms-nfs41-client-x64/ms-nfs41-client-x64 && bash ../msnfs41client.bash sys_mount_homedir
2929
#
3030
3131
function is_windows_admin_account
3232
{
3333
	#
3434
	# Test whether we have the Windows permissions to install DLLs
3535
	# and the kernel module
3636
	#
3737
	# Usually Windows Adminstrator rights are indicated by the
3838
	# membership in group "544(Administratoren)" (Cygwin maps
3939
	# "SID S-1-5-32-544" to GID 544)
4040
	#
4141
	if [[ "$(id -G)" =~ (^|[[:space:]]+)544([[:space:]]+|$) ]] ; then
4242
		return 0
4343
	fi
4444
	return 1
4545
}
4646
4747
function nfsclient_install
4848
{
4949
	set -o nounset
5050
	set -o xtrace
5151
	set -o errexit
5252
5353
	if ! is_windows_admin_account ; then
5454
		printf $"%s: Install requires Windows Adminstator permissions.\n" "$0"
5555
		return 1
5656
	fi
5757
5858
	# make sure all binaries are executable, Windows cmd does
5959
	# not care, but Cygwin&bash do.
6060
	# If *.ddl are not executable nfs*.exe fail with 0xc0000022
6161
	chmod a+x *.exe *.dll
6262
6363
	if false ; then
6464
		# install.bat needs PATH to include $PWD
6565
		PATH="$PWD:$PATH" cmd /c install.bat
6666
	else
6767
		nfs_install
6868
		rundll32 setupapi.dll,InstallHinfSection DefaultInstall 132 ./nfs41rdr.inf
6969
	fi
7070
71+
	mkdir -p /cygdrive/c/etc
7172
	cp etc_netconfig /cygdrive/c/etc/netconfig
7273
	cp ms-nfs41-idmap.conf /cygdrive/c/etc/.
7374
7475
	bcdedit /set testsigning on
7576
	regtool -s set '/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Tcpip/Parameters/Domain' 'GLOBAL.LOC'
7677
7778
	sc query Dfsc
7879
	sc stop Dfsc || true
7980
	sc config Dfsc start=disabled
8081
8182
	sc query nfs41_driver
8283
	domainname
8384
8485
	# check whether the driver really has been installed
8586
	md5sum \
8687
		"$PWD/nfs41_driver.sys" \
8788
		'/cygdrive/c/Windows/System32/drivers/nfs41_driver.sys'
8889
8990
	return 0
9091
}
9192
9293
function nfsclient_rundeamon
9394
{
9495
	set -o xtrace
9596
	set -o nounset
9697
9798
	nfsd_debug -d 0 --noldap --gid 1616 --uid 1616
9899
	return $?
99100
}
100101
101102
function nfsclient_system_rundeamon
102103
{
103104
	set -o xtrace
104105
	set -o nounset
105106
106107
	su_system nfsd_debug -d 0 --noldap --gid 1616 --uid 1616
107108
	return $?
108109
}
109110
110111
function nfsclient_mount_homedir
111112
{
112113
	set -o xtrace
113114
	set -o nounset
114115
	set -o errexit
115116
116117
	#nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz'
117118
	# fixme: Specifying IPv6 addresses do not work yet, as soon as
118119
	# they come as UNC paths (e.g.
119120
	# $ cd '//[fe80::219:99ff:feae:73ce]@2049/nfs4/export/home/rmainz' #
120121
	# they get corrupted once they arrive in nfsd_debug.exe)
121122
	#nfs_mount -p -o sec=sys H '[fe80::219:99ff:feae:73ce]:/export/home/rmainz'
122123
	nfs_mount -p -o sec=sys H 'derfwpc5131_ipv6:/export/home/rmainz'
123124
	mkdir -p '/home/rmainz'
124125
	mount -o bind,posix=1 '/cygdrive/h' '/home/rmainz'
125126
	return $?
126127
}
127128
128129
function nfsclient_system_mount_homedir
129130
{
130131
	set -o xtrace
131132
	set -o nounset
132133
	set -o errexit
133134
135+
	# purge any leftover persistent mappings to device H:
134138
	#su_system nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz'
135139
	# fixme: Specifying IPv6 addresses do not work yet, as soon as
136140
	# they come as UNC paths (e.g.
137141
	# $ cd '//[fe80::219:99ff:feae:73ce]@2049/nfs4/export/home/rmainz' #
138142
	# they get corrupted once they arrive in nfsd_debug.exe)
139143
	#su_system nfs_mount -p -o sec=sys H '[fe80::219:99ff:feae:73ce]:/export/home/rmainz'
140144
	su_system nfs_mount -p -o sec=sys H 'derfwpc5131_ipv6:/export/home/rmainz'
141145
142146
	return $?
143147
}
144148
145149
function nfsclient_umount_homedir
146150
{
147151
	set -o xtrace
148152
	set -o nounset
149153
	typeset -i res
150154
151155
	nfs_mount -d H
152156
	(( res=$? ))
153157
154158
	if (( res == 0 )) ; then
155159
		# remove bind mount
156160
		umount '/home/rmainz' && rmdir '/home/rmainz'
157161
	fi
158162
159163
	return $res
160164
}
161165
162166
function require_cmd
163167
{
164168
	typeset cmd="$1"
165169
166170
	if ! which "$cmd" >'/dev/null' 2>&1 ; then
167171
		printf $"%s: %q not found in %q\n" "$0" "$cmd" "$PWD" 1>&2
168172
		return 1
169173
	fi
170174
	return 0
171175
}
172176
173177
# execute cmd as Windows user "SYSTEM"
174178
function su_system
175179
{
176180
	typeset cmd="$1"
177181
	shift
178182
179183
	typeset abspath_cmd="$(which "$cmd")"
180184
	if [[ ! -x "$abspath_cmd" ]] ; then
181185
		printf "%s: Command %q not found." $"su_system" "$abspath_cmd" 1>&2
182186
		return 127
183187
	fi
184188
185189
	PsExec \
186190
		-accepteula -nobanner \
187191
		-s \
188192
		-w "$(cygpath -w "$PWD")" \
189193
		"$(cygpath -w "$abspath_cmd")" "$@"
190194
}
191195
192196
function sys_terminal
193197
{
194198
	# su_system does not work, mintty requires PsExec -i
195199
	PsExec -accepteula -nobanner \
196200
		-i \
197201
		-s -w "$(cygpath -w "$PWD")" \
198202
		'C:\cygwin64\bin\mintty.exe'
199203
}
200204
201205
function main
202206
{
203207
	typeset cmd="$1"
204208
205209
	# "$PATH:/usr/bin:/bin" is used for PsExec where $PATH might be empty
206210
	export PATH="$PWD:$PATH:/usr/bin:/bin"
207211
208212
	# my own path to pstools
209213
	PATH+=':/home/roland_mainz/work/win_pstools/'
210214
211215
	case "$cmd" in
212216
		'install')
213217
			nfsclient_install
214218
			return $?
215219
			;;
216220
		'run_deamon' | 'run_daemon')
217221
			require_cmd 'nfsd.exe' || return 1
218222
			require_cmd 'nfsd_debug.exe' || return 1
219223
			require_cmd 'nfs_mount.exe' || return 1
220224
			nfsclient_rundeamon
221225
			return $?
222226
			;;
223227
		'sys_run_deamon' | 'sys_run_daemon')
224228
			require_cmd 'PsExec.exe' || return 1
225229
			require_cmd 'nfsd.exe' || return 1
226230
			require_cmd 'nfsd_debug.exe' || return 1
227231
			require_cmd 'nfs_mount.exe' || return 1
228232
			if ! is_windows_admin_account ; then
229233
				printf $"%s: %q requires Windows Adminstator permissions.\n" "$0" "$cmd"
230234
				return 1
231235
			fi
232236
			nfsclient_system_rundeamon
233237
			return $?
234238
			;;
235239
		'sys_mount_homedir')
236240
			require_cmd 'nfs_mount.exe' || return 1
237241
			if ! is_windows_admin_account ; then
238242
				printf $"%s: %q requires Windows Adminstator permissions.\n" "$0" "$cmd"
239243
				return 1
240244
			fi
241245
			nfsclient_system_mount_homedir
242246
			return $?
243247
			;;
244248
		'mount_homedir')
245249
			require_cmd 'nfs_mount.exe' || return 1
246250
			nfsclient_mount_homedir
247251
			return $?
248252
			;;
249253
		'umount_homedir')
250254
			require_cmd 'nfs_mount.exe' || return 1
251255
			nfsclient_umount_homedir
252256
			return $?
253257
			;;
254258
		# misc
255259
		'sys_terminal')
256260
			require_cmd 'mintty.exe' || return 1
257261
			if ! is_windows_admin_account ; then
258262
				printf $"%s: %q requires Windows Adminstator permissions.\n" "$0" "$cmd"
259263
				return 1
260264
			fi
261265
			sys_terminal
262266
			return $?
263267
			;;
264268
		*)
265269
			printf $"%s: Unknown cmd %q\n" "$0" "$cmd" 1>&2
266270
			return 1
267271
			;;
268272
	esac
269273
	return 1
270274
}
271275
272276
273277
#
274278
# main
275279
#
276280
main "$@"
277281
exit $?
278282
279283
# EOF.
280284

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