Releasing debian version 4.0.3-1.
[live-build.git] / scripts / build / lb_binary_syslinux
1 #!/bin/sh
2
3 ## live-build(7) - System Build Scripts
4 ## Copyright (C) 2006-2012 Daniel Baumann <daniel@debian.org>
5 ##
6 ## live-build 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
11 set -e
12
13 # Including common functions
14 . "${LB_BASE:-/usr/share/live/build}"/scripts/build.sh
15
16 # Setting static variables
17 DESCRIPTION="$(Echo 'installs syslinux into binary')"
18 HELP=""
19 USAGE="${PROGRAM} [--force]"
20
21 Arguments "${@}"
22
23 # Reading configuration files
24 Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
25 Set_defaults
26
27 if [ "${LB_BOOTLOADER}" != "syslinux" ]
28 then
29         exit 0
30 fi
31
32 Echo_message "Begin installing syslinux..."
33
34 # Requiring stage file
35 Require_stagefile .build/config .build/bootstrap
36
37 # Checking stage file
38 Check_stagefile .build/binary_syslinux
39
40 # Checking lock file
41 Check_lockfile .lock
42
43 # Creating lock file
44 Create_lockfile .lock
45
46 # Check architecture
47 Check_architectures amd64 i386
48 Check_crossarchitectures
49
50 # Assembling image specifics
51 case "${LB_BINARY_IMAGES}" in
52         iso*)
53                 _BOOTLOADER="isolinux"
54
55                 case "${LB_MODE}" in
56                         progress)
57                                 _TARGET="binary/boot"
58                                 ;;
59
60                         *)
61                                 _TARGET="binary/isolinux"
62                                 ;;
63                 esac
64                 ;;
65
66         net*)
67                 _BOOTLOADER="pxelinux"
68                 _TARGET="tftpboot"
69                 ;;
70
71         hdd*|*)
72                 _BOOTLOADER="syslinux"
73
74                 case "${LB_MODE}" in
75                         progress)
76                                 _TARGET="binary/boot"
77                                 ;;
78
79                         *)
80                                 _TARGET="binary/syslinux"
81                                 ;;
82                 esac
83                 ;;
84 esac
85
86 # Checking depends
87 case "${LB_BUILD_WITH_CHROOT}" in
88         true)
89                 Check_package chroot/usr/bin/syslinux syslinux
90                 Check_package chroot/usr/lib/syslinux syslinux-common
91
92                 if [ "${LB_SYSLINUX_THEME}" != "live-build" ]
93                 then
94                         Check_package chroot/usr/share/syslinux/themes/${LB_SYSLINUX_THEME} syslinux-themes-${LB_SYSLINUX_THEME}
95
96                         case "${LB_MODE}" in
97                                 ubuntu)
98                                         Check_package chroot/usr/share/gfxboot-theme-ubuntu/bootlogo.tar.gz gfxboot-theme-ubuntu
99                                         ;;
100                         esac
101                 fi
102                 ;;
103
104         false)
105                 if [ ! -e /usr/bin/syslinux ]
106                 then
107                         # syslinux
108                         Echo_error "/usr/bin/syslinux - no such file."
109                         exit 1
110                 fi
111
112                 if [ ! -e /usr/lib/syslinux ]
113                 then
114                         # syslinux-common
115                         Echo_error "/usr/lib/syslinux - no such directory"
116                         exit 1
117                 fi
118
119                 if [ "${LB_SYSLINUX_THEME}" != "live-build" ]
120                 then
121                         if [ ! -e /usr/share/syslinux/themes/${LB_SYSLINUX_THEME} ]
122                         then
123                                 # syslinux-theme
124                                 Echo_error "/usr/share/syslinux/themes/${LB_SYSLINUX_THEME} - no such directory."
125                                 exit 1
126                         fi
127                 fi
128                 ;;
129 esac
130
131 # Restoring cache
132 Restore_cache cache/packages.binary
133
134 # Installing depends
135 Install_package
136
137 # FIXME: cleanup, unify, and extend themes for ${_BOOTLOADER}-live and ${_BOOTLOADER}-installer
138 if [ "${LB_SYSLINUX_THEME}" = "live-build" ]
139 then
140         if [ -e "config/bootloaders/${_BOOTLOADER}" ]
141         then
142                 # Internal local copy
143                 _SOURCE="config/bootloaders/${_BOOTLOADER}"
144         else
145                 # Internal system copy
146                 _SOURCE="${LB_BASE:-/usr/share/live/build}/bootloaders/${_BOOTLOADER}"
147         fi
148 else
149         # External copy from chroot or system
150         _SOURCE="/usr/share/syslinux/themes/${LB_SYSLINUX_THEME}/${_BOOTLOADER}-live"
151 fi
152
153 # Copying files
154 mkdir -p $(dirname ${_TARGET})
155
156 case "${LB_BUILD_WITH_CHROOT}" in
157         true)
158                 # Copy in two steps since the theme can have absolute symlinks and would therefore not be dereferenced correctly
159                 if [ "${LB_SYSLINUX_THEME}" = "live-build" ]
160                 then
161                         cp -a ${_SOURCE} chroot/root
162                         Chroot chroot cp -aL /root/$(basename ${_SOURCE}) /root/$(basename ${_SOURCE}).tmp
163                         rm -rf chroot/$(basename ${_SOURCE})
164                 else
165                         Chroot chroot cp -aL ${_SOURCE} /root/$(basename ${_SOURCE}).tmp
166                 fi
167
168                 case "${LB_MODE}" in
169                         ubuntu)
170                                 Chroot chroot "tar xfz /usr/share/gfxboot-theme-ubuntu/bootlogo.tar.gz -C /root/$(basename ${_SOURCE}).tmp"
171                                 ;;
172                 esac
173
174                 mv chroot/root/$(basename ${_SOURCE}).tmp ${_TARGET}
175                 ;;
176
177         false)
178                 cp -aL ${_SOURCE}/* ${_TARGET}
179
180                 case "${LB_MODE}" in
181                         ubuntu)
182                                 tar xfz /usr/share/gfxboot-theme-ubuntu/bootlogo.tar.gz -C ${_TARGET}
183                                 ;;
184                 esac
185                 ;;
186 esac
187
188 # Configuring files
189 if [ -e "${_TARGET}/live.cfg.in" ]
190 then
191         # This is all rather suboptimal.. needs prettifying at some point
192         _FLAVOURS="$(echo ${LB_LINUX_FLAVOURS} | wc -w)"
193
194         case "${_FLAVOURS}" in
195                 1)
196                         mv binary/live/vmlinuz-* binary/live/vmlinuz
197                         mv binary/live/initrd.img-* binary/live/initrd.img
198
199                         sed -e "s|@FLAVOUR@|${LB_LINUX_FLAVOUR}|g" \
200                             -e "s|@KERNEL@|/live/vmlinuz|g" \
201                             -e "s|@INITRD@|/live/initrd.img|g" \
202                             -e "s|@LB_BOOTAPPEND_LIVE@|${LB_BOOTAPPEND_LIVE}|g" \
203                             -e "s|@LB_BOOTAPPEND_FAILSAFE@|${LB_BOOTAPPEND_FAILSAFE}|g" \
204                         "${_TARGET}/live.cfg.in" >> "${_TARGET}/live.cfg"
205
206                         rm -f "${_TARGET}/live.cfg.in"
207                         ;;
208
209                 *)
210                         _NUMBER="0"
211
212                         for _FLAVOUR in ${LB_LINUX_FLAVOURS}
213                         do
214                                 _NUMBER="$((${_NUMBER} + 1))"
215
216                                 mv binary/live/vmlinuz-*-${_FLAVOUR} binary/live/vmlinuz${_NUMBER}
217                                 mv binary/live/initrd.img-*-${_FLAVOUR} binary/live/initrd${_NUMBER}.img
218
219                                 sed -e "s|@FLAVOUR@|${_FLAVOUR}|g" \
220                                     -e "s|@KERNEL@|/live/vmlinuz${_NUMBER}|g" \
221                                     -e "s|@INITRD@|/live/initrd${_NUMBER}.img|g" \
222                                     -e "s|@LB_BOOTAPPEND_LIVE@|${LB_BOOTAPPEND_LIVE}|g" \
223                                     -e "s|@LB_BOOTAPPEND_FAILSAFE@|${LB_BOOTAPPEND_FAILSAFE}|g" \
224                                 "${_TARGET}/live.cfg.in" >> "${_TARGET}/live.cfg"
225                         done
226
227                         rm -f "${_TARGET}/live.cfg.in"
228                         ;;
229         esac
230 elif [ -e "${_TARGET}/live.cfg" ]
231 then
232         sed -i  -e "s|@LB_BOOTAPPEND_LIVE@|${LB_BOOTAPPEND_LIVE}|g" \
233                 -e "s|@LB_BOOTAPPEND_FAILSAFE@|${LB_BOOTAPPEND_FAILSAFE}|g" \
234         ${_TARGET}/live.cfg
235 fi
236
237 if [ -e ${_TARGET}/install.cfg ]
238 then
239         sed -i -e "s|@LB_BOOTAPPEND_INSTALL@|${LB_BOOTAPPEND_INSTALL}|g" \
240         ${_TARGET}/install.cfg
241 fi
242
243 case "${LB_MODE}" in
244         progress)
245                 for _FILE in "${_TARGET}/isolinux.bin" "${_TARGET}/isolinux.cfg" "${_TARGET}/syslinux.cfg"
246                 do
247                         if [ -e "${_FILE}" ]
248                         then
249                                 mv "${_FILE}" "${_TARGET}/$(echo ${_FILE} | sed -e 's|.*linux|boot|')"
250                         fi
251                 done
252                 ;;
253 esac
254
255 case "${LB_BUILD_WITH_CHROOT}" in
256         true)
257                 # Saving cache
258                 Save_cache cache/packages.binary
259
260                 # Removing depends
261                 Remove_package
262                 ;;
263 esac
264
265 # Creating stage file
266 Create_stagefile .build/binary_syslinux