Debian Codegraph @

linux-boot-probes/common/50mounted-tests

raw
1 #!/bin/sh
2 # Sub-tests that require a mounted partition.
3 . /usr/share/os-prober/common.sh
4 set -e
5
6 do_unmount() {
7 if [ "$mounted" ]; then
8 umount "$tmpmnt/boot" 2>/dev/null || true
9 if ! umount "$tmpmnt"; then
10 warn "failed to umount $tmpmnt"
11 fi
12 fi
13 rmdir "$tmpmnt" || true
14 }
15
16 partition="$1"
17
18 types="$(fs_type "$partition")"
19 if [ "$types" = NOT-DETECTED ]; then
20 debug "$1 type not recognised; skipping"
21 exit 0
22 elif [ "$types" = swap ]; then
23 debug "$1 is a swap partition; skipping"
24 exit 0
25 elif [ "$types" = crypto_LUKS ]; then
26 debug "$1 is a LUKS partition; skipping"
27 exit 0
28 elif [ "$types" = ntfs ]; then
29 if type ntfs-3g >/dev/null 2>&1; then
30 types='ntfs-3g ntfs'
31 fi
32 elif [ -z "$types" ]; then
33 if is_dos_extended_partition "$partition"; then
34 debug "$1 looks like an extended dos partition; skipping"
35 exit 0
36 fi
37 if type cryptsetup >/dev/null 2>&1 && \
38 cryptsetup luksDump "$partition" >/dev/null 2>&1; then
39 debug "$1 is a LUKS partition; skipping"
40 exit 0
41 fi
42 types="$(grep -v nodev /proc/filesystems)"
43 fi
44
45 tmpmnt=/var/lib/os-prober/mount
46 if [ ! -d "$tmpmnt" ]; then
47 mkdir "$tmpmnt"
48 fi
49
50 mounted=
51 if type grub-mount >/dev/null 2>&1 && \
52 type grub-probe >/dev/null 2>&1 && \
53 grub-mount "$partition" "$tmpmnt" 2>/dev/null; then
54 mounted=1
55 type="$(grub-probe -d "$partition" -t fs)"
56 [ "$type" ] || type=fuseblk
57 fi
58
59 if [ "$mounted" ]; then
60 linux_mount_boot "$partition" "$tmpmnt"
61 bootpart="${mountboot%% *}"
62 mounted="${mountboot#* }"
63
64 for test in /usr/lib/linux-boot-probes/mounted/*; do
65 if [ -f "$test" ] && [ -x "$test" ]; then
66 debug "running $test $partition $bootpart $tmpmnt $type"
67 if $test "$partition" "$bootpart" "$tmpmnt" "$type"; then
68 debug "$test succeeded"
69 do_unmount
70 exit 0
71 fi
72 fi
73 done
74 fi
75 do_unmount
76
77 # No tests found anything.
78 exit 1