source: live-build/trunk/fuentes/scripts/build/lb_binary_grub2 @ 900

Last change on this file since 900 was 900, checked in by kbut, 4 years ago

add original source

  • Property svn:executable set to *
File size: 7.3 KB
Line 
1#!/bin/sh
2
3## live-build(7) - System Build Scripts
4## Copyright (C) 2006-2012 Daniel Baumann <daniel@debian.org>
5##
6## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
7## This is free software, and you are welcome to redistribute it
8## under certain conditions; see COPYING for details.
9
10
11set -e
12
13# Including common functions
14( . "${LIVE_BUILD}/scripts/build.sh" > /dev/null 2>&1 || true ) || . /usr/lib/live/build.sh
15
16# Setting static variables
17DESCRIPTION="$(Echo 'installs grub2 into binary')"
18HELP=""
19USAGE="${PROGRAM} [--force]"
20
21Arguments "${@}"
22
23# Reading configuration files
24Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
25Set_defaults
26
27if [ "${LB_BOOTLOADER}" != "grub2" ]
28then
29        exit 0
30fi
31
32Echo_message "Begin installing grub2..."
33
34# Requiring stage file
35Require_stagefile .build/config .build/bootstrap
36
37# Checking stage file
38Check_stagefile .build/binary_grub
39
40# Checking grub2 templates
41Check_templates grub2
42
43# Checking lock file
44Check_lockfile .lock
45
46# Creating lock file
47Create_lockfile .lock
48
49# Check architecture
50Check_architectures amd64 i386
51Check_crossarchitectures
52
53# Checking depends
54Check_package chroot/usr/bin/grub-mkimage grub-pc
55
56# Restoring cache
57Restore_cache cache/packages.binary
58
59# Installing depends
60Install_package
61
62# Local functions
63Grub_live_entry ()
64{
65        LABEL="${1}"
66        KERNEL="${2}"
67        INITRD="${3}"
68        APPEND="${4}"
69
70        LINUX_LIVE="${LINUX_LIVE}\nmenuentry \"Debian GNU/Linux - ${LABEL}\" {"
71        LINUX_LIVE="${LINUX_LIVE}\nlinux\t\t/${KERNEL} ${INITFS:+boot=${INITFS} }config LB_BOOTAPPEND_LIVE ${APPEND}"
72        LINUX_LIVE="${LINUX_LIVE}\ninitrd\t\t/${INITRD}"
73        LINUX_LIVE="${LINUX_LIVE}\n}"
74}
75
76Grub_install_entry ()
77{
78        LABEL="${1}"
79        KERNEL="${2}"
80        INITRD="${3}"
81        APPEND="${4}"
82
83        if [ "${LABEL}" != "rescue" ] && [ "${LABEL}" != "rescuegui" ]
84        then
85                APPEND="${APPEND} quiet"
86        fi
87
88        LINUX_INSTALL="${LINUX_INSTALL}\nmenuentry \"Debian GNU/Linux - ${LABEL}\" {"
89        LINUX_INSTALL="${LINUX_INSTALL}\nlinux\t\t/${KERNEL} ${APPEND} LB_BOOTAPPEND_INSTALL"
90        LINUX_INSTALL="${LINUX_INSTALL}\ninitrd\t\t/${INITRD}"
91        LINUX_INSTALL="${LINUX_INSTALL}\n}"
92}
93
94case "${LB_INITRAMFS}" in
95        casper)
96                INITFS="casper"
97                ;;
98
99        live-boot)
100                INITFS="live"
101                ;;
102
103        *)
104                INITFS=""
105                ;;
106esac
107
108# Setting destination directory
109case "${LB_BINARY_IMAGES}" in
110        iso*|tar)
111                case "${LB_INITRAMFS}" in
112                        casper)
113                                DESTDIR_LIVE="binary/casper"
114                                ;;
115
116                        live-boot)
117                                DESTDIR_LIVE="binary/live"
118                                ;;
119
120                        *)
121                                DESTDIR_LIVE="binary/live"
122                                ;;
123                esac
124
125                DESTDIR_INSTALL="binary/install"
126                ;;
127
128        hdd*|netboot)
129                Echo_warning "Bootloader in this image type not yet supported by live-build."
130                Echo_warning "This would produce a not bootable image, aborting (FIXME)."
131                exit 1
132        ;;
133esac
134
135Check_multiarchitectures
136
137# Creating directory
138mkdir -p "${DESTDIR_LIVE}"
139
140# Setting boot parameters
141if [ "${LB_UNION_FILESYSTEM}" != "aufs" ]
142then
143        LB_BOOTAPPEND_LIVE="${LB_BOOTAPPEND_LIVE} union=${LB_UNION_FILESYSTEM}"
144fi
145
146if [ -n "${LB_NET_COW_PATH}" ]
147then
148        Echo_error "Net cow not yet supported on grub"
149        exit 1
150fi
151
152if [ "${LB_EXPOSED_ROOT}" != "false" ]
153then
154        LB_BOOTAPPEND_LIVE="${LB_BOOTAPPEND_LIVE} exposedroot"
155fi
156
157LB_BOOTAPPEND_LIVE="$(echo ${LB_BOOTAPPEND_LIVE} | sed -e 's|  ||')"
158
159# Assembling kernel configuration
160
161# Default entries
162DEFAULT_FLAVOUR="$(echo ${LB_LINUX_FLAVOURS} | awk '{ print $1 }')"
163DEFAULT_KERNEL="$(basename chroot/boot/vmlinuz-*${DEFAULT_FLAVOUR})"
164DEFAULT_INITRD="initrd.img-$(echo ${DEFAULT_KERNEL} | sed -e 's|vmlinuz-||')"
165
166Grub_live_entry "live" "$(basename ${DESTDIR_LIVE})/${DEFAULT_KERNEL}" "$(basename ${DESTDIR_LIVE})/${DEFAULT_INITRD}"
167
168if [ "${LB_BOOTAPPEND_FAILSAFE}" != "none" ]
169then
170        Grub_live_entry "live (fail-safe mode)" "$(basename ${DESTDIR_LIVE})/${DEFAULT_KERNEL}" "$(basename ${DESTDIR_LIVE})/${DEFAULT_INITRD}" "${LB_BOOTAPPEND_FAILSAFE}"
171fi
172
173for KERNEL in chroot/boot/vmlinuz-*
174do
175        VERSION="$(basename ${KERNEL} | sed -e 's|vmlinuz-||')"
176
177        Grub_live_entry "live, kernel ${VERSION}" "$(basename ${DESTDIR_LIVE})/$(basename ${KERNEL})" "$(basename ${DESTDIR_LIVE})/initrd.img-${VERSION}"
178        Grub_live_entry "live, kernel ${VERSION} (fail-safe mode)" "$(basename ${DESTDIR_LIVE})/$(basename ${KERNEL})" "$(basename ${DESTDIR_LIVE})/initrd.img-${VERSION}" "${LB_BOOTAPPEND_FAILSAFE}"
179done
180
181LINUX_LIVE="$(/bin/echo ${LINUX_LIVE} | sed -e 's|binary||g' -e 's|//|/|g')"
182
183# Assembling debian-installer configuration
184if [ "${LB_DEBIAN_INSTALLER}" != "false" ]
185then
186        LINUX_LIVE="#\t \"Live\"\n${LINUX_LIVE}"
187        LINUX_INSTALL="#\t \"Installer\"\n"
188
189        VMLINUZ_DI="install/vmlinuz"
190        INITRD_DI="install/initrd.gz"
191        APPEND_DI="vga=normal"
192
193        VMLINUZ_GI="install/gtk/vmlinuz"
194        INITRD_GI="install/gtk/initrd.gz"
195        APPEND_GI="video=vesa:ywrap,mtrr vga=788"
196
197        Grub_install_entry "install" "${VMLINUZ_DI}" "${INITRD_DI}" "${APPEND_DI}"
198        Grub_install_entry "installgui" "${VMLINUZ_GI}" "${INITRD_GI}" "${APPEND_GI}"
199        Grub_install_entry "expert" "${VMLINUZ_DI}" "${INITRD_DI}" "priority=low ${APPEND_DI}"
200        Grub_install_entry "expertgui" "${VMLINUZ_GI}" "${INITRD_GI}" "priority=low ${APPEND_GI}"
201        Grub_install_entry "rescue" "${VMLINUZ_DI}" "${INITRD_DI}" "rescue/enable=true ${APPEND_DI}"
202        Grub_install_entry "rescuegui" "${VMLINUZ_GI}" "${INITRD_GI}" "rescue/enable=true ${APPEND_GI}"
203        Grub_install_entry "auto" "${VMLINUZ_DI}" "${INITRD_DI}" "auto=true priority=critical ${APPEND_DI}"
204        Grub_install_entry "autogui" "${VMLINUZ_GI}" "${INITRD_GI}" "auto=true priority=critical ${APPEND_GI}"
205fi
206
207LINUX_INSTALL="$(/bin/echo ${LINUX_INSTALL} | sed -e 's|binary||g' -e 's|//|/|g')"
208
209# Assembling memtest configuration
210if [ -f "${DESTDIR_LIVE}"/memtest ]
211then
212        MEMTEST="#\t \"Other\"\n"
213        MEMTEST="${MEMTEST}\nmenuentry\t\"${LB_MEMTEST}\" {\nlinux16\t$(basename ${DESTDIR_LIVE})/memtest\n}"
214        MEMTEST="$(/bin/echo ${MEMTEST} | sed -e 's|//|/|g')"
215fi
216
217# Copying templates
218mkdir -p binary/boot/grub
219cp -r "${TEMPLATES}"/* binary/boot/grub
220
221case ${LB_BINARY_IMAGES} in
222        iso*)
223                FILES="chroot/usr/lib/grub/i386-pc/*.mod chroot/usr/lib/grub/i386-pc/*.lst chroot/usr/lib/grub/i386-pc/efiemu??.o chroot/usr/share/grub/*.pf2"
224                ;;
225
226        hdd*|tar)
227                FILES="chroot/usr/lib/grub/i386-pc/*"
228                ;;
229esac
230
231if [ "${LB_BUILD_WITH_CHROOT}" = "false" ]
232then
233        FILES="$(echo ${FILES} | sed -e 's|chroot||g')"
234fi
235
236# Copying grub
237cp ${FILES} binary/boot/grub
238
239# Copying local configuration file
240if [ -f config/binary_grub/grub.cfg ]
241then
242        cp config/binary_grub/grub.cfg binary/boot/grub/grub.cfg
243fi
244
245# Copying splash screen
246if [ -f config/binary_grub/splash.tga ]
247then
248        LB_GRUB_SPLASH="config/binary_grub/splash.tga"
249fi
250
251if [ -n "${LB_GRUB_SPLASH}" ]
252then
253        if [ "${LB_GRUB_SPLASH}" = "none" ]
254        then
255                # Removing splash file
256                rm -f binary/boot/grub/splash.tga
257
258                # Removing splash entry
259                sed -i -e "s|background_image.*||" binary/boot/grub/grub.cfg
260        else
261                # Overwriting splash file
262                cp -f "${LB_GRUB_SPLASH}" binary/boot/grub
263                sed -i -e "s|background_image .*.tga|background_image \$\(root\)/boot/grub/$(basename ${LB_GRUB_SPLASH})|" binary/boot/grub/grub.cfg
264        fi
265fi
266
267sed -i -e "s|LINUX_LIVE|${LINUX_LIVE}|" -e "s|LINUX_INSTALL|${LINUX_INSTALL}|" -e "s|MEMTEST|${MEMTEST}|" binary/boot/grub/grub.cfg
268sed -i -e "s|LB_BOOTAPPEND_INSTALL|${LB_BOOTAPPEND_INSTALL}|" -e "s|LB_BOOTAPPEND_LIVE|${LB_BOOTAPPEND_LIVE}|" binary/boot/grub/grub.cfg
269
270sed -i -e 's|\ $||g' binary/boot/grub/grub.cfg
271
272# Saving cache
273Save_cache cache/packages.binary
274
275# Removing depends
276Remove_package
277
278# Creating stage file
279Create_stagefile .build/binary_grub
Note: See TracBrowser for help on using the repository browser.