Updating splash.svg handling for unchrooted and chrooted builds.
[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         netboot)
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                 case "${LB_SYSLINUX_THEME}" in
93                         live-build)
94                                 Check_package chroot/usr/bin/rsvg librsvg2-bin
95                                 ;;
96
97                         *)
98                                 Check_package chroot/usr/share/syslinux/themes/${LB_SYSLINUX_THEME} syslinux-themes-${LB_SYSLINUX_THEME}
99
100                                 case "${LB_MODE}" in
101                                         ubuntu)
102                                                 Check_package chroot/usr/share/gfxboot-theme-ubuntu/bootlogo.tar.gz gfxboot-theme-ubuntu
103                                                 ;;
104                                 esac
105                                 ;;
106                 esac
107                 ;;
108
109         false)
110                 if [ ! -e /usr/bin/syslinux ]
111                 then
112                         # syslinux
113                         Echo_error "/usr/bin/syslinux - no such file."
114                         exit 1
115                 fi
116
117                 if [ ! -e /usr/lib/syslinux ]
118                 then
119                         # syslinux-common
120                         Echo_error "/usr/lib/syslinux - no such directory"
121                         exit 1
122                 fi
123
124                 case "${LB_SYSLINUX_THEME}" in
125                         live-build)
126                                 if [ -e /usr/bin/rsvg ]
127                                 then
128                                         # librsvg2-bin
129                                         Echo_error "/usr/bin/rsvg - no such file"
130                                         exit 1
131                                 fi
132                                 ;;
133
134                         *)
135                                 if [ ! -e /usr/share/syslinux/themes/${LB_SYSLINUX_THEME} ]
136                                 then
137                                         # syslinux-theme
138                                         Echo_error "/usr/share/syslinux/themes/${LB_SYSLINUX_THEME} - no such directory."
139                                         exit 1
140                                 fi
141                                 ;;
142                 esac
143                 ;;
144 esac
145
146 # Restoring cache
147 Restore_cache cache/packages.binary
148
149 # Installing depends
150 Install_package
151
152 # FIXME: cleanup, unify, and extend themes for ${_BOOTLOADER}-live and ${_BOOTLOADER}-installer
153 if [ "${LB_SYSLINUX_THEME}" = "live-build" ]
154 then
155         if [ -e "config/bootloaders/${_BOOTLOADER}" ]
156         then
157                 # Internal local copy
158                 _SOURCE="config/bootloaders/${_BOOTLOADER}"
159         else
160                 # Internal system copy
161                 _SOURCE="${LB_BASE:-/usr/share/live/build}/bootloaders/${_BOOTLOADER}"
162         fi
163 else
164         # External copy from chroot or system
165         _SOURCE="/usr/share/syslinux/themes/${LB_SYSLINUX_THEME}/${_BOOTLOADER}-live"
166 fi
167
168 # Copying files
169 mkdir -p $(dirname ${_TARGET})
170
171 case "${LB_BUILD_WITH_CHROOT}" in
172         true)
173                 # Copy in two steps since the theme can have absolute symlinks and would therefore not be dereferenced correctly
174                 if [ "${LB_SYSLINUX_THEME}" = "live-build" ]
175                 then
176                         cp -a ${_SOURCE} chroot/root
177                         Chroot chroot cp -aL /root/$(basename ${_SOURCE}) /root/$(basename ${_SOURCE}).tmp
178                         rm -rf chroot/$(basename ${_SOURCE})
179                 else
180                         Chroot chroot cp -aL ${_SOURCE} /root/$(basename ${_SOURCE}).tmp
181                 fi
182
183                 case "${LB_MODE}" in
184                         ubuntu)
185                                 Chroot chroot "tar xfz /usr/share/gfxboot-theme-ubuntu/bootlogo.tar.gz -C /root/$(basename ${_SOURCE}).tmp"
186                                 ;;
187                 esac
188
189                 mv chroot/root/$(basename ${_SOURCE}).tmp ${_TARGET}
190                 ;;
191
192         false)
193                 cp -aL ${_SOURCE}/* ${_TARGET}
194
195                 case "${LB_MODE}" in
196                         ubuntu)
197                                 tar xfz /usr/share/gfxboot-theme-ubuntu/bootlogo.tar.gz -C ${_TARGET}
198                                 ;;
199                 esac
200                 ;;
201 esac
202
203 # Configuring files
204 if [ -e "${_TARGET}/live.cfg.in" ]
205 then
206         # This is all rather suboptimal.. needs prettifying at some point
207         _FLAVOURS="$(echo ${LB_LINUX_FLAVOURS} | wc -w)"
208
209         case "${_FLAVOURS}" in
210                 1)
211                         mv binary/live/vmlinuz-* binary/live/vmlinuz
212                         mv binary/live/initrd.img-* binary/live/initrd.img
213
214                         sed -e "s|@FLAVOUR@|${LB_LINUX_FLAVOUR}|g" \
215                             -e "s|@KERNEL@|/live/vmlinuz|g" \
216                             -e "s|@INITRD@|/live/initrd.img|g" \
217                             -e "s|@LB_BOOTAPPEND_LIVE@|${LB_BOOTAPPEND_LIVE}|g" \
218                             -e "s|@LB_BOOTAPPEND_FAILSAFE@|${LB_BOOTAPPEND_FAILSAFE}|g" \
219                         "${_TARGET}/live.cfg.in" >> "${_TARGET}/live.cfg"
220
221                         rm -f "${_TARGET}/live.cfg.in"
222                         ;;
223
224                 *)
225                         _NUMBER="0"
226
227                         for _FLAVOUR in ${LB_LINUX_FLAVOURS}
228                         do
229                                 _NUMBER="$((${_NUMBER} + 1))"
230
231                                 mv binary/live/vmlinuz-*-${_FLAVOUR} binary/live/vmlinuz${_NUMBER}
232                                 mv binary/live/initrd.img-*-${_FLAVOUR} binary/live/initrd${_NUMBER}.img
233
234                                 sed -e "s|@FLAVOUR@|${_FLAVOUR}|g" \
235                                     -e "s|@KERNEL@|/live/vmlinuz${_NUMBER}|g" \
236                                     -e "s|@INITRD@|/live/initrd${_NUMBER}.img|g" \
237                                     -e "s|@LB_BOOTAPPEND_LIVE@|${LB_BOOTAPPEND_LIVE}|g" \
238                                     -e "s|@LB_BOOTAPPEND_FAILSAFE@|${LB_BOOTAPPEND_FAILSAFE}|g" \
239                                 "${_TARGET}/live.cfg.in" >> "${_TARGET}/live.cfg"
240                         done
241
242                         rm -f "${_TARGET}/live.cfg.in"
243                         ;;
244         esac
245 elif [ -e "${_TARGET}/live.cfg" ]
246 then
247         sed -i  -e "s|@LB_BOOTAPPEND_LIVE@|${LB_BOOTAPPEND_LIVE}|g" \
248                 -e "s|@LB_BOOTAPPEND_FAILSAFE@|${LB_BOOTAPPEND_FAILSAFE}|g" \
249         ${_TARGET}/live.cfg
250 fi
251
252 if [ -e ${_TARGET}/install.cfg ]
253 then
254         sed -i -e "s|@LB_BOOTAPPEND_INSTALL@|${LB_BOOTAPPEND_INSTALL}|g" \
255         ${_TARGET}/install.cfg
256 fi
257
258 if [ -e "${_TARGET}/splash.svg.in" ]
259 then
260         case "${LB_MODE}" in
261                 progress)
262                         _PROJECT="Progress Linux"
263
264                         if ls config/package-lists/client-gnome.list*
265                         then
266                                 _DESCRIPTION="Client GNOME"
267                         elif ls config/package-lists/client-lxde.list* > /dev/null 2>&1
268                         then
269                                 _DESCRIPTION="Client LXDE"
270                         elif ls config/package-lists/server-lxc.list* > /dev/null 2>&1
271                         then
272                                 _DESCRIPTION="Server LXC"
273                         else
274                                 _DESCRIPTION="Standard"
275                         fi
276                         ;;
277
278                 *)
279                         _PROJECT="Debian GNU/Linux"
280                         _DESCRIPTION=""
281                         ;;
282
283         esac
284
285         eval _VERSION="$`echo RELEASE_${LB_DISTRIBUTION}`"
286         _DISTRIBUTION="${LB_DISTRIBUTION}"
287         _ARCHITECTURE="${LB_ARCHITECTURES}"
288         _DATE=$(date -R)
289         _YEAR="$(date +%Y)"
290         _MONTH="$(date +%m)"
291         _DAY="$(date +%d)"
292         _HOUR="$(date +%H)"
293         _MINUTE="$(date +%M)"
294         _SECOND="$(date +%S)"
295         _LINUX_VERSIONS="$(for _LINUX in chroot/boot/vmlinuz-* ; do chroot chroot apt-cache policy $(basename ${_LINUX} | sed -e 's|vmlinuz-|linux-image-|') | awk '/Installed: / { print $2 }' ; done | sort -u)"
296         _LIVE_BUILD_VERSIONS="$(chroot chroot apt-cache policy live-build | awk '/Installed: / { print $2 }')"
297         _LIVE_BOOT_VERSIONS="$(chroot chroot apt-cache policy live-boot | awk '/Installed: / { print $2 }')"
298         _LIVE_CONFIG_VERSION="$(chroot chroot apt-cache policy live-config | awk '/Installed: / { print $2 }')"
299         _LIVE_TOOLS_VERSION="$(chroot chroot apt-cache policy live-tools | awk '/Installed: / { print $2 }')"
300
301         sed     -e "s|@PROJECT@|${_PROJECT}|g" \
302                 -e "s|@DISTRIBUTION@|${_DISTRIBUTION}|g" \
303                 -e "s|@VERSION@|${_VERSION}|g" \
304                 -e "s|@ARCHITECTURE@|${_ARCHITECTURE}|g" \
305                 -e "s|@DESCRIPTION@|${_DESCRIPTION}|g" \
306                 -e "s|@DATE@|${_DATE}|g" \
307                 -e "s|@YEAR@|${_YEAR}|g" \
308                 -e "s|@MONTH@|${_MONTH}|g" \
309                 -e "s|@DAY@|${_DAY}|g" \
310                 -e "s|@HOUR@|${_HOUR}|g" \
311                 -e "s|@MINUTE@|${_MINUTE}|g" \
312                 -e "s|@SECOND@|${_SECOND}|g" \
313                 -e "s|@LINUX_VERSIONS@|${_LINUX_VERSIONS}|g" \
314                 -e "s|@LIVE_BUILD_VERSION@|${_LIVE_BUILD_VERSIONS}|g" \
315                 -e "s|@LIVE_BOOT_VERSION@|${_LIVE_BOOT_VERSION}|g" \
316                 -e "s|@LIVE_CONFIG_VERSION@|${_LIVE_CONFIG_VERSION}|g" \
317                 -e "s|@LIVE_TOOLS_VERSION@|${_LIVE_TOOLS_VERSION}|g" \
318         "${_TARGET}/splash.svg.in" > "${_TARGET}/splash.svg"
319
320         case "${LB_BUILD_WITH_CHROOT}" in
321                 true)
322                         cp "${_TARGET}/splash.svg" chroot
323                         Chroot chroot "rsvg --format png --height 480 --width 640 splash.svg splash.png"
324                         mv chroot/splash.png "${_TARGET}"
325                         rm -f chroot/splash.svg
326                         ;;
327
328                 false)
329                         rsvg --format png --height 480 --width 640 "${_TARGET}/splash.svg" "${_TARGET}/splash.png"
330                         ;;
331         esac
332
333         rm -f "${_TARGET}/splash.svg.in" "${_TARGET}/splash.svg"
334 fi
335
336 case "${LB_MODE}" in
337         progress)
338                 for _FILE in "${_TARGET}/isolinux.bin" "${_TARGET}/isolinux.cfg" "${_TARGET}/syslinux.cfg"
339                 do
340                         if [ -e "${_FILE}" ]
341                         then
342                                 mv "${_FILE}" "${_TARGET}/$(echo ${_FILE} | sed -e 's|.*linux|boot|')"
343                         fi
344                 done
345                 ;;
346 esac
347
348 case "${LB_BUILD_WITH_CHROOT}" in
349         true)
350                 # Saving cache
351                 Save_cache cache/packages.binary
352
353                 # Removing depends
354                 Remove_package
355                 ;;
356 esac
357
358 # Creating stage file
359 Create_stagefile .build/binary_syslinux