pastebin - collaborative debugging tool
rovema.kpaste.net RSS

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

    
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
#
15+
# 1. Mount for current users:
1616
# (requires PsExec from https://download.sysinternals.com/files/PSTools.zip
1717
# 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
2021
#
22+
# 2. Mount for all users:
2130
22-
function nfsclient_install
31+
function is_windows_admin_account
2332
{
2833
	#
2934
	# Test whether we have the Windows permissions to install DLLs
3035
	# and the kernel module
3136
	#
3237
	# Usually Windows Adminstrator rights are indicated by the
3338
	# membership in group "544(Administratoren)" (Cygwin maps
3439
	# "SID S-1-5-32-544" to GID 544)
3540
	#
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
3943
	fi
44+
	return 1
4046
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
4552
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
5256
	fi
5357
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
5662
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
5970
71+
	cp etc_netconfig /cygdrive/c/etc/netconfig
6373
74+
	bcdedit /set testsigning on
6676
77+
	sc query Dfsc
7180
81+
	sc query nfs41_driver
7483
84+
	# check whether the driver really has been installed
7988
80-
	nfsd_debug -d 2 --noldap --gid 1616 --uid 1616
89+
	return 0
8290
}
8391
84-
function nfsclient_mount_homedir
92+
function nfsclient_rundeamon
8593
{
8694
	set -o xtrace
8795
	set -o nounset
8996
90-
	nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz'
97+
	nfsd_debug -d 0 --noldap --gid 1616 --uid 1616
9398
	return $?
9499
}
95100
96-
function nfsclient_umount_homedir
101+
function nfsclient_system_rundeamon
97102
{
98103
	set -o xtrace
99104
	set -o nounset
101105
102-
	nfs_mount -d H
106+
	su_system nfsd_debug -d 0 --noldap --gid 1616 --uid 1616
103-
	(( res=$? ))
107+
	return $?
108+
}
104109
105-
	if (( res == 0 )) ; then
110+
function nfsclient_mount_homedir
111+
{
109115
110-
	return $res
116+
	nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz'
117+
	mkdir -p /home/rmainz
111120
}
112121
113-
function main
122+
function nfsclient_system_mount_homedir
114123
{
115-
	typeset cmd="$1"
124+
	set -o xtrace
125+
	set -o nounset
116127
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'
119129
120-
	if [[ "$cmd" != 'install' ]] ; then
130+
	return $?
121-
		if ! which 'nfsd.exe' >/dev/null 2>&1 ; then
131+
}
130132
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
154148
}
155149
156-
main "$@"
150+
function require_cmd
157-
exit $?
151+
{
152+
	typeset cmd="$1"
158153
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+
}
165160
166-
161+
# execute cmd as Windows user "SYSTEM"
167-
162+
function su_system
168-
163+
{
169-
164+
	typeset cmd="$1"
170-
165+
	shift
171166
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
177172
178-
173+
	PsExec \
179-
174+
		-accepteula -nobanner \
180-
175+
		-s \
181-
176+
		-w "$(cygpath -w "$PWD")" \
182-
177+
		"$(cygpath -w "$abspath_cmd")" "$@"
183-
178+
}
184179
185-
180+
function main
186-
181+
{
187-
182+
	typeset cmd="$1"
188183
189-
184+
	# "$PATH:/usr/bin:/bin" is used for PsExec where $PATH might be empty
190-
185+
	export PATH="$PWD:$PATH:/usr/bin:/bin"
191186
192-
187+
	# my own path to pstools
193-
188+
	PATH+=':/home/roland_mainz/work/win_pstools/'
194189
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+
}
239234
240-
235+
#
241-
236+
# main
242-
237+
#
243-
238+
main "$@"
244-
239+
exit $?
245240
246-
241+
# EOF.
247242

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