[2cd8344] | 1 | #!/bin/sh |
---|
| 2 | # Detects all Microsoft OSes on a collection of partitions. |
---|
| 3 | |
---|
| 4 | . /usr/share/os-prober/common.sh |
---|
| 5 | |
---|
| 6 | partition="$1" |
---|
| 7 | mpoint="$2" |
---|
| 8 | type="$3" |
---|
| 9 | |
---|
| 10 | # This file is for UEFI platform only |
---|
| 11 | if [ ! -d /sys/firmware/efi ] || [ -f /var/lib/partman/ignore_uefi ]; then |
---|
| 12 | debug "Not on UEFI platform" |
---|
| 13 | exit 1 |
---|
| 14 | fi |
---|
| 15 | |
---|
| 16 | # Weed out stuff that doesn't apply to us |
---|
| 17 | case "$type" in |
---|
| 18 | vfat) debug "$1 is a FAT32 partition" ;; |
---|
| 19 | msdos) debug "$1 is a FAT16 partition" ;; |
---|
| 20 | fat) debug "$1 is a FAT partition (mounted by GRUB)" ;; |
---|
| 21 | *) debug "$1 is $type partition: exiting"; exit 1 ;; |
---|
| 22 | esac |
---|
| 23 | |
---|
| 24 | if type udevadm > /dev/null 2>&1; then |
---|
| 25 | udevinfo () { |
---|
| 26 | udevadm info "$@" |
---|
| 27 | } |
---|
| 28 | fi |
---|
| 29 | |
---|
| 30 | if type udevinfo > /dev/null 2>&1; then |
---|
| 31 | # Skip virtual devices |
---|
| 32 | if udevinfo -q path -n $partition | grep -q /virtual/; then |
---|
| 33 | debug "$1 is virtual device: exiting" |
---|
| 34 | exit 1 |
---|
| 35 | fi |
---|
| 36 | |
---|
| 37 | eval "$(udevinfo -q property -n "$partition" | grep -E '^ID_PART_ENTRY_(TYPE|SCHEME)=')" |
---|
| 38 | debug "$partition partition scheme is $ID_PART_ENTRY_SCHEME" |
---|
| 39 | debug "$partition partition type is $ID_PART_ENTRY_TYPE" |
---|
| 40 | |
---|
| 41 | if [ -z "$ID_PART_ENTRY_TYPE" -o -z "$ID_PART_ENTRY_SCHEME" -o \ |
---|
| 42 | \( "$ID_PART_ENTRY_SCHEME" != gpt -a "$ID_PART_ENTRY_SCHEME" != msdos \) -o \ |
---|
| 43 | \( "$ID_PART_ENTRY_SCHEME" = gpt -a "$ID_PART_ENTRY_TYPE" != c12a7328-f81f-11d2-ba4b-00a0c93ec93b \) -o \ |
---|
| 44 | \( "$ID_PART_ENTRY_SCHEME" = msdos -a "$ID_PART_ENTRY_TYPE" != 0xef \) ]; then |
---|
| 45 | debug "$partition is not a ESP partition: exiting" |
---|
| 46 | exit 1 |
---|
| 47 | fi |
---|
| 48 | else |
---|
| 49 | debug "udevinfo and udevadm missing - cannot check partition type" |
---|
| 50 | fi |
---|
| 51 | |
---|
| 52 | efi=$(item_in_dir efi "$mpoint") |
---|
| 53 | if [ -z "$efi" ]; then |
---|
| 54 | debug "$mpoint does not have /EFI directory: exiting" |
---|
| 55 | exit 1 |
---|
| 56 | fi |
---|
| 57 | |
---|
| 58 | ret=1 |
---|
| 59 | for test in /usr/lib/os-probes/mounted/efi/*; do |
---|
| 60 | debug "running subtest $test" |
---|
| 61 | if [ -f "$test" ] && [ -x "$test" ]; then |
---|
| 62 | entry=$("$test" "$mpoint/$efi") |
---|
| 63 | if [ -n "$entry" ]; then |
---|
| 64 | debug "bootloader $entry found by subtest $test" |
---|
| 65 | ret=0 |
---|
| 66 | result "${partition}@/$efi/${entry}:efi" |
---|
| 67 | fi |
---|
| 68 | fi |
---|
| 69 | done |
---|
| 70 | |
---|
| 71 | exit $ret |
---|