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