| 1 |
#!/bin/sh |
| 2 |
. /usr/share/os-prober/common.sh |
| 3 |
set -e |
| 4 |
|
| 5 |
partition="$1" |
| 6 |
bootpart="$2" |
| 7 |
mpoint="$3" |
| 8 |
type="$4" |
| 9 |
|
| 10 |
found_item=0 |
| 11 |
|
| 12 |
entry_result () { |
| 13 |
if [ "$ignore_item" = 0 ] && \ |
| 14 |
[ -n "$kernel" ] && \ |
| 15 |
[ -e "$mpoint/$kernel" ]; then |
| 16 |
result "$rootpart:$bootpart:$title:$kernel:$initrd:$parameters" |
| 17 |
found_item=1 |
| 18 |
fi |
| 19 |
kernel="" |
| 20 |
parameters="" |
| 21 |
initrd="" |
| 22 |
title="" |
| 23 |
ignore_item=0 |
| 24 |
} |
| 25 |
|
| 26 |
parse_grub_menu () { |
| 27 |
mpoint="$1" |
| 28 |
rootpart="$2" |
| 29 |
bootpart="$3" |
| 30 |
|
| 31 |
kernel="" |
| 32 |
parameters="" |
| 33 |
initrd="" |
| 34 |
title="" |
| 35 |
ignore_item=0 |
| 36 |
|
| 37 |
while read line; do |
| 38 |
debug "parsing: $line" |
| 39 |
set -f |
| 40 |
set -- $line |
| 41 |
set +f |
| 42 |
case "$1" in |
| 43 |
menuentry) |
| 44 |
entry_result |
| 45 |
shift 1 |
| 46 |
# The double-quoted string is the title. |
| 47 |
# Make sure to look at the text of the line |
| 48 |
# before 'set' mangled it. |
| 49 |
title="$(echo "$line" | sed -n 's/[^"]*"\(.*\)".*/\1/p' | sed 's/://g')" |
| 50 |
if [ -z "$title" ]; then |
| 51 |
# ... or single-quoted? Be careful |
| 52 |
# to handle constructions like |
| 53 |
# 'foo'\''bar' (which expands to |
| 54 |
# foo'bar, as in shell), and to |
| 55 |
# handle multiple single-quoted |
| 56 |
# strings on the same line. |
| 57 |
title="$(echo "$line" | sed -n "s/[^']*'\(\([^']\|'\\\\''\)*\)'.*/\1/p" | sed "s/'\\\\''/'/; s/://g")" |
| 58 |
fi |
| 59 |
if [ -z "$title" ]; then |
| 60 |
ignore_item=1 |
| 61 |
elif echo "$title" | grep -q '(on /dev/[^)]*)$'; then |
| 62 |
log "Skipping entry '$title':" |
| 63 |
log "appears to be an automatic reference taken from another menu.lst" |
| 64 |
ignore_item=1 |
| 65 |
fi |
| 66 |
;; |
| 67 |
linux) |
| 68 |
# Hack alert: sed off any (hdn,n) but |
| 69 |
# assume the kernel is on the same |
| 70 |
# partition. |
| 71 |
kernel="$(echo "$2" | sed 's/(.*)//')" |
| 72 |
shift 2 |
| 73 |
parameters="$@" |
| 74 |
# Systems with a separate /boot will not have |
| 75 |
# the path to the kernel in grub.cfg. |
| 76 |
if [ "$partition" != "$bootpart" ]; then |
| 77 |
kernel="/boot$kernel" |
| 78 |
fi |
| 79 |
;; |
| 80 |
initrd) |
| 81 |
shift |
| 82 |
initrd="" |
| 83 |
for initrd_path in "$@"; do |
| 84 |
# sed hack, as above |
| 85 |
initrd_path="$(echo "$initrd_path" | sed 's/(.*)//')" |
| 86 |
# Initrd same. |
| 87 |
if [ "$partition" != "$bootpart" ]; then |
| 88 |
initrd_path="/boot$initrd_path" |
| 89 |
fi |
| 90 |
if [ -z "$initrd" ]; then |
| 91 |
initrd="$initrd_path" |
| 92 |
else |
| 93 |
initrd="$initrd $initrd_path" |
| 94 |
fi |
| 95 |
done |
| 96 |
;; |
| 97 |
"}") |
| 98 |
entry_result |
| 99 |
;; |
| 100 |
esac |
| 101 |
done |
| 102 |
|
| 103 |
entry_result |
| 104 |
} |
| 105 |
|
| 106 |
if [ -e "$mpoint/boot/grub/grub.cfg" ] && \ |
| 107 |
([ ! -e "$mpoint/boot/grub/menu.lst" ] || \ |
| 108 |
[ "$mpoint/boot/grub/grub.cfg" -nt "$mpoint/boot/grub/menu.lst" ]); then |
| 109 |
debug "parsing grub.cfg" |
| 110 |
parse_grub_menu "$mpoint" "$partition" "$bootpart" < "$mpoint/boot/grub/grub.cfg" |
| 111 |
elif [ -e "$mpoint/boot/grub2/grub.cfg" ]; then |
| 112 |
debug "parsing grub.cfg" |
| 113 |
parse_grub_menu "$mpoint" "$partition" "$bootpart" < "$mpoint/boot/grub2/grub.cfg" |
| 114 |
fi |
| 115 |
|
| 116 |
if [ "$found_item" = 0 ]; then |
| 117 |
exit 1 |
| 118 |
else |
| 119 |
exit 0 |
| 120 |
fi |