pastebin - collaborative debugging tool
rovema.kpaste.net RSS

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

    
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
7171
	cp etc_netconfig /cygdrive/c/etc/netconfig
7272
	cp ms-nfs41-idmap.conf /cygdrive/c/etc/.
7373
7474
	bcdedit /set testsigning on
7575
	regtool -s set '/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Tcpip/Parameters/Domain' 'GLOBAL.LOC'
7676
7777
	sc query Dfsc
7878
	sc stop Dfsc || true
7979
	sc config Dfsc start=disabled
8080
8181
	sc query nfs41_driver
8282
	domainname
8383
8484
	# check whether the driver really has been installed
8585
	md5sum \
8686
		"$PWD/nfs41_driver.sys" \
87-
		/cygdrive/c/Windows/System32/drivers/nfs41_driver.sys
87+
		'/cygdrive/c/Windows/System32/drivers/nfs41_driver.sys'
8888
8989
	return 0
9090
}
9191
9292
function nfsclient_rundeamon
9393
{
9494
	set -o xtrace
9595
	set -o nounset
9696
97-
	nfsd_debug -d 0 --noldap --gid 1616 --uid 1616
97+
	nfsd_debug -d 2  --noldap --gid 1616 --uid 1616
9898
	return $?
9999
}
100100
101101
function nfsclient_system_rundeamon
102102
{
103103
	set -o xtrace
104104
	set -o nounset
105105
106-
	su_system nfsd_debug -d 0 --noldap --gid 1616 --uid 1616
106+
	su_system nfsd_debug -d 2 --noldap --gid 1616 --uid 1616
107107
	return $?
108108
}
109109
110110
function nfsclient_mount_homedir
111111
{
112112
	set -o xtrace
113113
	set -o nounset
114114
	set -o errexit
115115
116116
	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'
119119
	return $?
120120
}
121121
122122
function nfsclient_system_mount_homedir
123123
{
124124
	set -o xtrace
125125
	set -o nounset
126126
	set -o errexit
127127
128128
	su_system nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz'
129129
130130
	return $?
131131
}
132132
133133
function nfsclient_umount_homedir
134134
{
135135
	set -o xtrace
136136
	set -o nounset
137137
	typeset -i res
138138
139139
	nfs_mount -d H
140140
	(( res=$? ))
141141
142142
	if (( res == 0 )) ; then
143143
		# remove bind mount
144-
		umount /home/rmainz
144+
		umount '/home/rmainz' && rmdir '/home/rmainz'
145145
	fi
146146
147147
	return $res
148148
}
149149
150150
function require_cmd
151151
{
152152
	typeset cmd="$1"
153153
154154
	if ! which "$cmd" >'/dev/null' 2>&1 ; then
155155
		printf $"%s: %q not found in %q\n" "$0" "$cmd" "$PWD" 1>&2
156156
		return 1
157157
	fi
158158
	return 0
159159
}
160160
161161
# execute cmd as Windows user "SYSTEM"
162162
function su_system
163163
{
164164
	typeset cmd="$1"
165165
	shift
166166
167167
	typeset abspath_cmd="$(which "$cmd")"
168168
	if [[ ! -x "$abspath_cmd" ]] ; then
169169
		printf "%s: Command %q not found." $"su_system" "$abspath_cmd" 1>&2
170170
		return 127
171171
	fi
172172
173173
	PsExec \
174174
		-accepteula -nobanner \
175175
		-s \
176176
		-w "$(cygpath -w "$PWD")" \
177177
		"$(cygpath -w "$abspath_cmd")" "$@"
178178
}
179179
180180
function main
181181
{
182182
	typeset cmd="$1"
183183
184184
	# "$PATH:/usr/bin:/bin" is used for PsExec where $PATH might be empty
185185
	export PATH="$PWD:$PATH:/usr/bin:/bin"
186186
187187
	# my own path to pstools
188188
	PATH+=':/home/roland_mainz/work/win_pstools/'
189189
190190
	case "$cmd" in
191191
		'install')
192192
			nfsclient_install
193193
			return $?
194194
			;;
195195
		'run_deamon' | 'run_daemon')
196196
			require_cmd 'nfsd.exe' || return 1
197197
			require_cmd 'nfsd_debug.exe' || return 1
198198
			require_cmd 'nfs_mount.exe' || return 1
199199
			nfsclient_rundeamon
200200
			return $?
201201
			;;
202202
		'sys_run_deamon' | 'sys_run_daemon')
203203
			require_cmd 'PsExec.exe' || return 1
204204
			require_cmd 'nfsd.exe' || return 1
205205
			require_cmd 'nfsd_debug.exe' || return 1
206206
			require_cmd 'nfs_mount.exe' || return 1
207207
			is_windows_admin_account || return 1
208208
			nfsclient_system_rundeamon
209209
			return $?
210210
			;;
211211
		'sys_mount_homedir')
212212
			require_cmd 'nfs_mount.exe' || return 1
213213
			is_windows_admin_account || return 1
214214
			nfsclient_system_mount_homedir
215215
			return $?
216216
			;;
217217
		'mount_homedir')
218218
			require_cmd 'nfs_mount.exe' || return 1
219219
			nfsclient_mount_homedir
220220
			return $?
221221
			;;
222222
		'umount_homedir')
223223
			require_cmd 'nfs_mount.exe' || return 1
224224
			nfsclient_umount_homedir
225225
			return $?
226226
			;;
227227
		*)
228228
			printf $"%s: Unknown cmd %q\n" "$0" "$cmd" 1>&2
229229
			return 1
230230
			;;
231231
	esac
232232
	return 1
233233
}
234234
235+
235236
#
236237
# main
237238
#
238239
main "$@"
239240
exit $?
240241
241242
# EOF.
242243

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