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

Packit d86cd3
#!/bin/sh
Packit d86cd3
# Sub-tests that require a mounted partition.
Packit d86cd3
. /usr/share/os-prober/common.sh
Packit d86cd3
set -e
Packit d86cd3
Packit d86cd3
do_unmount() {
Packit d86cd3
	if [ "$mounted" ]; then
Packit d86cd3
		umount "$tmpmnt/boot" 2>/dev/null || true
Packit d86cd3
		if ! umount "$tmpmnt"; then
Packit d86cd3
			warn "failed to umount $tmpmnt"
Packit d86cd3
		fi
Packit d86cd3
	fi
Packit d86cd3
	for dm_device in $dm_devices; do
Packit d86cd3
		if [ -e "$dm_device" ]; then
Packit d86cd3
			debug "remove device mapper device $dm_device"
Packit d86cd3
			dmsetup remove $dm_device
Packit d86cd3
		fi
Packit d86cd3
	done
Packit d86cd3
	rmdir "$tmpmnt" || true
Packit d86cd3
}
Packit d86cd3
Packit d86cd3
partition="$1"
Packit d86cd3
Packit d86cd3
types="$(fs_type "$partition")"
Packit d86cd3
if [ "$types" = NOT-DETECTED ]; then
Packit d86cd3
	debug "$1 type not recognised; skipping"
Packit d86cd3
	exit 0
Packit d86cd3
elif [ "$types" = swap ]; then
Packit d86cd3
	debug "$1 is a swap partition; skipping"
Packit d86cd3
	exit 0
Packit d86cd3
elif [ "$types" = crypto_LUKS ]; then
Packit d86cd3
	debug "$1 is a LUKS partition; skipping"
Packit d86cd3
	exit 0
Packit d86cd3
elif [ "$types" = ntfs ]; then
Packit d86cd3
	if type ntfs-3g >/dev/null 2>&1; then
Packit d86cd3
		types='ntfs-3g ntfs'
Packit d86cd3
	fi
Packit d86cd3
elif [ -z "$types" ]; then
Packit d86cd3
	if is_dos_extended_partition "$partition"; then
Packit d86cd3
		debug "$1 looks like an extended dos partition; skipping"
Packit d86cd3
		exit 0
Packit d86cd3
	fi
Packit d86cd3
	if type cryptsetup >/dev/null 2>&1 && \
Packit d86cd3
	   cryptsetup luksDump "$partition" >/dev/null 2>&1; then
Packit d86cd3
		debug "$1 is a LUKS partition; skipping"
Packit d86cd3
		exit 0
Packit d86cd3
	fi
Packit d86cd3
	types="$(grep -v nodev /proc/filesystems)"
Packit d86cd3
fi
Packit d86cd3
Packit d86cd3
tmpmnt=/var/lib/os-prober/mount
Packit d86cd3
if [ ! -d "$tmpmnt" ]; then
Packit d86cd3
	mkdir "$tmpmnt"
Packit d86cd3
fi
Packit d86cd3
Packit d86cd3
mounted=
Packit d86cd3
dm_devices=
Packit d86cd3
if type grub-mount >/dev/null 2>&1 && \
Packit Service 8d4c46
   type grub2-probe >/dev/null 2>&1 && \
Packit d86cd3
   grub-mount "$partition" "$tmpmnt" 2>/dev/null; then
Packit d86cd3
	mounted=1
Packit Service 8d4c46
	type="$(grub2-probe -d "$partition" -t fs)"
Packit d86cd3
	[ "$type" ] || type=fuseblk
Packit d86cd3
elif dm_device="$(do_dmsetup osprober-linux "$partition")" && \
Packit d86cd3
     [ "$dm_device" ]; then
Packit d86cd3
	dm_devices="$dm_device"
Packit d86cd3
	for type in $types; do
Packit d86cd3
		if mountinfo=`mount -o ro -t "$type" "$dm_device" "$tmpmnt" 2>&1;; then
Packit d86cd3
			debug "mounted as $type filesystem"
Packit d86cd3
			mounted=1
Packit d86cd3
			break
Packit d86cd3
		else
Packit d86cd3
			debug "mounting $dm_device ($partition) as $type failed: $mountinfo"
Packit d86cd3
		fi
Packit d86cd3
	done
Packit d86cd3
fi
Packit d86cd3
Packit d86cd3
if [ "$mounted" ]; then
Packit d86cd3
	linux_mount_boot "$partition" "$tmpmnt"
Packit d86cd3
	bootpart="${mountboot%% *}"
Packit d86cd3
	mounted="${mountboot#* }"
Packit d86cd3
	if [ "$dm_device" ]; then
Packit d86cd3
		dm_devices="$dm_device $dm_devices"
Packit d86cd3
	fi
Packit d86cd3
Packit Service 8d4c46
	for test in /usr/libexec/linux-boot-probes/mounted/*; do
Packit d86cd3
		if [ -f "$test" ] && [ -x "$test" ]; then
Packit d86cd3
			debug "running $test $partition $bootpart $tmpmnt $type"
Packit d86cd3
			if $test "$partition" "$bootpart" "$tmpmnt" "$type"; then
Packit d86cd3
				debug "$test succeeded"
Packit d86cd3
				do_unmount
Packit d86cd3
				exit 0
Packit d86cd3
			fi
Packit d86cd3
		fi
Packit d86cd3
	done
Packit d86cd3
fi
Packit d86cd3
do_unmount
Packit d86cd3
Packit d86cd3
# No tests found anything.
Packit d86cd3
exit 1