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

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

add original source

  • Property svn:executable set to *
File size: 7.2 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 grub 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}" != "grub" ]
28then
29        exit 0
30fi
31
32Echo_message "Begin installing grub..."
33
34# Requiring stage file
35Require_stagefile .build/config .build/bootstrap
36
37# Checking stage file
38Check_stagefile .build/binary_grub
39
40# Checking grub templates
41Check_templates grub
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/sbin/grub grub-legacy
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}\ntitle\t\tDebian GNU/Linux - ${LABEL}"
71        LINUX_LIVE="${LINUX_LIVE}\nkernel\t\t/${KERNEL} ${INITFS:+boot=${INITFS} }config LB_BOOTAPPEND_LIVE ${APPEND}"
72        LINUX_LIVE="${LINUX_LIVE}\ninitrd\t\t/${INITRD}"
73}
74
75Grub_install_entry ()
76{
77        LABEL="${1}"
78        KERNEL="${2}"
79        INITRD="${3}"
80        APPEND="${4}"
81
82        QAPPEND="quiet"
83
84        for TYPE in Install Expert Rescue Auto
85        do
86                case "${TYPE}" in
87                        Install)
88                                TAPPEND="${APPEND} ${QAPPEND}"
89                                ;;
90
91                        Expert)
92                                TAPPEND="priority=low ${APPEND}"
93                                ;;
94
95                        Rescue)
96                                TAPPEND="rescue/enable=true ${APPEND} ${QAPPEND}"
97                                ;;
98
99                        Auto)
100                                TAPPEND="auto=true priority=critical ${APPEND} ${QAPPEND}"
101                                ;;
102                esac
103
104                case "${LABEL}" in
105                        Text)
106                                TYPE_SUFFIX=""
107                                ;;
108                        GUI)
109                                TYPE_SUFFIX="gui"
110                                ;;
111                esac
112
113
114                LINUX_INSTALL="${LINUX_INSTALL}\ntitle\t\t${LABEL} ${TYPE}"
115                LINUX_INSTALL="${LINUX_INSTALL}\nkernel\t\t/${KERNEL} ${TAPPEND} ${LB_BOOTAPPEND_INSTALL}"
116                LINUX_INSTALL="${LINUX_INSTALL}\ninitrd\t\t/${INITRD}"
117        done
118}
119
120case "${LB_INITRAMFS}" in
121        casper)
122                INITFS="casper"
123                ;;
124
125        live-boot)
126                INITFS="live"
127                ;;
128
129        *)
130                INITFS=""
131                ;;
132esac
133
134# Setting destination directory
135case "${LB_BINARY_IMAGES}" in
136        iso*|tar)
137                case "${LB_INITRAMFS}" in
138                        casper)
139                                DESTDIR_LIVE="binary/casper"
140                                ;;
141
142                        live-boot)
143                                DESTDIR_LIVE="binary/live"
144                                ;;
145
146                        *)
147                                DESTDIR_LIVE="binary/boot"
148                                ;;
149                esac
150
151                DESTDIR_INSTALL="binary/install"
152                ;;
153
154        hdd*|netboot)
155                Echo_warning "Bootloader in this image type not yet supported by live-build."
156                Echo_warning "This would produce a not bootable image, aborting (FIXME)."
157                exit 1
158        ;;
159esac
160
161Check_multiarchitectures
162
163# Creating directory
164mkdir -p "${DESTDIR_LIVE}"
165
166# Setting boot parameters
167if [ "${LB_UNION_FILESYSTEM}" != "aufs" ]
168then
169        LB_BOOTAPPEND_LIVE="${LB_BOOTAPPEND_LIVE} union=${LB_UNION_FILESYSTEM}"
170fi
171
172if [ -n "${LB_NET_COW_PATH}" ]
173then
174        Echo_error "Net cow not yet supported on grub"
175        exit 1
176fi
177
178if [ "${LB_EXPOSED_ROOT}" != "false" ]
179then
180        LB_BOOTAPPEND_LIVE="${LB_BOOTAPPEND_LIVE} exposedroot"
181fi
182
183LB_BOOTAPPEND_LIVE="$(echo ${LB_BOOTAPPEND_LIVE} | sed -e 's|  ||')"
184
185# Assembling kernel configuration
186
187# Default entries
188DEFAULT_FLAVOUR="$(echo ${LB_LINUX_FLAVOURS} | awk '{ print $1 }')"
189DEFAULT_KERNEL="$(basename chroot/boot/vmlinuz-*${DEFAULT_FLAVOUR})"
190DEFAULT_INITRD="initrd.img-$(echo ${DEFAULT_KERNEL} | sed -e 's|vmlinuz-||')"
191
192Grub_live_entry "live" "$(basename ${DESTDIR_LIVE})/${DEFAULT_KERNEL}" "$(basename ${DESTDIR_LIVE})/${DEFAULT_INITRD}"
193
194if [ "${LB_BOOTAPPEND_FAILSAFE}" != "none" ]
195then
196        Grub_live_entry "live (fail-safe mode)" "$(basename ${DESTDIR_LIVE})/${DEFAULT_KERNEL}" "$(basename ${DESTDIR_LIVE})/${DEFAULT_INITRD}" "${LB_BOOTAPPEND_FAILSAFE}"
197fi
198
199for KERNEL in chroot/boot/vmlinuz-*
200do
201        VERSION="$(basename ${KERNEL} | sed -e 's|vmlinuz-||')"
202
203        Grub_live_entry "live, kernel ${VERSION}" "$(basename ${DESTDIR_LIVE})/$(basename ${KERNEL})" "$(basename ${DESTDIR_LIVE})/initrd.img-${VERSION}"
204        Grub_live_entry "live, kernel ${VERSION} (fail-safe mode)" "$(basename ${DESTDIR_LIVE})/$(basename ${KERNEL})" "$(basename ${DESTDIR_LIVE})/initrd.img-${VERSION}" "${LB_BOOTAPPEND_FAILSAFE}"
205done
206
207LINUX_LIVE="$(/bin/echo ${LINUX_LIVE} | sed -e 's|binary||g' -e 's|//|/|g')"
208
209# Assembling debian-installer configuration
210if [ "${LB_DEBIAN_INSTALLER}" != "false" ]
211then
212        LINUX_LIVE="title\t\tLive:\nroot\n\n${LINUX_LIVE}"
213        LINUX_INSTALL="title\t\tInstaller:\nroot"
214
215        VMLINUZ_DI="install/vmlinuz"
216        INITRD_DI="install/initrd.gz"
217        APPEND_DI="vga=normal"
218
219        VMLINUZ_GI="install/gtk/vmlinuz"
220        INITRD_GI="install/gtk/initrd.gz"
221        APPEND_GI="video=vesa:ywrap,mtrr vga=788"
222
223        if [ -f "binary/${VMLINUZ_DI}" ] && [ -f "binary/${INITRD_DI}" ]
224        then
225                Grub_install_entry "Text" "${VMLINUZ_DI}" "${INITRD_DI}" "${APPEND_DI}"
226        fi
227
228        if [ -f "binary/${VMLINUZ_GI}" ] && [ -f "binary/${INITRD_GI}" ]
229        then
230                Grub_install_entry "GUI" "${VMLINUZ_GI}" "${INITRD_GI}" "${APPEND_GI}"
231        fi
232fi
233
234LINUX_INSTALL="$(/bin/echo ${LINUX_INSTALL} | sed -e 's|binary||g' -e 's|//|/|g')"
235
236# Assembling memtest configuration
237if [ -f "${DESTDIR_LIVE}"/memtest ]
238then
239        MEMTEST="title\t\tOther:\nroot"
240        MEMTEST="${MEMTEST}\n\ntitle\t\t${LB_MEMTEST}\nkernel\t\t/$(basename ${DESTDIR_LIVE})/memtest"
241        MEMTEST="$(/bin/echo ${MEMTEST} | sed -e 's|//|/|g')"
242fi
243
244# Copying templates
245mkdir -p binary/boot/grub
246cp -r "${TEMPLATES}"/* binary/boot/grub
247
248case ${LB_BINARY_IMAGES} in
249        iso*)
250                FILES="chroot/usr/lib/grub/*/stage2_eltorito"
251                ;;
252
253        hdd*|tar)
254                FILES="chroot/usr/lib/grub/*/stage1 chroot/usr/lib/grub/*/e2fs_stage1_5 chroot/usr/lib/grub/*/stage2"
255                ;;
256esac
257
258if [ "${LB_BUILD_WITH_CHROOT}" = "false" ]
259then
260        FILES="$(echo ${FILES} | sed -e 's|chroot||g')"
261fi
262
263# Copying grub
264cp ${FILES} binary/boot/grub
265
266# Copying local configuration file
267if [ -f config/binary_grub/menu.lst ]
268then
269        cp config/binary_grub/menu.lst binary/boot/grub/menu.lst
270fi
271
272# Copying splash screen
273if [ -f config/binary_grub/splash.xpm.gz ]
274then
275        LB_GRUB_SPLASH="config/binary_grub/splash.xpm.gz"
276elif [ -f config/binary_grub/splash.xpm ]
277then
278        LB_GRUB_SPLASH="config/binary_grub/splash.xpm"
279fi
280
281if [ -n "${LB_GRUB_SPLASH}" ]
282then
283        if [ "${LB_GRUB_SPLASH}" = "none" ]
284        then
285                # Removing splash file
286                rm -f binary/boot/grub/splash.xpm.gz
287
288                # Removing splash entry
289                sed -i -e "s|splashimage.*||" binary/boot/grub/menu.lst
290        else
291                # Overwriting splash file
292                cp -f "${LB_GRUB_SPLASH}" binary/boot/grub
293                sed -i -e "s|splashimage.*|splashimage /boot/grub/$(basename ${LB_GRUB_SPLASH})|" binary/boot/grub/menu.lst
294        fi
295fi
296
297sed -i -e "s|LINUX_LIVE|${LINUX_LIVE}|" -e "s|LINUX_INSTALL|${LINUX_INSTALL}|" -e "s|MEMTEST|${MEMTEST}|" binary/boot/grub/menu.lst
298sed -i -e "s|LB_BOOTAPPEND_INSTALL|${LB_BOOTAPPEND_INSTALL}|" -e "s|LB_BOOTAPPEND_LIVE|${LB_BOOTAPPEND_LIVE}|" binary/boot/grub/menu.lst
299
300sed -i -e 's|\ $||g' binary/boot/grub/menu.lst
301
302# Saving cache
303Save_cache cache/packages.binary
304
305# Removing depends
306Remove_package
307
308# Creating stage file
309Create_stagefile .build/binary_grub
Note: See TracBrowser for help on using the repository browser.