summaryrefslogtreecommitdiffstats
path: root/init.d/localmount
blob: 622e2e047ab2ba0dfb7bdc6d0e6b4dbebd770850 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/sbin/runscript

: ${NET_FS_LIST:="afs cifs coda davfs fuse gfs ncpfs nfs nfs4 ocfs2 shfs smbfs"}
: ${NO_UNMOUNT:="/dev/shm /dev/pts /dev /sys /proc /"}

start() {
	local types="noprocfs" i=
	for i in ${NET_FS_LIST}; do
		types="$types,$i"
	done

	# create mount points from fstab
	mkmntdirs /etc/fstab

	ebegin "Mounting local file systems"
	mount -at "$types"
	eend $? "Some local filesystems failed to mount"

	if [ ! -d /proc/bus/usb ]; then
		modprobe usbcore &>/dev/null
	fi

	if [ -e /proc/filesystems ] ; then	
		if [ -d /proc/bus/usb -a ! -e /proc/bus/usb/devices ] ; then
			local usbfs=$(grep -ow usbfs /proc/filesystems)

			if [ -n "${usbfs}" ] ; then
				ebegin "Mounting USB device filesystem"
				local gid=$(getent group usb | cut -d: -f3)
				mount -t ${usbfs} \
					-o ${gid:+devmode=0664,devgid=${gid},}noexec,nosuid \
					usbfs /proc/bus/usb
				eend $?
			fi
		fi

		if [ -d /proc/fs/nfsd ] ; then
			if grep -qs nfsd /proc/filesystems ; then
				ebegin "Mounting nfsd filesystem"
				mount -t nfsd -o nodev,noexec,nosuid nfsd /proc/fs/nfsd
				eend $?
			fi
		fi
	fi
}

reverse_mounts() {
	local rev=
	while read line ; do 
		rev="$line\n$rev"
	done < /proc/mounts
}

unmountable() {
	local i=
	for i in $NO_UNMOUNT ; do
		[ "$i" = "$1" ] && return 1
	done
	for i in $NET_FS_LIST ; do
		[ "$i" = "$2" ] && return 1
	done
	return 0
}

stop() {
	local rev= dev= mnt= rc=0 fs=
	ebegin "Unmounting filesystems"
	sync ; sync

	while read line ; do 
		rev="$line\n$rev"
	done < /proc/mounts

	echo -e "$rev" | grep -v '^$' | while read dev mnt fs ; do
		if unmountable $mnt $fs ; then
			umount -r "$mnt"
			rc=$(($rc + $?))
		fi
	done
			
	eend $rc
}