PageRenderTime 22ms CodeModel.GetById 1ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 1ms

/grub.d/30_os-prober

http://github.com/brinkman83/bashrc
Shell | 249 lines | 209 code | 22 blank | 18 comment | 36 complexity | 235cb43f280c29557f0f24a1e8163457 MD5 | raw file
  1#! /bin/sh -e
  2
  3# grub-mkconfig helper script.
  4# Copyright (C) 2006,2007,2008,2009  Free Software Foundation, Inc.
  5#
  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.
 10#
 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.
 15#
 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/>.
 18
 19prefix=/usr
 20exec_prefix=${prefix}
 21libdir=${exec_prefix}/lib
 22
 23. ${libdir}/grub/grub-mkconfig_lib
 24
 25found_other_os=
 26
 27adjust_timeout () {
 28  if [ "x${found_other_os}" = "x" ] ; then
 29    if [ "x${GRUB_HIDDEN_TIMEOUT}" != "x" ] ; then
 30      if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then
 31	verbose=
 32      else
 33	verbose=" --verbose"
 34      fi
 35
 36      if [ "x${GRUB_HIDDEN_TIMEOUT}" = "x0" ] ; then
 37	cat <<EOF
 38if [ \${timeout} != -1 ]; then
 39  if keystatus; then
 40    if keystatus --shift; then
 41      set timeout=-1
 42    else
 43      set timeout=0
 44    fi
 45  else
 46    if sleep$verbose --interruptible 3 ; then
 47      set timeout=0
 48    fi
 49  fi
 50fi
 51EOF
 52      else
 53	cat << EOF
 54if [ \${timeout} != -1 ]; then
 55  if sleep$verbose --interruptible ${GRUB_HIDDEN_TIMEOUT} ; then
 56    set timeout=0
 57  fi
 58fi
 59EOF
 60      fi
 61    fi
 62  fi
 63}
 64
 65if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then
 66  adjust_timeout
 67  exit 0
 68fi
 69
 70if [ -z "`which os-prober 2> /dev/null`" -o -z "`which linux-boot-prober 2> /dev/null`" ] ; then
 71  # missing os-prober and/or linux-boot-prober
 72  adjust_timeout
 73  exit 0
 74fi
 75
 76OSPROBED="`os-prober | tr ' ' '^' | paste -s -d ' '`"
 77if [ -z "${OSPROBED}" ] ; then
 78  # empty os-prober output, nothing doing
 79  adjust_timeout
 80  exit 0
 81fi
 82
 83osx_entry() {
 84        cat << EOF
 85menuentry "${LONGNAME} (${2}-bit) (on ${DEVICE})" {
 86EOF
 87	save_default_entry | sed -e "s/^/\t/"
 88	prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
 89	cat << EOF
 90        insmod ${GRUB_VIDEO_BACKEND}
 91        set do_resume=0
 92        if [ /var/vm/sleepimage -nt10 / ]; then
 93           if xnu_resume /var/vm/sleepimage; then
 94             set do_resume=1
 95           fi
 96        fi
 97        if [ \$do_resume == 0 ]; then
 98           xnu_uuid ${OSXUUID} uuid
 99           if [ -f /Extra/DSDT.aml ]; then
100              acpi -e /Extra/DSDT.aml
101           fi
102           $1 /mach_kernel boot-uuid=\${uuid} rd=*uuid
103           if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then
104              xnu_mkext /System/Library/Extensions.mkext
105           else
106              xnu_kextdir /System/Library/Extensions
107           fi
108           if [ -f /Extra/Extensions.mkext ]; then
109              xnu_mkext /Extra/Extensions.mkext
110           fi
111           if [ -d /Extra/Extensions ]; then
112              xnu_kextdir /Extra/Extensions
113           fi
114           if [ -f /Extra/devprop.bin ]; then
115              xnu_devprop_load /Extra/devprop.bin
116           fi
117           if [ -f /Extra/splash.jpg ]; then
118              insmod jpeg
119              xnu_splash /Extra/splash.jpg
120           fi
121           if [ -f /Extra/splash.png ]; then
122              insmod png
123              xnu_splash /Extra/splash.png
124           fi
125           if [ -f /Extra/splash.tga ]; then
126              insmod tga
127              xnu_splash /Extra/splash.tga
128           fi
129        fi
130}
131EOF
132}
133
134for OS in ${OSPROBED} ; do
135  DEVICE="`echo ${OS} | cut -d ':' -f 1`"
136  LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
137  LABEL="`echo ${OS} | cut -d ':' -f 3 | tr '^' ' '`"
138  BOOT="`echo ${OS} | cut -d ':' -f 4`"
139
140  if [ -z "${LONGNAME}" ] ; then
141    LONGNAME="${LABEL}"
142  fi
143
144  echo "Found ${LONGNAME} on ${DEVICE}" >&2
145  found_other_os=1
146
147  case ${BOOT} in
148    chain)
149
150      cat << EOF
151menuentry "${LONGNAME} (on ${DEVICE})" {
152EOF
153      save_default_entry | sed -e "s/^/\t/"
154      prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
155
156      case ${LONGNAME} in
157	Windows\ Vista*|Windows\ 7*)
158	;;
159	*)
160	  cat << EOF
161	drivemap -s (hd0) \${root}
162EOF
163	;;
164      esac
165
166      cat <<EOF
167	chainloader +1
168}
169EOF
170    ;;
171    linux)
172      LINUXPROBED="`linux-boot-prober ${DEVICE} 2> /dev/null | tr ' ' '^' | paste -s -d ' '`"
173      prepare_boot_cache=
174
175      for LINUX in ${LINUXPROBED} ; do
176        LROOT="`echo ${LINUX} | cut -d ':' -f 1`"
177        LBOOT="`echo ${LINUX} | cut -d ':' -f 2`"
178        LLABEL="`echo ${LINUX} | cut -d ':' -f 3 | tr '^' ' '`"
179        LKERNEL="`echo ${LINUX} | cut -d ':' -f 4`"
180        LINITRD="`echo ${LINUX} | cut -d ':' -f 5`"
181        LPARAMS="`echo ${LINUX} | cut -d ':' -f 6- | tr '^' ' '`"
182
183        if [ -z "${LLABEL}" ] ; then
184          LLABEL="${LONGNAME}"
185        fi
186
187	if [ "${LROOT}" != "${LBOOT}" ]; then
188	  LKERNEL="${LKERNEL#/boot}"
189	  LINITRD="${LINITRD#/boot}"
190	fi
191
192        cat << EOF
193menuentry "${LLABEL} (on ${DEVICE})" {
194EOF
195	save_default_entry | sed -e "s/^/\t/"
196	if [ -z "${prepare_boot_cache}" ]; then
197	  prepare_boot_cache="$(prepare_grub_to_access_device ${LBOOT} | sed -e "s/^/\t/")"
198	fi
199	printf '%s\n' "${prepare_boot_cache}"
200	cat <<  EOF
201	linux ${LKERNEL} ${LPARAMS}
202EOF
203        if [ -n "${LINITRD}" ] ; then
204          cat << EOF
205	initrd ${LINITRD}
206EOF
207        fi
208        cat << EOF
209}
210EOF
211      done
212    ;;
213    macosx)
214      OSXUUID="`grub-probe --target=fs_uuid --device ${DEVICE} 2> /dev/null`"
215      osx_entry xnu_kernel 32
216      osx_entry xnu_kernel64 64
217    ;;
218    hurd)
219      cat << EOF
220menuentry "${LONGNAME} (on ${DEVICE})" {
221EOF
222      save_default_entry | sed -e "s/^/\t/"
223      prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
224      grub_device="`${grub_probe} --device ${DEVICE} --target=drive`"
225      mach_device="`echo "${grub_device}" | tr -d '()' | tr , s`"
226      grub_fs="`${grub_probe} --device ${DEVICE} --target=fs`"
227      case "${grub_fs}" in
228	*fs)	hurd_fs="${grub_fs}" ;;
229	*)	hurd_fs="${grub_fs}fs" ;;
230      esac
231      cat << EOF
232	multiboot /boot/gnumach.gz root=device:${mach_device}
233	module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\
234			--multiboot-command-line='\${kernel-command-line}' \\
235			--host-priv-port='\${host-port}' \\
236			--device-master-port='\${device-port}' \\
237			--exec-server-task='\${exec-task}' -T typed '\${root}' \\
238			'\$(task-create)' '\$(task-resume)'
239	module /lib/ld.so.1 exec /hurd/exec '\$(exec-task=task-create)'
240}
241EOF
242    ;;
243    *)
244      echo "  ${LONGNAME} is not yet supported by grub-mkconfig." >&2
245    ;;
246  esac
247done
248
249adjust_timeout