summaryrefslogtreecommitdiff
path: root/scripts/build/lb_binary_debian-installer
blob: f2c0bd7a09b72482a5e8267282c187e772c02d5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
#!/bin/sh

## live-build(7) - System Build Scripts
## Copyright (C) 2006-2011 Daniel Baumann <daniel@debian.org>
##
## live-build comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
## This is free software, and you are welcome to redistribute it
## under certain conditions; see COPYING for details.


set -e

# Including common functions
. "${LB_BASE:-/usr/share/live/build}"/scripts/build.sh

# Setting static variables
DESCRIPTION="$(Echo 'install debian-installer into binary')"
HELP=""
USAGE="${PROGRAM} [--force]"

Arguments "${@}"

# Reading configuration files
Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
Set_defaults

if [ "${LB_BINARY_IMAGES}" = "virtual-hdd" ]
then
	exit 0
fi

if [ "${_DEBUG}" = "true" ]
then
	WGET_OPTIONS="${WGET_OPTIONS} --verbose"
elif [ "${_QUIET}" = "true" ]
then
	WGET_OPTIONS="${WGET_OPTIONS} --quiet"
else
	WGET_OPTIONS="${WGET_OPTIONS} --no-verbose"
fi

# Check d-i configuration
case "${LB_DEBIAN_INSTALLER}" in
	true|cdrom|netinst|netboot|businesscard|live)
		;;

	false)
		exit 0
		;;

	*)
		Echo_error "debian-installer flavour %s not supported." "${LB_DEBIAN_INSTALLER}"
		exit 1
		;;
esac

Echo_message "Begin installing debian-installer..."

# Requiring stage file
Require_stagefile .stage/config .stage/bootstrap

# Checking stage file
Check_stagefile .stage/binary_debian-installer

# Checking lock file
Check_lockfile .lock

# Creating lock file
Create_lockfile .lock

# Checking depends
Check_package chroot/usr/bin/wget wget
Check_package chroot/usr/bin/apt-ftparchive apt-utils

# Restoring cache
Restore_cache cache/packages_binary

# Installing depends
Install_package

# Setting destination directory
case "${LB_BINARY_IMAGES}" in
	net)
		DESTDIR="tftpboot/debian-install/${LB_ARCHITECTURE}"
		;;

	usb*|tar)
		DESTDIR="binary/install"
		;;

	*)
		DESTDIR="binary/install"
		;;
esac

# Set d-i image type
case "${LB_DEBIAN_INSTALLER}" in
	businesscard|netboot|netinst)
		DI_IMAGE_TYPE="netboot"
		;;
	*)
		case "${LB_BINARY_IMAGES}" in
			net)
				DI_IMAGE_TYPE="netboot"
				;;

			*)
				DI_IMAGE_TYPE="cdrom"
				;;
		esac
		;;
esac

# Set architecture-specific variables
case "${LB_ARCHITECTURE}" in
	powerpc)
		case "${DI_IMAGE_TYPE}" in
			cdrom)
				DI_REMOTE_BASE="${LB_ARCHITECTURE}/cdrom"
			;;

			netboot)
				DI_REMOTE_BASE="${LB_ARCHITECTURE}/netboot"
				;;
		esac

		DI_REMOTE_KERNEL="vmlinux"
		DI_REMOTE_BASE_GTK="${DI_REMOTE_BASE}/gtk"
		;;

	sparc)
		DEFAULT_FLAVOUR="$(echo ${LB_LINUX_FLAVOURS} | awk '{ print $1 }')"
		DI_REMOTE_KERNEL="$(basename chroot/boot/vmlinuz-*${DEFAULT_FLAVOUR})"
		DI_REMOTE_BASE_GTK="none"

		DI_REMOTE_BASE="cdrom"
		;;
	*)
		case "${DI_IMAGE_TYPE}" in
			netboot)
				DI_REMOTE_BASE="netboot/debian-installer/${LB_ARCHITECTURE}"
				DI_REMOTE_BASE_GTK="netboot/gtk/debian-installer/${LB_ARCHITECTURE}"
				DI_REMOTE_KERNEL="linux"
				;;

			cdrom)
				DI_REMOTE_BASE="cdrom"
				DI_REMOTE_BASE_GTK="cdrom/gtk"
				DI_REMOTE_KERNEL="vmlinuz"
				;;
		esac
		;;
