File: mountfloppy

package info (click to toggle)
mountfloppy 0.11
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 288 kB
  • ctags: 2
  • sloc: sh: 43; makefile: 25
file content (64 lines) | stat: -rwxr-xr-x 1,509 bytes parent folder | download
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
#!/bin/sh
. /usr/share/debconf/confmodule

FLOPPYMNT=/floppy

ask_dev() {
	DEVS=""
	for dev in $(list-devices maybe-floppy); do
		# TODO if sfdisk or something similar were available, we could
		# do this:
		#        SIZE=sfdisk -s $DEV
		#        if [ "$SIZE" -eq '1440' -o "$SIZE" -eq '2880' ]; then
		if [ -b "$dev" ]; then
			if [ -z "$DEVS" ]; then
				DEVS="$dev"
			else
				DEVS="$DEVS, $dev"
			fi
		fi
	done
	db_subst retriever/floppy/device DEVS $DEVS
	db_input high retriever/floppy/device
	db_go 
	db_get retriever/floppy/device
	if [ "$RET" = Cancel ]; then
		exit 1
	fi
	echo $RET
}

try_mount() {
    # TO REMOVE, there is a bug somewhere in the kernel, the first
    # mount command fail when changing floppy disk
    # so we have to launch mount twice
    mount $1 -tauto $2 || true
    umount $2 || true
    mount $1 -tauto $2
}

if ! mount | cut -d' ' -f3 | grep -q "^$FLOPPYMNT$"; then
	# This is a good reasonable default, but will fail for
	# USB floppys.
	FLOPPYDEV=/dev/floppy/0
	
	if [ ! -e $FLOPPYDEV ]; then
		log-output -t mountfloppy modprobe floppy || true
	fi

	if ! grep -q ^vfat /proc/modules ; then
		log-output -t mountfloppy modprobe vfat || true
	fi
	
	if [ ! -e "$FLOPPYDEV" ]; then
		# Try non-devfs naming.
		FLOPPYDEV=/dev/fd0
	fi

	if [ ! -e "$FLOPPYDEV" ] || ! try_mount $FLOPPYDEV $FLOPPYMNT; then
		# Cannot find a device, or found the wrong device.
		# Ask for help from the user and try it again.
		FLOPPYDEV=$(ask_dev)
		try_mount $FLOPPYDEV $FLOPPYMNT
	fi
fi