malloc->zalloc
[grub2/phcoder.git] / util / grub.d / 30_os-prober.in
blob552ad8e28b8289d231bb220d5a17064e07d2b08f
1 #! /bin/sh -e
3 # grub-mkconfig helper script.
4 # Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
6 # GRUB is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # GRUB is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 prefix=@prefix@
20 exec_prefix=@exec_prefix@
21 libdir=@libdir@
23 . ${libdir}/grub/grub-mkconfig_lib
25 if [ -z "`which os-prober 2> /dev/null`" -o -z "`which linux-boot-prober 2> /dev/null`" ] ; then
26 # missing os-prober and/or linux-boot-prober
27 exit 0
30 OSPROBED="`os-prober 2> /dev/null | tr ' ' '^' | paste -s -d ' '`"
31 if [ -z "${OSPROBED}" ] ; then
32 # empty os-prober output, nothing doing
33 exit 0
36 for OS in ${OSPROBED} ; do
37 DEVICE="`echo ${OS} | cut -d ':' -f 1`"
38 LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
39 LABEL="`echo ${OS} | cut -d ':' -f 3 | tr '^' ' '`"
40 BOOT="`echo ${OS} | cut -d ':' -f 4`"
42 if [ -z "${LONGNAME}" ] ; then
43 LONGNAME="${LABEL}"
46 echo "Found ${LONGNAME} on ${DEVICE}" >&2
48 case ${BOOT} in
49 chain)
50 CHAINROOT="`grub-probe --target=drive --device ${DEVICE} 2> /dev/null`"
52 cat << EOF
53 menuentry "${LONGNAME} (on ${DEVICE})" {
54 EOF
55 prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
57 cat << EOF
58 drivemap -s (hd0) \${root}
59 chainloader +1
61 EOF
63 linux)
64 LINUXPROBED="`linux-boot-prober ${DEVICE} 2> /dev/null | tr ' ' '^' | paste -s -d ' '`"
66 for LINUX in ${LINUXPROBED} ; do
67 LROOT="`echo ${LINUX} | cut -d ':' -f 1`"
68 LBOOT="`echo ${LINUX} | cut -d ':' -f 2`"
69 LLABEL="`echo ${LINUX} | cut -d ':' -f 3 | tr '^' ' '`"
70 LKERNEL="`echo ${LINUX} | cut -d ':' -f 4`"
71 LINITRD="`echo ${LINUX} | cut -d ':' -f 5`"
72 LPARAMS="`echo ${LINUX} | cut -d ':' -f 6- | tr '^' ' '`"
74 if [ -z "${LLABEL}" ] ; then
75 LLABEL="${LONGNAME}"
78 cat << EOF
79 menuentry "${LLABEL} (on ${DEVICE})" {
80 EOF
81 prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
82 cat << EOF
83 linux ${LKERNEL} ${LPARAMS}
84 EOF
85 if [ -n "${LINITRD}" ] ; then
86 cat << EOF
87 initrd ${LINITRD}
88 EOF
90 cat << EOF
92 EOF
93 done
95 macosx)
96 OSXUUID="`grub-probe --target=fs_uuid --device ${DEVICE} 2> /dev/null`"
97 cat << EOF
98 menuentry "${LONGNAME} (on ${DEVICE})" {
99 EOF
100 prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
101 cat << EOF
102 insmod vbe
103 do_resume=0
104 if [ /var/vm/sleepimage -nt10 / ]; then
105 if xnu_resume /var/vm/sleepimage; then
106 do_resume=1
109 if [ \$do_resume == 0 ]; then
110 xnu_uuid ${OSXUUID} uuid
111 if [ -f /Extra/DSDT.aml ]; then
112 acpi -e /Extra/DSDT.aml
114 xnu_kernel /mach_kernel boot-uuid=\${uuid} rd=*uuid
115 if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then
116 xnu_mkext /System/Library/Extensions.mkext
117 else
118 xnu_kextdir /System/Library/Extensions
120 if [ -f /Extra/Extensions.mkext ]; then
121 xnu_mkext /Extra/Extensions.mkext
123 if [ -d /Extra/Extensions ]; then
124 xnu_kextdir /Extra/Extensions
126 if [ -f /Extra/devtree.txt ]; then
127 xnu_devtree /Extra/devtree.txt
129 if [ -f /Extra/splash.jpg ]; then
130 insmod jpeg
131 xnu_splash /Extra/splash.jpg
133 if [ -f /Extra/splash.png ]; then
134 insmod png
135 xnu_splash /Extra/splash.png
137 if [ -f /Extra/splash.tga ]; then
138 insmod tga
139 xnu_splash /Extra/splash.tga
145 hurd|*)
146 echo " ${LONGNAME} is not yet supported by grub-mkconfig." >&2
148 esac
149 done