1 | #!/bin/bash |
---|
2 | set -e |
---|
3 | |
---|
4 | #grubSyntax |
---|
5 | #version 1.1.0 |
---|
6 | #autoconfigurador de items de menu para grub/brg |
---|
7 | #basado en scripts del paquete de grub |
---|
8 | #Antonio Doblas Viso |
---|
9 | #Universidad de Málaga |
---|
10 | |
---|
11 | DISK= |
---|
12 | PART= |
---|
13 | |
---|
14 | |
---|
15 | |
---|
16 | if [ $# == 3 ]; then |
---|
17 | DISK=$1;PART=$2;KERNELPARAM=$3 |
---|
18 | fi |
---|
19 | |
---|
20 | if [ $# == 2 ]; then |
---|
21 | DISK=$1;PART=$2 |
---|
22 | fi |
---|
23 | |
---|
24 | if [ $# == 1 ]; then |
---|
25 | KERNELPARAM=$1 |
---|
26 | fi |
---|
27 | |
---|
28 | |
---|
29 | #Versión de scripts compatible con la versión 1.99 de grub-probe |
---|
30 | #Uso del grub-probe 1.99 según arquitectura |
---|
31 | grub_probe=${grub_probe:-$OGBIN/grub-probe1.99_$(arch)} |
---|
32 | |
---|
33 | #librerias del osProber para kernel antiguos: detecta e identifica sistema operativos. |
---|
34 | grub-install --version | grep 1.99 && cp -r /opt/opengnsys/lib/os-probes/* /usr/lib/os-probes/ |
---|
35 | |
---|
36 | |
---|
37 | #Autoreconocimiento del ogLive en cache |
---|
38 | #fichero de reconocimeinto de grub |
---|
39 | #fichero de lsb-release en la cache (al final de este scripts se elimina esta entrada para que el browser no lo muestre |
---|
40 | |
---|
41 | if [ $(ls /opt/opengnsys/cache/boot/$oglivedir/ogvmlinuz 2>/dev/null) ]; then |
---|
42 | sed -i 's|/boot/\${oglivedir}/ogvmlinuz |/vmlinuz |i' /usr/lib/linux-boot-probes/mounted/90fallback |
---|
43 | sed -i 's|/vmlinuz |/vmlinuz /boot/\${oglivedir}/ogvmlinuz |1' /usr/lib/linux-boot-probes/mounted/90fallback |
---|
44 | mkdir -p /opt/opengnsys/cache/etc/ |
---|
45 | echo "DISTRIB_ID=Ubuntu" > /opt/opengnsys/cache/etc/lsb-release |
---|
46 | echo "DISTRIB_RELEASE= " >> /opt/opengnsys/cache/etc/lsb-release |
---|
47 | echo $oglivedir | awk -F- ' {print "DISTRIB_CODENAME="$2 }' >> /opt/opengnsys/cache/etc/lsb-release |
---|
48 | echo "DISTRIB_DESCRIPTION=OpenGnsys Live" >> /opt/opengnsys/cache/etc/lsb-release |
---|
49 | fi |
---|
50 | |
---|
51 | #ver linea 195 detección de los os en variable OSPROBED |
---|
52 | |
---|
53 | OG_prepare_grub_to_access_device () |
---|
54 | { |
---|
55 | device="$1" |
---|
56 | loop_file= |
---|
57 | case ${device} in |
---|
58 | /dev/loop/*|/dev/loop[0-9]) |
---|
59 | grub_loop_device="${device#/dev/}" |
---|
60 | loop_file=`losetup "${device}" | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"` |
---|
61 | case $loop_file in |
---|
62 | /dev/*) ;; |
---|
63 | *) |
---|
64 | loop_device="${device}" |
---|
65 | device=`"${grub_probe}" --target=device "${loop_file}"` || return 0 |
---|
66 | ;; |
---|
67 | esac |
---|
68 | ;; |
---|
69 | esac |
---|
70 | if dmsetup status $device 2>/dev/null | grep -q 'crypt[[:space:]]$'; then |
---|
71 | grub_warn \ |
---|
72 | "$device is a crypto device, which GRUB cannot read directly. Some" \ |
---|
73 | "necessary modules may be missing from /boot/grub/grub.cfg. You may" \ |
---|
74 | "need to list them in GRUB_PRELOAD_MODULES in /etc/default/grub. See" \ |
---|
75 | "http://bugs.debian.org/542165 for details." |
---|
76 | return 0 |
---|
77 | fi |
---|
78 | # Abstraction modules aren't auto-loaded. |
---|
79 | abstraction="`"${grub_probe}" --device "${device}" --target=abstraction`" |
---|
80 | for module in ${abstraction} ; do |
---|
81 | echo "insmod ${module}" |
---|
82 | done |
---|
83 | partmap="`"${grub_probe}" --device "${device}" --target=partmap`" |
---|
84 | for module in ${partmap} ; do |
---|
85 | case "${module}" in |
---|
86 | netbsd | openbsd) |
---|
87 | echo "insmod part_bsd";; |
---|
88 | *) |
---|
89 | echo "insmod part_${module}";; |
---|
90 | esac |
---|
91 | done |
---|
92 | fs="`"${grub_probe}" --device "${device}" --target=fs`" |
---|
93 | for module in ${fs} ; do |
---|
94 | echo "insmod ${module}" |
---|
95 | done |
---|
96 | # If there's a filesystem UUID that GRUB is capable of identifying, use it; |
---|
97 | # otherwise set root as per value in device.map. |
---|
98 | #OG modificacion |
---|
99 | echo "set root='`"${grub_probe}" --device "${device}" --target=drive`'" |
---|
100 | #if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then |
---|
101 | # echo "search --no-floppy --fs-uuid --set=root ${fs_uuid}" |
---|
102 | #fi |
---|
103 | |
---|
104 | if [ "x${loop_file}" != x ]; then |
---|
105 | loop_mountpoint="$(awk '"'${loop_file}'" ~ "^"$2 && $2 != "/" { print $2 }' /proc/mounts | tail -n1)" |
---|
106 | if [ "x${loop_mountpoint}" != x ]; then |
---|
107 | echo "loopback ${grub_loop_device} ${loop_file#$loop_mountpoint}" |
---|
108 | echo "set root=(${grub_loop_device})" |
---|
109 | fi |
---|
110 | fi |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | # grub-mkconfig helper script. |
---|
118 | # Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. |
---|
119 | # |
---|
120 | # GRUB is free software: you can redistribute it and/or modify |
---|
121 | # it under the terms of the GNU General Public License as published by |
---|
122 | # the Free Software Foundation, either version 3 of the License, or |
---|
123 | # (at your option) any later version. |
---|
124 | # |
---|
125 | # GRUB is distributed in the hope that it will be useful, |
---|
126 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
127 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
128 | # GNU General Public License for more details. |
---|
129 | # |
---|
130 | # You should have received a copy of the GNU General Public License |
---|
131 | # along with GRUB. If not, see <http://www.gnu.org/licenses/>. |
---|
132 | |
---|
133 | |
---|
134 | prefix=/usr |
---|
135 | exec_prefix=${prefix} |
---|
136 | libdir=${exec_prefix}/lib |
---|
137 | |
---|
138 | . ${libdir}/grub/grub-mkconfig_lib |
---|
139 | |
---|
140 | found_other_os= |
---|
141 | |
---|
142 | make_timeout () { |
---|
143 | if [ "x${found_other_os}" = "x" ] ; then |
---|
144 | if [ "x${1}" != "x" ] ; then |
---|
145 | if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then |
---|
146 | verbose= |
---|
147 | else |
---|
148 | verbose=" --verbose" |
---|
149 | fi |
---|
150 | |
---|
151 | if [ "x${1}" = "x0" ] ; then |
---|
152 | cat <<EOF |
---|
153 | if [ "x\${timeout}" != "x-1" ]; then |
---|
154 | if keystatus; then |
---|
155 | if keystatus --shift; then |
---|
156 | set timeout=-1 |
---|
157 | else |
---|
158 | set timeout=0 |
---|
159 | fi |
---|
160 | else |
---|
161 | if sleep$verbose --interruptible 3 ; then |
---|
162 | set timeout=0 |
---|
163 | fi |
---|
164 | fi |
---|
165 | fi |
---|
166 | EOF |
---|
167 | else |
---|
168 | cat << EOF |
---|
169 | if [ "x\${timeout}" != "x-1" ]; then |
---|
170 | if sleep$verbose --interruptible ${GRUB_HIDDEN_TIMEOUT} ; then |
---|
171 | set timeout=0 |
---|
172 | fi |
---|
173 | fi |
---|
174 | EOF |
---|
175 | fi |
---|
176 | fi |
---|
177 | fi |
---|
178 | } |
---|
179 | |
---|
180 | adjust_timeout () { |
---|
181 | if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then |
---|
182 | cat <<EOF |
---|
183 | if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then |
---|
184 | EOF |
---|
185 | make_timeout "${GRUB_HIDDEN_TIMEOUT_BUTTON}" "${GRUB_TIMEOUT_BUTTON}" |
---|
186 | echo else |
---|
187 | make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}" |
---|
188 | echo fi |
---|
189 | else |
---|
190 | make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}" |
---|
191 | fi |
---|
192 | } |
---|
193 | |
---|
194 | if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then |
---|
195 | adjust_timeout |
---|
196 | exit 0 |
---|
197 | fi |
---|
198 | |
---|
199 | if [ -z "`which os-prober 2> /dev/null`" -o -z "`which linux-boot-prober 2> /dev/null`" ] ; then |
---|
200 | # missing os-prober and/or linux-boot-prober |
---|
201 | adjust_timeout |
---|
202 | exit 0 |
---|
203 | fi |
---|
204 | |
---|
205 | case "$1" in |
---|
206 | |
---|
207 | |
---|
208 | esac |
---|
209 | |
---|
210 | |
---|
211 | |
---|
212 | # ADV OSPROBED |
---|
213 | if [ -n "${DISK}" ]; then |
---|
214 | #Si $DISK esta definido buscar en el disco y la particion parametro 1 y 2 |
---|
215 | OSSEARCH=$(ogDiskToDev $DISK $PART) |
---|
216 | OSPROBED="`os-prober | grep $OSSEARCH | tr ' ' '^' | paste -s -d ' '`" |
---|
217 | else |
---|
218 | #si no esta definido |
---|
219 | OSPROBED="`os-prober | tr ' ' '^' | paste -s -d ' '`" |
---|
220 | fi |
---|
221 | |
---|
222 | #DISK=${DISK:-"1"} |
---|
223 | #echo $OSSEARCH |
---|
224 | #echo "$OSPROBED" |
---|
225 | |
---|
226 | |
---|
227 | if [ -z "${OSPROBED}" ] ; then |
---|
228 | # empty os-prober output, nothing doing |
---|
229 | adjust_timeout |
---|
230 | exit 0 |
---|
231 | fi |
---|
232 | |
---|
233 | osx_entry() { |
---|
234 | found_other_os=1 |
---|
235 | cat << EOF |
---|
236 | menuentry "${LONGNAME} (${2}-bit) (on ${DEVICE})" --class osx --class darwin --class os { |
---|
237 | EOF |
---|
238 | save_default_entry | sed -e "s/^/\t/" |
---|
239 | prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/" |
---|
240 | cat << EOF |
---|
241 | load_video |
---|
242 | set do_resume=0 |
---|
243 | if [ /var/vm/sleepimage -nt10 / ]; then |
---|
244 | if xnu_resume /var/vm/sleepimage; then |
---|
245 | set do_resume=1 |
---|
246 | fi |
---|
247 | fi |
---|
248 | if [ \$do_resume = 0 ]; then |
---|
249 | xnu_uuid ${OSXUUID} uuid |
---|
250 | if [ -f /Extra/DSDT.aml ]; then |
---|
251 | acpi -e /Extra/DSDT.aml |
---|
252 | fi |
---|
253 | $1 /mach_kernel boot-uuid=\${uuid} rd=*uuid |
---|
254 | if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then |
---|
255 | xnu_mkext /System/Library/Extensions.mkext |
---|
256 | else |
---|
257 | xnu_kextdir /System/Library/Extensions |
---|
258 | fi |
---|
259 | if [ -f /Extra/Extensions.mkext ]; then |
---|
260 | xnu_mkext /Extra/Extensions.mkext |
---|
261 | fi |
---|
262 | if [ -d /Extra/Extensions ]; then |
---|
263 | xnu_kextdir /Extra/Extensions |
---|
264 | fi |
---|
265 | if [ -f /Extra/devprop.bin ]; then |
---|
266 | xnu_devprop_load /Extra/devprop.bin |
---|
267 | fi |
---|
268 | if [ -f /Extra/splash.jpg ]; then |
---|
269 | insmod jpeg |
---|
270 | xnu_splash /Extra/splash.jpg |
---|
271 | fi |
---|
272 | if [ -f /Extra/splash.png ]; then |
---|
273 | insmod png |
---|
274 | xnu_splash /Extra/splash.png |
---|
275 | fi |
---|
276 | if [ -f /Extra/splash.tga ]; then |
---|
277 | insmod tga |
---|
278 | xnu_splash /Extra/splash.tga |
---|
279 | fi |
---|
280 | fi |
---|
281 | } |
---|
282 | EOF |
---|
283 | } |
---|
284 | |
---|
285 | wubi= |
---|
286 | |
---|
287 | for OS in ${OSPROBED} ; do |
---|
288 | DEVICE="`echo ${OS} | cut -d ':' -f 1`" |
---|
289 | LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`" |
---|
290 | LABEL="`echo ${OS} | cut -d ':' -f 3 | tr '^' ' '`" |
---|
291 | BOOT="`echo ${OS} | cut -d ':' -f 4`" |
---|
292 | |
---|
293 | if [ -z "${LONGNAME}" ] ; then |
---|
294 | LONGNAME="${LABEL}" |
---|
295 | fi |
---|
296 | |
---|
297 | echo "Found ${LONGNAME} on ${DEVICE}" >&2 |
---|
298 | |
---|
299 | case ${BOOT} in |
---|
300 | chain) |
---|
301 | |
---|
302 | case ${LONGNAME} in |
---|
303 | Windows*) |
---|
304 | if [ -z "$wubi" ]; then |
---|
305 | if [ -x /usr/share/lupin-support/grub-mkimage ] && \ |
---|
306 | /usr/share/lupin-support/grub-mkimage --test; then |
---|
307 | wubi=yes |
---|
308 | else |
---|
309 | wubi=no |
---|
310 | fi |
---|
311 | fi |
---|
312 | if [ "$wubi" = yes ]; then |
---|
313 | echo "Skipping ${LONGNAME} on Wubi system" >&2 |
---|
314 | continue |
---|
315 | fi |
---|
316 | ;; |
---|
317 | esac |
---|
318 | #adv |
---|
319 | LABELCLASS=$(echo "${LONGNAME}" | awk '{print tolower($1$2);}') |
---|
320 | |
---|
321 | found_other_os=1 |
---|
322 | cat << EOF |
---|
323 | menuentry "${LONGNAME} (on ${DEVICE})" --class $LABELCLASS --class windows { |
---|
324 | EOF |
---|
325 | save_default_entry | sed -e "s/^/\t/" |
---|
326 | #ADV prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/" |
---|
327 | OG_prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/" |
---|
328 | |
---|
329 | case ${LONGNAME} in |
---|
330 | Windows\ Vista*|Windows\ 7*|Windows\ Server\ 2008*) |
---|
331 | ;; |
---|
332 | *) |
---|
333 | #ADV cat << EOF |
---|
334 | #ADV drivemap -s (hd0) \${root} |
---|
335 | #ADV EOF |
---|
336 | ;; |
---|
337 | esac |
---|
338 | |
---|
339 | cat <<EOF |
---|
340 | chainloader +1 |
---|
341 | } |
---|
342 | EOF |
---|
343 | ;; |
---|
344 | linux) |
---|
345 | KERNELPARAM="" |
---|
346 | #linuxprobed detecta todos los kernels de una partición. |
---|
347 | LINUXPROBED="`linux-boot-prober ${DEVICE} 2> /dev/null | tr ' ' '^' | paste -s -d ' '`" |
---|
348 | #esta opcion de linuxprobe solo interpreta el primer kernel detectado de la partición |
---|
349 | #Si queremos que autoincluya todos los kernels hay que comentar esta filtrado de LINUXPROBED |
---|
350 | LINUXPROBED=$(echo $LINUXPROBED | awk '{ print $1}') |
---|
351 | prepare_boot_cache= |
---|
352 | # echo "ADV listado de los kerenel encontrados linux-boot-prober ${DEVICE} $LINUXPROBED" |
---|
353 | for LINUX in ${LINUXPROBED} ; do |
---|
354 | LINUX=$LINUXPROBED |
---|
355 | LROOT="`echo ${LINUX} | cut -d ':' -f 1`" |
---|
356 | LBOOT="`echo ${LINUX} | cut -d ':' -f 2`" |
---|
357 | LLABEL="`echo ${LINUX} | cut -d ':' -f 3 | tr '^' ' '`" |
---|
358 | LKERNEL="`echo ${LINUX} | cut -d ':' -f 4`" |
---|
359 | LINITRD="`echo ${LINUX} | cut -d ':' -f 5`" |
---|
360 | LPARAMS="`echo ${LINUX} | cut -d ':' -f 6- | tr '^' ' '`" |
---|
361 | if [ -z "${LLABEL}" ] ; then |
---|
362 | LLABEL="${LONGNAME}" |
---|
363 | fi |
---|
364 | |
---|
365 | if [ "${LROOT}" != "${LBOOT}" ]; then |
---|
366 | LKERNEL="${LKERNEL#/boot}" |
---|
367 | LINITRD="${LINITRD#/boot}" |
---|
368 | fi |
---|
369 | |
---|
370 | found_other_os=1 |
---|
371 | LABELCLASS=$(echo "${LLABEL}" | awk '{print tolower($1);}') |
---|
372 | cat << EOF |
---|
373 | menuentry "${LLABEL} (on ${DEVICE})" --class $LABELCLASS --class linux --class os { |
---|
374 | EOF |
---|
375 | save_default_entry | sed -e "s/^/\t/" |
---|
376 | if [ -z "${prepare_boot_cache}" ]; then |
---|
377 | #ADV prepare_boot_cache="$(prepare_grub_to_access_device ${LBOOT} | sed -e "s/^/\t/")" |
---|
378 | prepare_boot_cache="$(OG_prepare_grub_to_access_device ${LBOOT} | sed -e "s/^/\t/")" |
---|
379 | fi |
---|
380 | printf '%s\n' "${prepare_boot_cache}" |
---|
381 | if [ "$LABELCLASS" == "opengnsys" ]; then |
---|
382 | KERNELPARAM=$(cat /proc/cmdline) |
---|
383 | fi |
---|
384 | cat << EOF |
---|
385 | linux ${LKERNEL} ${LPARAMS} ${KERNELPARAM} |
---|
386 | EOF |
---|
387 | if [ -n "${LINITRD}" ] ; then |
---|
388 | cat << EOF |
---|
389 | initrd ${LINITRD} |
---|
390 | EOF |
---|
391 | fi |
---|
392 | cat << EOF |
---|
393 | } |
---|
394 | EOF |
---|
395 | done |
---|
396 | ;; |
---|
397 | macosx) |
---|
398 | OSXUUID="`grub-probe --target=fs_uuid --device ${DEVICE} 2> /dev/null`" |
---|
399 | osx_entry xnu_kernel 32 |
---|
400 | osx_entry xnu_kernel64 64 |
---|
401 | ;; |
---|
402 | hurd) |
---|
403 | found_other_os=1 |
---|
404 | cat << EOF |
---|
405 | menuentry "${LONGNAME} (on ${DEVICE})" --class hurd --class gnu --class os { |
---|
406 | EOF |
---|
407 | save_default_entry | sed -e "s/^/\t/" |
---|
408 | prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/" |
---|
409 | grub_device="`${grub_probe} --device ${DEVICE} --target=drive`" |
---|
410 | mach_device="`echo "${grub_device}" | sed -e 's/(\(hd.*\),msdos\(.*\))/\1s\2/'`" |
---|
411 | grub_fs="`${grub_probe} --device ${DEVICE} --target=fs`" |
---|
412 | case "${grub_fs}" in |
---|
413 | *fs) hurd_fs="${grub_fs}" ;; |
---|
414 | *) hurd_fs="${grub_fs}fs" ;; |
---|
415 | esac |
---|
416 | cat << EOF |
---|
417 | multiboot /boot/gnumach.gz root=device:${mach_device} |
---|
418 | module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\ |
---|
419 | --multiboot-command-line='\${kernel-command-line}' \\ |
---|
420 | --host-priv-port='\${host-port}' \\ |
---|
421 | --device-master-port='\${device-port}' \\ |
---|
422 | --exec-server-task='\${exec-task}' -T typed '\${root}' \\ |
---|
423 | '\$(task-create)' '\$(task-resume)' |
---|
424 | module /lib/ld.so.1 exec /hurd/exec '\$(exec-task=task-create)' |
---|
425 | } |
---|
426 | EOF |
---|
427 | ;; |
---|
428 | *) |
---|
429 | echo " ${LONGNAME} is not yet supported by grub-mkconfig." >&2 |
---|
430 | ;; |
---|
431 | esac |
---|
432 | done |
---|
433 | |
---|
434 | adjust_timeout |
---|
435 | |
---|
436 | rm /opt/opengnsys/cache/etc/lsb-release &>/dev/null |
---|