Releasing debian version 4.0.1-1.
[live-build.git] / scripts / build / 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 ## 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
11 set -e
12
13 # Including common functions
14 [ -e "${LIVE_BUILD}/scripts/build.sh" ] && . "${LIVE_BUILD}/scripts/build.sh" || . /usr/lib/live/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                 if [ -n "${LIVE_BUILD}" ]
162                 then
163                         _SOURCE="${LIVE_BUILD}/share/bootloaders/${_BOOTLOADER}"
164                 else
165                         _SOURCE="/usr/share/live/build/bootloaders/${_BOOTLOADER}"
166                 fi
167         fi
168 else
169         # External copy from chroot or system
170         _SOURCE="/usr/share/syslinux/themes/${LB_SYSLINUX_THEME}/${_BOOTLOADER}-live"
171 fi
172
173 # Copying files
174 case "${LB_BUILD_WITH_CHROOT}" in
175         true)
176                 mkdir -p $(dirname ${_TARGET})
177
178                 # Copy in two steps since the theme can have absolute symlinks and would therefore not be dereferenced correctly
179                 if [ "${LB_SYSLINUX_THEME}" = "live-build" ]
180                 then
181                         cp -a ${_SOURCE} chroot/root
182                         Chroot chroot cp -aL /root/$(basename ${_SOURCE}) /root/$(basename ${_SOURCE}).tmp
183                         rm -rf chroot/$(basename ${_SOURCE})
184                 else
185                         Chroot chroot cp -aL ${_SOURCE} /root/$(basename ${_SOURCE}).tmp
186                 fi
187
188                 case "${LB_MODE}" in
189                         ubuntu)
190                                 Chroot chroot "tar xfz /usr/share/gfxboot-theme-ubuntu/bootlogo.tar.gz -C /root/$(basename ${_SOURCE}).tmp"
191                                 ;;
192                 esac
193
194                 mv chroot/root/$(basename ${_SOURCE}).tmp ${_TARGET}
195                 ;;
196
197         false)
198                 mkdir -p ${_TARGET}
199
200                 cp -aL ${_SOURCE}/* ${_TARGET}
201
202                 case "${LB_MODE}" in
203                         ubuntu)
204                                 tar xfz /usr/share/gfxboot-theme-ubuntu/bootlogo.tar.gz -C ${_TARGET}
205                                 ;;
206                 esac
207                 ;;
208 esac
209
210 # Configuring files
211 if [ -e "${_TARGET}/live.cfg.in" ]
212 then
213         # This is all rather suboptimal.. needs prettifying at some point
214         _FLAVOURS="$(echo ${LB_LINUX_FLAVOURS} | wc -w)"
215
216         case "${_FLAVOURS}" in
217                 1)
218                         mv binary/live/vmlinuz-* binary/live/vmlinuz
219                         mv binary/live/initrd.img-* binary/live/initrd.img
220
221                         sed -e "s|@FLAVOUR@|${LB_LINUX_FLAVOURS}|g" \
222                             -e "s|@KERNEL@|/live/vmlinuz|g" \
223                             -e "s|@INITRD@|/live/initrd.img|g" \
224                             -e "s|@LB_BOOTAPPEND_LIVE@|${LB_BOOTAPPEND_LIVE}|g" \
225                             -e "s|@LB_BOOTAPPEND_FAILSAFE@|${LB_BOOTAPPEND_FAILSAFE}|g" \
226                         "${_TARGET}/live.cfg.in" >> "${_TARGET}/live.cfg"
227
228                         rm -f "${_TARGET}/live.cfg.in"
229                         ;;
230
231                 *)
232                         _NUMBER="0"
233
234                         for _FLAVOUR in ${LB_LINUX_FLAVOURS}
235                         do
236                                 _NUMBER="$((${_NUMBER} + 1))"
237
238                                 mv binary/live/vmlinuz-*-${_FLAVOUR} binary/live/vmlinuz${_NUMBER}
239                                 mv binary/live/initrd.img-*-${_FLAVOUR} binary/live/initrd${_NUMBER}.img
240
241                                 sed -e "s|@FLAVOUR@|${_FLAVOUR}|g" \
242                                     -e "s|@KERNEL@|/live/vmlinuz${_NUMBER}|g" \
243                                     -e "s|@INITRD@|/live/initrd${_NUMBER}.img|g" \
244                                     -e "s|@LB_BOOTAPPEND_LIVE@|${LB_BOOTAPPEND_LIVE}|g" \
245                                     -e "s|@LB_BOOTAPPEND_FAILSAFE@|${LB_BOOTAPPEND_FAILSAFE}|g" \
246                                 "${_TARGET}/live.cfg.in" >> "${_TARGET}/live.cfg"
247                         done
248
249                         rm -f "${_TARGET}/live.cfg.in"
250                         ;;
251         esac
252 elif [ -e "${_TARGET}/live.cfg" ]
253 then
254         sed -i  -e "s|@LB_BOOTAPPEND_LIVE@|${LB_BOOTAPPEND_LIVE}|g" \
255                 -e "s|@LB_BOOTAPPEND_FAILSAFE@|${LB_BOOTAPPEND_FAILSAFE}|g" \
256         ${_TARGET}/live.cfg
257 fi
258
259 if [ -e ${_TARGET}/install.cfg ]
260 then
261         sed -i -e "s|@LB_BOOTAPPEND_INSTALL@|${LB_BOOTAPPEND_INSTALL}|g" \
262         ${_TARGET}/install.cfg
263 fi
264
265 if [ -e "${_TARGET}/splash.svg.in" ]
266 then
267         case "${LB_MODE}" in
268                 progress)
269                         _PROJECT="Progress Linux"
270
271                         if ls config/package-lists/client-gnome.list*
272                         then
273                                 _DESCRIPTION="Client GNOME"
274                         elif ls config/package-lists/client-lxde.list* > /dev/null 2>&1
275                         then
276                                 _DESCRIPTION="Client LXDE"
277                         elif ls config/package-lists/server-lxc.list* > /dev/null 2>&1
278                         then
279                                 _DESCRIPTION="Server LXC"
280                         else
281                                 _DESCRIPTION="Standard"
282                         fi
283                         ;;
284
285                 *)
286                         _PROJECT="Debian GNU/Linux"
287                         _DESCRIPTION=""
288                         ;;
289
290         esac
291
292         eval _VERSION="$`echo RELEASE_${LB_DISTRIBUTION}`"
293         _DISTRIBUTION="${LB_DISTRIBUTION}"
294         _ARCHITECTURE="${LB_ARCHITECTURES}"
295         _DATE=$(date -R)
296         _YEAR="$(date +%Y)"
297         _MONTH="$(date +%m)"
298         _DAY="$(date +%d)"
299         _HOUR="$(date +%H)"
300         _MINUTE="$(date +%M)"
301         _SECOND="$(date +%S)"
302         _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)"
303         _LIVE_BUILD_VERSION="$(lb --version)"
304         _LIVE_BOOT_VERSION="$(chroot chroot apt-cache policy live-boot | awk '/Installed: / { print $2 }')"
305         _LIVE_CONFIG_VERSION="$(chroot chroot apt-cache policy live-config | awk '/Installed: / { print $2 }')"
306         _LIVE_TOOLS_VERSION="$(chroot chroot apt-cache policy live-tools | awk '/Installed: / { print $2 }')"
307
308         sed     -e "s|@PROJECT@|${_PROJECT}|g" \
309                 -e "s|@DISTRIBUTION@|${_DISTRIBUTION}|g" \
310                 -e "s|@VERSION@|${_VERSION}|g" \
311                 -e "s|@ARCHITECTURE@|${_ARCHITECTURE}|g" \
312                 -e "s|@DESCRIPTION@|${_DESCRIPTION}|g" \
313                 -e "s|@DATE@|${_DATE}|g" \
314                 -e "s|@YEAR@|${_YEAR}|g" \
315                 -e "s|@MONTH@|${_MONTH}|g" \
316                 -e "s|@DAY@|${_DAY}|g" \
317                 -e "s|@HOUR@|${_HOUR}|g" \
318                 -e "s|@MINUTE@|${_MINUTE}|g" \
319                 -e "s|@SECOND@|${_SECOND}|g" \
320                 -e "s|@LINUX_VERSIONS@|${_LINUX_VERSIONS}|g" \
321                 -e "s|@LIVE_BUILD_VERSION@|${_LIVE_BUILD_VERSION}|g" \
322                 -e "s|@LIVE_BOOT_VERSION@|${_LIVE_BOOT_VERSION}|g" \
323                 -e "s|@LIVE_CONFIG_VERSION@|${_LIVE_CONFIG_VERSION}|g" \
324                 -e "s|@LIVE_TOOLS_VERSION@|${_LIVE_TOOLS_VERSION}|g" \
325         "${_TARGET}/splash.svg.in" > "${_TARGET}/splash.svg"
326
327         case "${LB_BUILD_WITH_CHROOT}" in
328                 true)
329                         cp "${_TARGET}/splash.svg" chroot
330                         Chroot chroot "rsvg --format png --height 480 --width 640 splash.svg splash.png"
331                         mv chroot/splash.png "${_TARGET}"
332                         rm -f chroot/splash.svg
333                         ;;
334
335                 false)
336                         rsvg --format png --height 480 --width 640 "${_TARGET}/splash.svg" "${_TARGET}/splash.png"
337                         ;;
338         esac
339
340         rm -f "${_TARGET}/splash.svg.in" "${_TARGET}/splash.svg"
341 fi
342
343 case "${LB_MODE}" in
344         progress)
345                 for _FILE in "${_TARGET}/isolinux.bin" "${_TARGET}/isolinux.cfg" "${_TARGET}/syslinux.cfg"
346                 do
347                         if [ -e "${_FILE}" ]
348                         then
349                                 mv "${_FILE}" "${_TARGET}/$(echo ${_FILE} | sed -e 's|.*linux|boot|')"
350                         fi
351                 done
352                 ;;
353 esac
354
355 case "${LB_BUILD_WITH_CHROOT}" in
356         true)
357                 # Saving cache
358                 Save_cache cache/packages.binary
359
360                 # Removing depends
361                 Remove_package
362                 ;;
363 esac
364
365 # Creating stage file
366 Create_stagefile .build/binary_syslinux