| 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 |
dequote () { |
| 13 |
item="${1%\"}" |
| 14 |
echo "${item#\"}" |
| 15 |
} |
| 16 |
|
| 17 |
recordstanza () { |
| 18 |
if [ -n "$kernel" ]; then |
| 19 |
# TODO: handle device=/partition= to find images |
| 20 |
if ! [ -e "$mpoint/$kernel" ]; then |
| 21 |
debug "cannot find $kernel; not recording" |
| 22 |
return |
| 23 |
fi |
| 24 |
if [ "$initrd" ] && ! [ -e "$mpoint/$initrd" ]; then |
| 25 |
debug "cannot find $initrd: not recording" |
| 26 |
return |
| 27 |
fi |
| 28 |
|
| 29 |
if [ -z "$title" ]; then |
| 30 |
title="${kernel##*/}" |
| 31 |
fi |
| 32 |
if [ "$read_only" ]; then |
| 33 |
parameters="ro $parameters" |
| 34 |
fi |
| 35 |
if [ "$rootdev" ]; then |
| 36 |
parameters="root=$rootdev $parameters" |
| 37 |
fi |
| 38 |
parameters="${parameters% }" |
| 39 |
result "$rootpart:$bootpart:$title:$kernel:$initrd:$parameters" |
| 40 |
found_item=1 |
| 41 |
|
| 42 |
title= |
| 43 |
rootdev="$default_rootdev" |
| 44 |
kernel="$default_kernel" |
| 45 |
parameters="$default_parameters" |
| 46 |
initrd="$default_initrd" |
| 47 |
read_only="$default_read_only" |
| 48 |
else |
| 49 |
# Everything in the global options section set default values. |
| 50 |
default_rootdev="$rootdev" |
| 51 |
default_kernel="$kernel" |
| 52 |
default_parameters="$parameters" |
| 53 |
default_initrd="$initrd" |
| 54 |
default_read_only="$read_only" |
| 55 |
fi |
| 56 |
} |
| 57 |
|
| 58 |
parse_yaboot_conf () { |
| 59 |
mpoint="$1" |
| 60 |
rootpart="$2" |
| 61 |
bootpart="$3" |
| 62 |
IFS=" =" |
| 63 |
while read line; do |
| 64 |
debug "parsing: $line" |
| 65 |
set -f |
| 66 |
set -- $line |
| 67 |
set +f |
| 68 |
case "$1" in |
| 69 |
root) |
| 70 |
rootdev="$(dequote "$2")" |
| 71 |
;; |
| 72 |
image) |
| 73 |
recordstanza |
| 74 |
kernel="$(dequote "$2")" |
| 75 |
;; |
| 76 |
append) |
| 77 |
cleanappend=`printf %s "$line" | sed 's/append\([[:space:]]\)*=\([[:space:]]\)*//'` |
| 78 |
parameters="$(dequote "$cleanappend")" |
| 79 |
;; |
| 80 |
initrd) |
| 81 |
initrd="$(dequote "$2")" |
| 82 |
;; |
| 83 |
label) |
| 84 |
shift 1 |
| 85 |
title="$(dequote "$*")" |
| 86 |
;; |
| 87 |
alias) |
| 88 |
shift 1 |
| 89 |
titlealias="$(dequote "$*")" |
| 90 |
;; |
| 91 |
read-only) |
| 92 |
read_only=1 |
| 93 |
;; |
| 94 |
esac |
| 95 |
done |
| 96 |
recordstanza |
| 97 |
} |
| 98 |
|
| 99 |
# Avoid failing if archdetect is missing (running outside d-i). This is |
| 100 |
# suboptimal but will do for now. |
| 101 |
if type archdetect >/dev/null 2>&1; then |
| 102 |
case "`archdetect`" in |
| 103 |
powerpc/powermac_newworld) |
| 104 |
;; |
| 105 |
powerpc/chrp*) |
| 106 |
;; |
| 107 |
*) |
| 108 |
exit 1 |
| 109 |
;; |
| 110 |
esac |
| 111 |
fi |
| 112 |
|
| 113 |
if [ -e "$mpoint/etc/yaboot.conf" ]; then |
| 114 |
debug "parsing yaboot.conf" |
| 115 |
parse_yaboot_conf "$mpoint" "$partition" "$bootpart" < "$mpoint/etc/yaboot.conf" |
| 116 |
fi |
| 117 |
|
| 118 |
if [ "$found_item" = 0 ]; then |
| 119 |
exit 1 |
| 120 |
else |
| 121 |
exit 0 |
| 122 |
fi |