3
# lh_binary_debian-installer(1) - install debian-installer into binary
4
# Copyright (C) 2006-2009 Daniel Baumann <daniel@debian.org>
6
# live-helper 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.
12
# Including common functions
13
. "${LH_BASE:-/usr/share/live-helper}"/functions.sh
15
# Setting static variables
16
DESCRIPTION="$(Echo 'install debian-installer into binary')"
18
USAGE="${PROGRAM} [--force]"
22
# Reading configuration files
23
Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
26
if [ "${LH_BINARY_IMAGES}" = "virtual-hdd" ]
31
if [ "${_DEBUG}" = "enabled" ]
33
WGET_OPTIONS="${WGET_OPTIONS} --verbose"
34
elif [ "${_QUIET}" = "enabled" ]
36
WGET_OPTIONS="${WGET_OPTIONS} --quiet"
38
WGET_OPTIONS="${WGET_OPTIONS} --no-verbose"
41
# Check d-i configuration
42
case "${LH_DEBIAN_INSTALLER}" in
43
enabled|cdrom|netinst|netboot|businesscard|live)
51
Echo_error "debian-installer flavour %s not supported." "${LH_DEBIAN_INSTALLER}"
56
Echo_message "Begin installing debian-installer..."
58
# Requiring stage file
59
Require_stagefile .stage/config .stage/bootstrap
62
Check_stagefile .stage/binary_debian-installer
71
Check_package chroot/usr/bin/wget wget
72
Check_package chroot/usr/bin/apt-ftparchive apt-utils
75
Restore_cache cache/packages_binary
80
# Setting destination directory
81
case "${LH_BINARY_IMAGES}" in
83
DESTDIR="tftpboot/debian-install/${LH_ARCHITECTURE}"
87
DESTDIR="binary/install"
89
# Workaround for syslinux (<< 3.36) which doesn't support long file/path names
90
if [ "${LH_DEBIAN_INSTALLER_DISTRIBUTION}" = "etch" ] && [ "${LH_BOOTLOADER}" = "syslinux" ]
97
DESTDIR="binary/install"
102
case "${LH_DEBIAN_INSTALLER}" in
103
businesscard|netboot|netinst)
104
DI_IMAGE_TYPE="netboot"
107
case "${LH_BINARY_IMAGES}" in
109
DI_IMAGE_TYPE="netboot"
113
DI_IMAGE_TYPE="cdrom"
119
# Set architecture-specific variables
120
case "${LH_ARCHITECTURE}" in
122
case "${DI_IMAGE_TYPE}" in
124
DI_REMOTE_BASE="${LH_ARCHITECTURE}/cdrom"
128
DI_REMOTE_BASE="${LH_ARCHITECTURE}/netboot"
132
DI_REMOTE_KERNEL="vmlinux"
133
DI_REMOTE_BASE_GTK="${DI_REMOTE_BASE}/gtk"
137
DEFAULT_FLAVOUR="$(echo ${LH_LINUX_FLAVOURS} | awk '{ print $1 }')"
138
DI_REMOTE_KERNEL="$(basename chroot/boot/vmlinuz-*${DEFAULT_FLAVOUR})"
139
DI_REMOTE_BASE_GTK="none"
141
if [ "${LH_DEBIAN_INSTALLER_DISTRIBUTION}" = "etch" ]
143
DI_REMOTE_BASE="cdrom/2.6"
145
DI_REMOTE_BASE="cdrom"
149
case "${DI_IMAGE_TYPE}" in
151
DI_REMOTE_BASE="netboot/debian-installer/${LH_ARCHITECTURE}"
152
DI_REMOTE_BASE_GTK="netboot/gtk/debian-installer/${LH_ARCHITECTURE}"
153
DI_REMOTE_KERNEL="linux"
157
DI_REMOTE_BASE="cdrom"
158
DI_REMOTE_BASE_GTK="cdrom/gtk"
159
DI_REMOTE_KERNEL="vmlinuz"
165
Check_multiarchitecture
174
SOURCE="$(dpkg -f ${FILE} Source | awk '{ print $1 }')"
176
if [ -z "${SOURCE}" ]
178
SOURCE="$(basename ${FILE} | awk -F_ '{ print $1 }')"
183
LETTER="$(echo ${SOURCE} | sed 's|\(....\).*|\1|')"
187
LETTER="$(echo ${SOURCE} | sed 's|\(.\).*|\1|')"
192
mkdir -p "${TARGET}"/"${LETTER}"/"${SOURCE}"
195
cp "${FILE}" "${TARGET}"/"${LETTER}"/"${SOURCE}"
198
# Set absolute directory for caching; we require it when we call Download_file
199
# from a non-standard cwd.
200
_LH_CACHE_DIR="$(pwd)/cache/binary_debian-installer"
209
_LH_CACHE_FILE="${_LH_CACHE_DIR}/$(echo "${_LH_URL}" | sed 's|/|_|g')"
211
if [ ! -f "${_LH_CACHE_FILE}" ]
213
mkdir -p ${_LH_CACHE_DIR}
214
if ! wget ${WGET_OPTIONS} -O "${_LH_CACHE_FILE}" "${_LH_URL}"
216
rm -f "${_LH_CACHE_FILE}"
218
Echo_error "Could not download file: %s" "${_LH_URL}"
223
if [ "$(stat --printf %d "${_LH_CACHE_DIR}")" = "$(stat --printf %d ./)" ]
228
cp -f ${CP_OPTIONS} -- "${_LH_CACHE_FILE}" "${_LH_TARGET}"
232
INITRD_DI="initrd.gz"
233
DESTDIR_DI="${DESTDIR}"
235
VMLINUZ_GI="gtk/vmlinuz"
236
INITRD_GI="gtk/initrd.gz"
237
DESTDIR_GI="${DESTDIR}/gtk"
239
# Workaround for syslinux (<< 3.36) which doesn't support long file/path names
240
if [ "${LH_DEBIAN_INSTALLER_DISTRIBUTION}" = "etch" ]
242
case "${LH_BINARY_IMAGES}" in
244
VMLINUZ_DI="vmlinuz.di"
245
INITRD_DI="initrddi.gz"
246
DESTDIR_DI="${DESTDIR}"
248
VMLINUZ_GI="vmlinuz.gi"
249
INITRD_GI="initrdgi.gz"
250
DESTDIR_GI="${DESTDIR}"
255
if [ "${LH_DEBIAN_INSTALLER_DISTRIBUTION}" = "daily" ]
257
LH_DEBIAN_INSTALLER_DISTRIBUTION="sid"
259
# Debian Installer daily builds
260
case "${LH_ARCHITECTURE}" in
261
alpha|amd64|hppa|ia64|mips|mipsel|powerpc)
262
URL="http://d-i.debian.org/daily-images/${LH_ARCHITECTURE}/daily/"
266
URL="http://people.debian.org/~kmuto/d-i/images/daily/"
270
URL="http://people.debian.org/~joeyh/d-i/images/daily/"
274
URL="http://people.debian.org/~smarenka/d-i/images-m68k/daily/"
278
URL="http://lophos.multibuild.org/d-i/images/daily/"
282
URL="http://people.debian.org/~stappers/d-i/images/daily/"
286
Echo_error "No daily-builds found for your architecture."
291
URL="${LH_MIRROR_CHROOT}/dists/${LH_DEBIAN_INSTALLER_DISTRIBUTION}/main/installer-${LH_ARCHITECTURE}/current/images/"
294
mkdir -p "${DESTDIR_DI}"
296
if [ "${LH_ARCHITECTURE}" = "sparc" ] && [ "${DI_IMAGE_TYPE}" = "netboot" ]
298
# There are no prepared kernel/initrd pairs for sparc netboot so we
299
# must unpack them from a mini.iso
301
if [ "${LH_DEBIAN_INSTALLER_DISTRIBUTION}" = "etch" ]
303
Download_file mini.iso ${URL}/combined/2.6/mini.iso
305
Download_file mini.iso ${URL}/mini.iso
309
${LH_ROOT_COMMAND} mount -o loop -t iso9660 mini.iso mini.tmp
311
cp mini.tmp/boot/vmlinuz-${DEFAULT_FLAVOUR} "${DESTDIR}"/"${VMLINUZ_DI}"
312
cp mini.tmp/boot/initrd.gz "${DESTDIR}"/"${INITRD_DI}"
314
${LH_ROOT_COMMAND} umount mini.tmp
315
rm -rf mini.tmp mini.iso
317
# Downloading debian-installer
318
Download_file "${DESTDIR}"/"${VMLINUZ_DI}" ${URL}/${DI_REMOTE_BASE}/${DI_REMOTE_KERNEL}
319
Download_file "${DESTDIR}"/"${INITRD_DI}" ${URL}/${DI_REMOTE_BASE}/initrd.gz
321
# Downloading graphical-installer
322
DOWNLOAD_GTK_INSTALLER=0
323
if [ "${LH_DEBIAN_INSTALLER_GUI}" = "enabled" ]
325
case "${LH_ARCHITECTURE}" in
327
DOWNLOAD_GTK_INSTALLER=1
331
if [ "${LH_DEBIAN_INSTALLER}" = "netboot" ]
333
DOWNLOAD_GTK_INSTALLER=1
339
if [ ${DOWNLOAD_GTK_INSTALLER} -eq 1 ]
341
mkdir -p "${DESTDIR_GI}"
342
Download_file "${DESTDIR}"/"${VMLINUZ_GI}" ${URL}/${DI_REMOTE_BASE_GTK}/${DI_REMOTE_KERNEL}
343
Download_file "${DESTDIR}"/"${INITRD_GI}" ${URL}/${DI_REMOTE_BASE_GTK}/initrd.gz
347
# Only download additional packages if appropriate
348
if [ "${DI_IMAGE_TYPE}" != "netboot" ]
350
# Downloading additional packages
351
mkdir -p chroot/binary.deb/archives/partial
352
mkdir -p binary/pool/main
353
mv chroot/var/lib/dpkg/status chroot/var/lib/dpkg/status.tmp
354
touch chroot/var/lib/dpkg/status
356
case "${LH_ARCHITECTURE}" in
358
DI_REQ_PACKAGES="lilo grub"
359
DI_PACKAGES="${DI_REQ_PACKAGES} linux-image-2.6-amd64"
363
DI_REQ_PACKAGES="elilo lilo grub"
364
DI_PACKAGES="${DI_REQ_PACKAGES} linux-image-2.6-486 linux-image-2.6-686"
368
DI_REQ_PACKAGES="silo"
369
DI_PACKAGES="${DI_REQ_PACKAGES} linux-image-2.6-sparc64 linux-image-2.6-sparc64-smp"
371
if [ "${LH_DEBIAN_INSTALLER_DISTRIBUTION}" = "etch" ]
373
DI_PACKAGES="${DI_PACKAGES} linux-image-2.6-sparc32"
378
DI_REQ_PACKAGES="yaboot"
379
DI_PACKAGES="${DI_REQ_PACKAGES} linux-image-2.6-powerpc linux-image-2.6-powerpc64 linux-image-2.6-powerpc-smp"
381
if [ "${LH_DEBIAN_INSTALLER_DISTRIBUTION}" = "etch" ]
383
DI_PACKAGES="${DI_PACKAGES} linux-image-2.6-prep"
388
DI_PACKAGES="${DI_PACKAGES} busybox cryptsetup lvm2"
390
# Set apt command prefix
391
_LH_APT_COMMAND="apt-get ${APT_OPTIONS} -o Dir::Cache=/binary.deb -o APT::Install-Recommends=false --download-only"
393
if [ "${LH_DEBIAN_INSTALLER}" = "live" ]
395
# We don't want to duplicate .debs of packages in binary/pool that are already
396
# installed to target/ via live-installer.
398
# However, we need to force various packages' inclusion in binary/pool/main as
399
# d-i does not support (for example) re-installing grub from target/ - the grub
400
# .debs must actually exist.
402
# Modify dpkg status to show the required packages are not installed.
403
cp chroot/var/lib/dpkg/status.tmp chroot/var/lib/dpkg/status
404
for PACKAGE in ${DI_REQ_PACKAGES}
407
f == 1 { print "Status: purge ok not-installed"; f=0; next }
408
/Package: '"${PACKAGE}"'/ { f=1; }
410
' chroot/var/lib/dpkg/status > chroot/var/lib/dpkg/status.awk
411
mv chroot/var/lib/dpkg/status.awk chroot/var/lib/dpkg/status
414
# Download .deb's that we just marked as "purged" which caused broken dependencies
415
Chroot chroot ${_LH_APT_COMMAND} -f dist-upgrade
417
# Revert dpkg status file
418
mv chroot/var/lib/dpkg/status.tmp chroot/var/lib/dpkg/status
420
# Download .debs of the required packages
421
Chroot chroot ${_LH_APT_COMMAND} install ${DI_REQ_PACKAGES}
423
# Download .debs of the required packages
424
Chroot chroot ${_LH_APT_COMMAND} install ${DI_PACKAGES}
426
# Revert dpkg status file
427
mv chroot/var/lib/dpkg/status.tmp chroot/var/lib/dpkg/status
430
mv chroot/binary.deb ./
432
if Find_files binary.deb/archives/*.deb
434
for FILE in binary.deb/archives/*.deb
436
Install_file "${FILE}" "binary/pool/main"
440
if [ "${LH_DEBIAN_INSTALLER}" != "live" ]
442
# Including base debian packages
443
if [ -d cache/packages_bootstrap ]
445
for FILE in cache/packages_bootstrap/*.deb
447
Install_file "${FILE}" "binary/pool/main"
450
Echo_error "Could not find cache/packages_bootstrap."
451
Echo_error "You selected values of LH_CACHE, LH_CACHE_PACKAGES, LH_CACHE_STAGES and LH_DEBIAN_INSTALLER which will result in 'bootstrap' packages not being cached - these are required when integrating the Debian Installer."
456
# Including local debs
457
if Find_files config/binary_local-debs/*_"${LH_ARCHITECTURE}".deb
459
for FILE in config/binary_local-debs/*_"${LH_ARCHITECTURE}".deb
461
Install_file "${FILE}" "binary/pool/main"
465
if Find_files config/binary_local-debs/*_all.deb
467
for FILE in config/binary_local-debs/*_all.deb
469
Install_file "${FILE}" "binary/pool/main"
473
# Generating deb indices
474
mkdir -p binary/dists/${LH_DEBIAN_INSTALLER_DISTRIBUTION}/main/binary-${LH_ARCHITECTURE}
476
mv binary chroot/root
477
echo "cd /root/binary && apt-ftparchive packages pool/main > dists/${LH_DEBIAN_INSTALLER_DISTRIBUTION}/main/binary-${LH_ARCHITECTURE}/Packages" > chroot/binary.sh
478
Chroot chroot "sh binary.sh"
479
rm -f chroot/binary.sh
480
mv chroot/root/binary ./
482
gzip -9 -c binary/dists/${LH_DEBIAN_INSTALLER_DISTRIBUTION}/main/binary-${LH_ARCHITECTURE}/Packages > binary/dists/${LH_DEBIAN_INSTALLER_DISTRIBUTION}/main/binary-${LH_ARCHITECTURE}/Packages.gz
485
Download_file binary/dists/${LH_DEBIAN_INSTALLER_DISTRIBUTION}/main/binary-${LH_ARCHITECTURE}/Release "${LH_MIRROR_CHROOT}"/dists/"${LH_DEBIAN_INSTALLER_DISTRIBUTION}"/main/binary-"${LH_ARCHITECTURE}"/Release
490
# Downloading udeb indices
491
Download_file Packages.gz "${LH_MIRROR_CHROOT}"/dists/"${LH_DEBIAN_INSTALLER_DISTRIBUTION}"/main/debian-installer/binary-"${LH_ARCHITECTURE}"/Packages.gz
492
gunzip -c Packages.gz > Packages
495
UDEBS="$(awk '/Filename: / { print $2 }' Packages)"
500
if [ -f ../cache/packages_debian-installer.udeb/"$(basename ${UDEB})" ]
502
# Copying cached udebs
503
cp ../cache/packages_debian-installer.udeb/"$(basename ${UDEB})" ./
506
wget ${WGET_OPTIONS} "${LH_MIRROR_CHROOT}"/${UDEB}
511
rm -rf ../cache/packages_debian-installer.udeb
512
mkdir -p ../cache/packages_debian-installer.udeb
513
cp *.udeb ../cache/packages_debian-installer.udeb
515
# Including local udebs
516
if Find_files ../config/binary_local-udebs/*_"${LH_ARCHITECTURE}".udeb
518
for FILE in ../config/binary_local-udebs/*_"${LH_ARCHITECTURE}".udeb
520
Install_file "${FILE}" "pool/main"
522
# Prefer local udebs over downloaded udebs
523
rm -f "$(basename ${FILE} | awk -F_ '{ print $1 }')"_*.udeb
527
if Find_files ../config/binary_local-udebs/*_all.udeb
529
for FILE in ../config/binary_local-udebs/*_all.udeb
531
Install_file "${FILE}" "pool/main"
533
# Prefer local udebs over downloaded udebs
534
rm -f "$(basename ${FILE} | awk -F_ '{ print $1 }')"_*.udeb
539
grep -v "^#" "${LH_BASE}"/data/debian-cd/"${LH_DEBIAN_INSTALLER_DISTRIBUTION}"/udeb_exclude > exclude || true
540
grep -v "^#" "${LH_BASE}"/data/debian-cd/"${LH_DEBIAN_INSTALLER_DISTRIBUTION}"/exclude-udebs >> exclude || true
541
grep -v "^#" "${LH_BASE}"/data/debian-cd/"${LH_DEBIAN_INSTALLER_DISTRIBUTION}"/exclude-udebs-${LH_ARCHITECTURE} >> exclude || true
544
if [ -e ../config/binary_debian-installer/udeb_exclude ]
546
cat ../config/binary_debian-installer/udeb_exclude >> exclude
549
# Excluding udebs from excludes because we want them to be in the image on purpose
550
sed -i -e 's|di-utils-exit-installer||' exclude # used for live-installer-launcher
554
if [ "${LH_DEBIAN_INSTALLER}" = "live" ] && [ "${EXCLUDE}" = "live-installer" ]
559
rm -f ${EXCLUDE}_*.udeb
562
# Enable live-installer
563
if [ "${LH_DEBIAN_INSTALLER}" = "live" ] && [ "${LH_DEBIAN_INSTALLER_DISTRIBUTION}" != "etch" ]
566
rm -f pool/main/b/base-installer/bootstrap-base_*.udeb
569
rm -f bootstrap-base_*.udeb
575
if [ -f "$(basename ${UDEB})" ]
577
mkdir -p $(dirname ${UDEB})
578
mv "$(basename ${UDEB})" "$(dirname ${UDEB})"
582
# Creating udeb indices
583
mkdir -p dists/"${LH_DEBIAN_INSTALLER_DISTRIBUTION}"/main/debian-installer/binary-"${LH_ARCHITECTURE}"
586
mv binary.udeb chroot/root
587
echo "cd /root/binary.udeb && apt-ftparchive packages pool/main > dists/${LH_DEBIAN_INSTALLER_DISTRIBUTION}/main/debian-installer/binary-${LH_ARCHITECTURE}/Packages" > chroot/binary.sh
588
Chroot chroot "sh binary.sh"
589
rm -f chroot/binary.sh
590
mv chroot/root/binary.udeb ./
593
gzip -9 -c dists/${LH_DEBIAN_INSTALLER_DISTRIBUTION}/main/debian-installer/binary-${LH_ARCHITECTURE}/Packages > dists/${LH_DEBIAN_INSTALLER_DISTRIBUTION}/main/debian-installer/binary-${LH_ARCHITECTURE}/Packages.gz
595
rm -f Packages* exclude
596
find . | cpio -dmpu "${OLDPWD}"/binary
602
# Generating release file
603
mv binary chroot/root
605
cat > chroot/binary.sh << EOF
606
cd /root/binary && apt-ftparchive \
607
-o APT::FTPArchive::Release::Origin="Debian" \
608
-o APT::FTPArchive::Release::Label="Debian" \
609
-o APT::FTPArchive::Release::Suite="${LH_DEBIAN_INSTALLER_DISTRIBUTION}" \
610
-o APT::FTPArchive::Release::Version="4.0" \
611
-o APT::FTPArchive::Release::Codename="${LH_DEBIAN_INSTALLER_DISTRIBUTION}" \
612
-o APT::FTPArchive::Release::Date="$(date -R)" \
613
-o APT::FTPArchive::Release::Architectures="${LH_ARCHITECTURE}" \
614
-o APT::FTPArchive::Release::Components="main" \
615
-o APT::FTPArchive::Release::Description="Last updated: $(date -R)" \
616
release dists/${LH_DEBIAN_INSTALLER_DISTRIBUTION} > dists/${LH_DEBIAN_INSTALLER_DISTRIBUTION}/Release
619
Chroot chroot "sh binary.sh"
620
rm -f chroot/binary.sh
621
mv chroot/root/binary ./
623
# Creating dist symlinks
624
for DISTRIBUTION in frozen stable testing unstable
626
ln -s ${LH_DEBIAN_INSTALLER_DISTRIBUTION} binary/dists/${DISTRIBUTION}
629
if [ "${LH_BINARY_IMAGES}" != "usb-hdd" ]
631
ln -s . binary/debian
634
# Including preseeding files
635
if Find_files config/binary_debian-installer/*.cfg
637
cp config/binary_debian-installer/*.cfg binary/install
647
REPACK_TMPDIR="unpacked-initrd"
649
if [ -d "${INCLUDE_PATH}" ]
651
INCLUDE_PATH=$(readlink -f ${INCLUDE_PATH})
654
# cpio does not have a "extract to directory", so we must change directory
655
mkdir -p ${REPACK_TMPDIR}
658
gzip -d < ../${TARGET_INITRD} | cpio -i --make-directories --no-absolute-filenames
659
if [ ! -d "${INCLUDE_PATH}" ]
661
# Invoked the old way, just copy the preseeds
662
cp ../config/binary_debian-installer/*.cfg .
664
# New way, include target directory content in the initrd
665
REPACK_TMPDIR_ABS="${PWD}"
667
find -print0 | cpio -pumd0 --no-preserve-owner "${REPACK_TMPDIR_ABS}/"
670
find -print0 | cpio -H newc -o0 | gzip -9 > ../${TARGET_INITRD}
673
rm -rf ${REPACK_TMPDIR}
676
# Preseed d-i by repacking the initrd in certain situations
677
if [ "${DI_IMAGE_TYPE}" = "netboot" ] && [ -e config/binary_debian-installer/preseed.cfg ]
679
Repack_initrd "${DESTDIR}"/"${INITRD_DI}"
681
if [ -e "${DESTDIR}"/"${INITRD_GI}" ]
683
Repack_initrd "${DESTDIR}"/"${INITRD_GI}"
687
# Include content of config/binary_debian-installer-includes if exists and not empty
688
if [ -d config/binary_debian-installer-includes ] && [ -n "$(ls -A config/binary_debian-installer-includes)" ]
690
Repack_initrd "${DESTDIR}"/"${INITRD_DI}" config/binary_debian-installer-includes
692
if [ -e "${DESTDIR}"/"${INITRD_GI}" ]
694
Repack_initrd "${DESTDIR}"/"${INITRD_GI}" config/binary_debian-installer-includes
699
Save_cache cache/packages_binary
704
# Creating stage file
705
Create_stagefile .stage/binary_debian-installer