esac

Check_multiarchitecture

Install_file() {
	local FILE
	FILE="${1}"

	local TARGET
	TARGET="${2}"

	SOURCE="$(dpkg -f ${FILE} Source | awk '{ print $1 }')"

	if [ -z "${SOURCE}" ]
	then
		SOURCE="$(basename ${FILE} | awk -F_ '{ print $1 }')"
	fi

	case "${SOURCE}" in
		lib?*)
			LETTER="$(echo ${SOURCE} | sed 's|\(....\).*|\1|')"
			;;

		*)
			LETTER="$(echo ${SOURCE} | sed 's|\(.\).*|\1|')"
			;;
	esac

	# Install directory
	mkdir -p "${TARGET}"/"${LETTER}"/"${SOURCE}"

	# Move files
	cp "${FILE}" "${TARGET}"/"${LETTER}"/"${SOURCE}"
}

# Set absolute directory for caching; we require it when we call Download_file
# from a non-standard cwd.
_LB_CACHE_DIR="$(pwd)/cache/binary_debian-installer"

Download_file () {
	local _LB_TARGET
	_LB_TARGET="${1}"

	local _LB_URL
	_LB_URL="${2}"

	_LB_CACHE_FILE="${_LB_CACHE_DIR}/$(echo "${_LB_URL}" | sed 's|/|_|g')"

	if [ ! -f "${_LB_CACHE_FILE}" ]
	then
		mkdir -p ${_LB_CACHE_DIR}
		if ! wget ${WGET_OPTIONS} -O "${_LB_CACHE_FILE}" "${_LB_URL}"
		then
			rm -f "${_LB_CACHE_FILE}"

			Echo_error "Could not download file: %s" "${_LB_URL}"
			exit 1
		fi
	fi

	if [ "$(stat --printf %d "${_LB_CACHE_DIR}")" = "$(stat --printf %d ./)" ]
	then
		CP_OPTIONS="-l"
	fi

	cp -f ${CP_OPTIONS} -- "${_LB_CACHE_FILE}" "${_LB_TARGET}"
}

VMLINUZ_DI="vmlinuz"
INITRD_DI="initrd.gz"
DESTDIR_DI="${DESTDIR}"

VMLINUZ_GI="gtk/vmlinuz"
INITRD_GI="gtk/initrd.gz"
DESTDIR_GI="${DESTDIR}/gtk"

if [ "${LB_DEBIAN_INSTALLER_DISTRIBUTION}" = "daily" ]
then
	LB_DEBIAN_INSTALLER_DISTRIBUTION="sid"

	# Debian Installer daily builds
	URL="http://d-i.debian.org/daily-images/${LB_ARCHITECTURE}/daily/"
else
	URL="${LB_MIRROR_DEBIAN_INSTALLER}/dists/${LB_DEBIAN_INSTALLER_DISTRIBUTION}/main/installer-${LB_ARCHITECTURE}/current/images/"
fi

mkdir -p "${DESTDIR_DI}"

if [ "${LB_ARCHITECTURE}" = "sparc" ] && [ "${DI_IMAGE_TYPE}" = "netboot" ]
then
	# There are no prepared kernel/initrd pairs for sparc netboot so we
	# must unpack them from a mini.iso
	Download_file mini.iso ${URL}/mini.iso

	mkdir mini.tmp
	${LB_ROOT_COMMAND} mount -o loop -t iso9660 mini.iso mini.tmp

	cp mini.tmp/boot/vmlinuz-${DEFAULT_FLAVOUR} "${DESTDIR}"/"${VMLINUZ_DI}"
	cp mini.tmp/boot/initrd.gz "${DESTDIR}"/"${INITRD_DI}"

	${LB_ROOT_COMMAND} umount mini.tmp
	rm -rf mini.tmp mini.iso
