| 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 |
title) |
| 44 |
entry_result |
| 45 |
shift 1 |
| 46 |
title="$(echo "$@" | sed 's/://g')" |
| 47 |
if echo "$title" | grep -q '(on /dev/[^)]*)$'; then |
| 48 |
log "Skipping entry '$title':" |
| 49 |
log "appears to be an automatic reference taken from another menu.lst" |
| 50 |
ignore_item=1 |
| 51 |
fi |
| 52 |
;; |
| 53 |
kernel) |
| 54 |
# Hack alert: sed off any (hdn,n) but |
| 55 |
# assume the kernel is on the same |
| 56 |
# partition. |
| 57 |
kernel="$(echo "$2" | sed 's/(.*)//')" |
| 58 |
shift 2 |
| 59 |
parameters="$@" |
| 60 |
# Systems with a separate /boot will not have |
| 61 |
# the path to the kernel in menu.lst. |
| 62 |
if [ "$partition" != "$bootpart" ]; then |
| 63 |
kernel="/boot$kernel" |
| 64 |
fi |
| 65 |
;; |
| 66 |
initrd) |
| 67 |
# Hack alert take 2: sed off any (hdn,n) |
| 68 |
# See #566102 |
| 69 |
initrd="$(echo "$2" | sed 's/(.*)//')" |
| 70 |
# Initrd same. |
| 71 |
if [ "$partition" != "$bootpart" ]; then |
| 72 |
initrd="/boot$initrd" |
| 73 |
fi |
| 74 |
;; |
| 75 |
boot) |
| 76 |
entry_result |
| 77 |
;; |
| 78 |
module) |
| 79 |
log "Skipping entry '$title':" |
| 80 |
log "parsing of entries containing 'module' lines is currently not supported" |
| 81 |
ignore_item=1 |
| 82 |
;; |
| 83 |
esac |
| 84 |
done |
| 85 |
|
| 86 |
entry_result |
| 87 |
} |
| 88 |
|
| 89 |
grubconf= |
| 90 |
if [ -e "$mpoint/boot/grub/menu.lst" ]; then |
| 91 |
grubconf="menu.lst" |
| 92 |
elif [ -e "$mpoint/boot/grub/grub.conf" ]; then |
| 93 |
grubconf="grub.conf" |
| 94 |
fi |
| 95 |
|
| 96 |
if [ "$grubconf" ] && \ |
| 97 |
([ ! -e "$mpoint/boot/grub/grub.cfg" ] || \ |
| 98 |
[ "$mpoint/boot/grub/$grubconf" -nt "$mpoint/boot/grub/grub.cfg" ]); then |
| 99 |
debug "parsing $grubconf" |
| 100 |
parse_grub_menu "$mpoint" "$partition" "$bootpart" < "$mpoint/boot/grub/$grubconf" |
| 101 |
fi |
| 102 |
|
| 103 |
if [ "$found_item" = 0 ]; then |
| 104 |
exit 1 |
| 105 |
else |
| 106 |
exit 0 |
| 107 |
fi |