else
	# Downloading debian-installer
	Download_file "${DESTDIR}"/"${VMLINUZ_DI}" ${URL}/${DI_REMOTE_BASE}/${DI_REMOTE_KERNEL}
	Download_file "${DESTDIR}"/"${INITRD_DI}" ${URL}/${DI_REMOTE_BASE}/initrd.gz

	# Downloading graphical-installer
	DOWNLOAD_GTK_INSTALLER=0
	if [ "${LB_DEBIAN_INSTALLER_GUI}" = "true" ]
	then
		case "${LB_ARCHITECTURE}" in
			amd64|i386)
				DOWNLOAD_GTK_INSTALLER=1
				;;

			powerpc)
				if [ "${LB_DEBIAN_INSTALLER}" = "netboot" ]
				then
					DOWNLOAD_GTK_INSTALLER=1
				fi
				;;
		esac
	fi

	if [ ${DOWNLOAD_GTK_INSTALLER} -eq 1 ]
	then
		mkdir -p "${DESTDIR_GI}"
		Download_file "${DESTDIR}"/"${VMLINUZ_GI}" ${URL}/${DI_REMOTE_BASE_GTK}/${DI_REMOTE_KERNEL}
		Download_file "${DESTDIR}"/"${INITRD_GI}" ${URL}/${DI_REMOTE_BASE_GTK}/initrd.gz
	fi
fi

# Only download additional packages if appropriate
if [ "${DI_IMAGE_TYPE}" != "netboot" ]
then
	# Downloading additional packages
	mkdir -p chroot/binary.deb/archives/partial
	mkdir -p binary/pool/main
	mv chroot/var/lib/dpkg/status chroot/var/lib/dpkg/status.tmp
	touch chroot/var/lib/dpkg/status

	case "${LB_ARCHITECTURE}" in
		amd64)
			#DI_REQ_PACKAGES="lilo grub grub2"
			DI_REQ_PACKAGES="lilo grub"

			case "${LB_MODE}" in
				ubuntu)
					DI_PACKAGES="${DI_REQ_PACKAGES} linux-generic"
					;;

				*)
					DI_PACKAGES="${DI_REQ_PACKAGES} linux-image-2.6-amd64"
					;;
			esac
			;;

		i386)
			#DI_REQ_PACKAGES="elilo lilo grub grub2"
			DI_REQ_PACKAGES="elilo lilo grub"

			case "${LB_MODE}" in
				ubuntu)
					DI_PACKAGES="${DI_REQ_PACKAGES} linux-generic"
					;;

				*)
					DI_PACKAGES="${DI_REQ_PACKAGES} linux-image-2.6-486 linux-image-2.6-686"
					;;
			esac
			;;

		sparc)
			DI_REQ_PACKAGES="silo"
			case "${LB_MODE}" in
				ubuntu)
					DI_PACKAGES="${DI_REQ_PACKAGES} linux-sparc64"
					;;

				*)
					DI_PACKAGES="${DI_REQ_PACKAGES} linux-image-2.6-sparc64 linux-image-2.6-sparc64-smp"
					;;
			esac
			;;

		powerpc)
			DI_REQ_PACKAGES="yaboot"
			case "${LB_MODE}" in
				ubuntu)
					DI_PACKAGES="${DI_REQ_PACKAGES} linux-image-powerpc linux-image-powerpc64-smp"
					;;

				*)
					DI_PACKAGES="${DI_REQ_PACKAGES} linux-image-2.6-powerpc linux-image-2.6-powerpc64 linux-image-2.6-powerpc-smp"
					;;
			esac
			;;
	esac

	DI_PACKAGES="${DI_PACKAGES} busybox cryptsetup lvm2"

	case "${LB_MODE}" in
		debian)
			case "${LB_DISTRIBUTION}" in
				lenny)
					DI_REQ_PACKAGES="${DI_REQ_PACKAGES} console-setup kbd"
					DI_PACKAGES="${DI_PACKAGES} console-setup kbd"
					;;

				*)
					DI_REQ_PACKAGES="${DI_REQ_PACKAGES} console-setup keyboard-configuration kbd"
					DI_PACKAGES="${DI_PACKAGES} console-setup keyboard-configuration kbd"
					;;
			esac
			;;
	esac

	# Set apt command prefix
	_LB_APT_COMMAND="apt-get ${APT_OPTIONS} -o Dir::Cache=/binary.deb -o APT::Install-Recommends=false --download-only"

	if [ "${LB_DEBIAN_INSTALLER}" = "live" ]
	then
		# We don't want to duplicate .debs of packages in binary/pool that are already
		# installed to target/ via live-installer.
		#
		# However, we need to force various packages' inclusion in binary/pool/main as
		# d-i does not support (for example) re-installing grub from target/ - the grub
		# .debs must actually exist.

		# Modify dpkg status to show the required packages are not installed.
		cp chroot/var/lib/dpkg/status.tmp chroot/var/lib/dpkg/status
		for PACKAGE in ${DI_REQ_PACKAGES}
		do
			awk -v f=0 '
				f == 1 { print "Status: purge ok not-installed"; f=0; next }
				/Package: '"${PACKAGE}"'/ { f=1; }
				{ print }
				' chroot/var/lib/dpkg/status > chroot/var/lib/dpkg/status.awk
			mv chroot/var/lib/dpkg/status.awk chroot/var/lib/dpkg/status
		done

		# Download .deb's that we just marked as "purged" which caused broken dependencies
		Chroot chroot ${_LB_APT_COMMAND} -f dist-upgrade

		# Revert dpkg status file
		mv chroot/var/lib/dpkg/status.tmp chroot/var/lib/dpkg/status

		# Download .debs of the required packages
		Chroot chroot ${_LB_APT_COMMAND} install ${DI_REQ_PACKAGES}
		Chroot chroot ${_LB_APT_COMMAND} install ${DI_PACKAGES}
	else
		# Download .debs of the required packages
		Chroot chroot ${_LB_APT_COMMAND} install ${DI_PACKAGES}

		# Revert dpkg status file
		mv chroot/var/lib/dpkg/status.tmp chroot/var/lib/dpkg/status
	fi

	mv chroot/binary.deb ./

	if Find_files binary.deb/archives/*.deb
	then
		for FILE in binary.deb/archives/*.deb
		do
			Install_file "${FILE}" "binary/pool/main"
		done
	fi

	if [ "${LB_DEBIAN_INSTALLER}" != "live" ]
	then
		# Including base debian packages
		if ls cache/packages_bootstrap/*.deb > /dev/null 2>&1
		then
			for FILE in cache/packages_bootstrap/*.deb
			do
				Install_file "${FILE}" "binary/pool/main"
			done
		else
			Echo_error "Could not find packages in cache/packages_bootstrap."
			Echo_error "You selected values of LB_CACHE, LB_CACHE_PACKAGES, LB_CACHE_STAGES and LB_DEBIAN_INSTALLER which will result in 'bootstrap' packages not being cached - these are required when integrating the Debian Installer."
			exit 1
		fi
	fi

	# Including local debs
	if Find_files config/binary_local-debs/*_"${LB_ARCHITECTURE}".deb
	then
		for FILE in config/binary_local-debs/*_"${LB_ARCHITECTURE}".deb
		do
			Install_file "${FILE}" "binary/pool/main"
		done
	fi

	if Find_files config/binary_local-debs/*_all.deb
	then
		for FILE in config/binary_local-debs/*_all.deb
		do
			Install_file "${FILE}" "binary/pool/main"
		done
	fi

	# Generating deb indices
	mkdir -p binary/dists/${LB_DEBIAN_INSTALLER_DISTRIBUTION}/main/binary-${LB_ARCHITECTURE}

	mv binary chroot/root
	echo "cd /root/binary && apt-ftparchive packages pool/main > dists/${LB_DEBIAN_INSTALLER_DISTRIBUTION}/main/binary-${LB_ARCHITECTURE}/Packages" > chroot/binary.sh
	Chroot chroot "sh binary.sh"
	rm -f chroot/binary.sh
	mv chroot/root/binary ./

	gzip -9 -c binary/dists/${LB_DEBIAN_INSTALLER_DISTRIBUTION}/main/binary-${LB_ARCHITECTURE}/Packages > binary/dists/${LB_DEBIAN_INSTALLER_DISTRIBUTION}/main/binary-${LB_ARCHITECTURE}/Packages.gz

	# Fetching release
	Download_file binary/dists/${LB_DEBIAN_INSTALLER_DISTRIBUTION}/main/binary-${LB_ARCHITECTURE}/Release "${LB_MIRROR_CHROOT}"/dists/"${LB_DEBIAN_INSTALLER_DISTRIBUTION}"/main/binary-"${LB_ARCHITECTURE}"/Release

	mkdir binary.udeb
	cd binary.udeb

	# Downloading udeb indices
	Download_file Packages.gz "${LB_MIRROR_CHROOT}"/dists/"${LB_DEBIAN_INSTALLER_DISTRIBUTION}"/main/debian-installer/binary-"${LB_ARCHITECTURE}"/Packages.gz
	gunzip -c Packages.gz > Packages

	# Sorting udebs
	UDEBS="$(awk '/Filename: / { print $2 }' Packages)"

	# Downloading udebs
	for UDEB in ${UDEBS}
	do
		if [ -f ../cache/packages_debian-installer.udeb/"$(basename ${UDEB})" ]
		then
			# Copying cached udebs
			cp ../cache/packages_debian-installer.udeb/"$(basename ${UDEB})" ./
		else
			# Downloading udebs
			wget ${WGET_OPTIONS} "${LB_MIRROR_CHROOT}"/${UDEB}
		fi
	done

	# Caching udebs
	rm -rf ../cache/packages_debian-installer.udeb
	mkdir -p ../cache/packages_debian-installer.udeb
	cp *.udeb ../cache/packages_debian-installer.udeb

	# Including local udebs
	if Find_files ../config/binary_local-udebs/*_"${LB_ARCHITECTURE}".udeb
	then
		for FILE in ../config/binary_local-udebs/*_"${LB_ARCHITECTURE}".udeb
		do
			Install_file "${FILE}" "pool/main"

			# Prefer local udebs over downloaded udebs
			rm -f "$(basename ${FILE} | awk -F_ '{ print $1 }')"_*.udeb
		done
	fi

	if Find_files ../config/binary_local-udebs/*_all.udeb
	then
		for FILE in ../config/binary_local-udebs/*_all.udeb
		do
			Install_file "${FILE}" "pool/main"

			# Prefer local udebs over downloaded udebs
			rm -f "$(basename ${FILE} | awk -F_ '{ print $1 }')"_*.udeb
		done
	fi

	# Excluding udebs
	grep -v "^#" "${LB_BASE}"/data/debian-cd/"${LB_DEBIAN_INSTALLER_DISTRIBUTION}"/udeb_exclude > exclude || true
	grep -v "^#" "${LB_BASE}"/data/debian-cd/"${LB_DEBIAN_INSTALLER_DISTRIBUTION}"/exclude-udebs >> exclude || true
	grep -v "^#" "${LB_BASE}"/data/debian-cd/"${LB_DEBIAN_INSTALLER_DISTRIBUTION}"/exclude-udebs-${LB_ARCHITECTURE} >> exclude || true

	# Local exclude file
	if [ -e ../config/binary_debian-installer/udeb_exclude ]
	then
		cat ../config/binary_debian-installer/udeb_exclude >> exclude
	fi

	# Excluding udebs from excludes because we want them to be in the image on purpose
	sed -i -e 's|di-utils-exit-installer||' exclude # used for live-installer-launcher

	while read EXCLUDE
	do
		if [ "${LB_DEBIAN_INSTALLER}" = "live" ] && [ "${EXCLUDE}" = "live-installer" ]
		then
			continue
		fi

		rm -f ${EXCLUDE}_*.udeb
	done < exclude

	# Enable live-installer
	if [ "${LB_DEBIAN_INSTALLER}" = "live" ]
	then
		# Remove local udebs
		rm -f pool/main/b/base-installer/bootstrap-base_*.udeb

		# Remove d-i udebs
		rm -f bootstrap-base_*.udeb
	fi

	# Moving udebs
	for UDEB in ${UDEBS}
	do
		if [ -f "$(basename ${UDEB})" ]
		then
			mkdir -p $(dirname ${UDEB})
			mv "$(basename ${UDEB})" "$(dirname ${UDEB})"
		fi
	done

	# Creating udeb indices
	mkdir -p dists/"${LB_DEBIAN_INSTALLER_DISTRIBUTION}"/main/debian-installer/binary-"${LB_ARCHITECTURE}"
	cd "${OLDPWD}"

	mv binary.udeb chroot/root
	echo "cd /root/binary.udeb && apt-ftparchive packages pool/main > dists/${LB_DEBIAN_INSTALLER_DISTRIBUTION}/main/debian-installer/binary-${LB_ARCHITECTURE}/Packages" > chroot/binary.sh
	Chroot chroot "sh binary.sh"
	rm -f chroot/binary.sh
	mv chroot/root/binary.udeb ./

	cd binary.udeb
	gzip -9 -c dists/${LB_DEBIAN_INSTALLER_DISTRIBUTION}/main/debian-installer/binary-${LB_ARCHITECTURE}/Packages > dists/${LB_DEBIAN_INSTALLER_DISTRIBUTION}/main/debian-installer/binary-${LB_ARCHITECTURE}/Packages.gz

	rm -f Packages* exclude
	find . | cpio -dmpu "${OLDPWD}"/binary
	cd "${OLDPWD}"

	rm -rf binary.udeb
	rm -rf binary.deb

	# Generating release file
	mv binary chroot/root

	eval _VERSION="$`echo RELEASE_${LB_DISTRIBUTION}`"

	case "${LB_DISTRIBUTION}" in
		sid)
			_SUITE="unstable"
			;;

		*)
			_SUITE="${LB_DISTRIBUTION}"
			;;
	esac

cat > chroot/binary.sh << EOF
cd /root/binary && apt-ftparchive \
	-o APT::FTPArchive::Release::Origin="Debian" \
	-o APT::FTPArchive::Release::Label="Debian" \
	-o APT::FTPArchive::Release::Suite="${_SUITE}" \
	-o APT::FTPArchive::Release::Version="${_VERSION}" \
	-o APT::FTPArchive::Release::Codename="${LB_DISTRIBUTION}" \
	-o APT::FTPArchive::Release::Date="$(date -R)" \
	-o APT::FTPArchive::Release::Architectures="${LB_ARCHITECTURE}" \
	-o APT::FTPArchive::Release::Components="main" \
	-o APT::FTPArchive::Release::Description="Last updated: $(date -R)" \
	release dists/${LB_DEBIAN_INSTALLER_DISTRIBUTION} > dists/${LB_DEBIAN_INSTALLER_DISTRIBUTION}/Release
EOF

	Chroot chroot "sh binary.sh"
	rm -f chroot/binary.sh
	mv chroot/root/binary ./

	DISTRIBUTIONS="frozen stable testing unstable"

	if [ "${LB_DEBIAN_INSTALLER_DISTRIBUTION}" != "${LB_DISTRIBUTION}" ]
	then
		DISTRIBUTIONS="${DISTRIBUTIONS} ${LB_DISTRIBUTION}"
	fi

	case "${LB_BINARY_IMAGES}" in
		usb-hdd)
			case "${LB_BINARY_FILESYSTEM}" in
				fat*)
					# Creating dist directories
					for DISTRIBUTION in ${DISTRIBUTIONS}
					do
						cp -a binary/dists/${LB_DEBIAN_INSTALLER_DISTRIBUTION} binary/dists/${DISTRIBUTION}
					done
					;;
			esac
			;;

		*)
			# Creating dist symlinks
			for DISTRIBUTION in ${DISTRIBUTIONS}
			do
				ln -s ${LB_DEBIAN_INSTALLER_DISTRIBUTION} binary/dists/${DISTRIBUTION}
			done

			ln -s . binary/debian
			;;
	esac

	# Including preseeding files
	if Find_files config/binary_debian-installer/*.cfg
	then
		cp config/binary_debian-installer/*.cfg binary/install
	fi
fi

Repack_initrd()
{
	local TARGET_INITRD
	local INCLUDE_PATH
	TARGET_INITRD="${1}"
	INCLUDE_PATH="${2}"
	REPACK_TMPDIR="unpacked-initrd"

	if [ -d "${INCLUDE_PATH}" ]
	then
		INCLUDE_PATH=$(readlink -f ${INCLUDE_PATH})
	fi

	# cpio does not have a "extract to directory", so we must change directory
	mkdir -p ${REPACK_TMPDIR}
	cd ${REPACK_TMPDIR}

	gzip -d < ../${TARGET_INITRD} | cpio -i --make-directories --no-absolute-filenames
	if [ ! -d "${INCLUDE_PATH}" ]
	then
		# Invoked the old way, just copy the preseeds
		cp ../config/binary_debian-installer/*.cfg .
	else
		# New way, include target directory content in the initrd
		REPACK_TMPDIR_ABS="${PWD}"
		cd "${INCLUDE_PATH}"
		find -print0 | cpio -pumd0 --no-preserve-owner "${REPACK_TMPDIR_ABS}/"
		cd "${OLDPWD}"
	fi
	find -print0 | cpio -H newc -o0 | gzip -9 > ../${TARGET_INITRD}

	cd ..
	rm -rf ${REPACK_TMPDIR}
}

# Preseed d-i by repacking the initrd in certain situations
if [ "${DI_IMAGE_TYPE}" = "netboot" ] && [ -e config/binary_debian-installer/preseed.cfg ]
then
	Repack_initrd "${DESTDIR}"/"${INITRD_DI}"

	if [ -e "${DESTDIR}"/"${INITRD_GI}" ]
	then
		Repack_initrd "${DESTDIR}"/"${INITRD_GI}"
	fi
fi

# Include content of config/binary_debian-installer-includes if exists and not empty
if [ -d config/binary_debian-installer-includes ] && [ -n "$(ls -A config/binary_debian-installer-includes)" ]
then
	Repack_initrd "${DESTDIR}"/"${INITRD_DI}" config/binary_debian-installer-includes

	if [ -e "${DESTDIR}"/"${INITRD_GI}" ]
	then
		Repack_initrd "${DESTDIR}"/"${INITRD_GI}" config/binary_debian-installer-includes
	fi
fi

# Saving cache
Save_cache cache/packages_binary

# Removing depends
Remove_package

# Creating stage file
Create_stagefile .stage/binary_debian-installer