installer_debian-installer 23.8 KB
Newer Older
1
2
#!/bin/sh

3
## live-build(7) - System Build Scripts
4
## Copyright (C) 2006-2013 Daniel Baumann <mail@daniel-baumann.ch>
5
##
6
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
7
8
9
## This is free software, and you are welcome to redistribute it
## under certain conditions; see COPYING for details.

10
11
12

set -e

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 'install debian-installer into binary')"
18
19
20
21
22
23
HELP=""
USAGE="${PROGRAM} [--force]"

Arguments "${@}"

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

27
if [ "${_DEBUG}" = "true" ]
28
29
then
	WGET_OPTIONS="${WGET_OPTIONS} --verbose"
30
elif [ "${_QUIET}" = "true" ]
31
32
then
	WGET_OPTIONS="${WGET_OPTIONS} --quiet"
33
34
else
	WGET_OPTIONS="${WGET_OPTIONS} --no-verbose"
35
36
fi

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

42
	false)
43
44
45
		exit 0
		;;

46
	*)
47
		Echo_error "debian-installer flavour %s not supported." "${LB_DEBIAN_INSTALLER}"
48
49
50
		exit 1
		;;
esac
51

52
Echo_message "Begin installing debian-installer..."
53
54

# Requiring stage file
55
Require_stagefile .build/config .build/bootstrap
56
57

# Checking stage file
58
Check_stagefile .build/installer_debian-installer
59
60
61
62
63
64
65

# Checking lock file
Check_lockfile .lock

# Creating lock file
Create_lockfile .lock

66
67
# Checking depends
Check_package chroot/usr/bin/wget wget
68
Check_package chroot/usr/bin/apt-ftparchive apt-utils
69
70

# Restoring cache
71
Restore_cache cache/packages.binary
72
73
74
75

# Installing depends
Install_package

76
# Setting destination directory
77
case "${LIVE_IMAGE_TYPE}" in
78
	netboot)
79
		DESTDIR="tftpboot/debian-install/${LIVE_IMAGE_ARCHITECTURE}"
80
81
		;;

82
	hdd*|tar)
83
		DESTDIR="binary/install"
84
		;;
85
86
87
88

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

91
# Set d-i image type
92
case "${LB_DEBIAN_INSTALLER}" in
93
94
	businesscard|netboot|netinst)
		DI_IMAGE_TYPE="netboot"
95
96
		;;
	*)
97
		case "${LIVE_IMAGE_TYPE}" in
98
			netboot)
99
				DI_IMAGE_TYPE="netboot"
100
				;;
101

102
			*)
103
				DI_IMAGE_TYPE="cdrom"
104
105
106
107
108
				;;
		esac
		;;
esac

109
# Set architecture-specific variables
110
case "${LIVE_IMAGE_ARCHITECTURE}" in
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
	armel)
		DEFAULT_FLAVOUR="$(echo ${LH_LINUX_FLAVOURS} | awk '{ print $1 }')"
		case "${DI_IMAGE_TYPE}" in
			cdrom)
				DI_REMOTE_BASE="${DEFAULT_FLAVOUR}/cdrom"
				;;

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

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

127
128
129
	powerpc)
		case "${DI_IMAGE_TYPE}" in
			cdrom)
130
				DI_REMOTE_BASE="${LIVE_IMAGE_ARCHITECTURE}/cdrom"
131
132
133
			;;

			netboot)
134
				DI_REMOTE_BASE="${LIVE_IMAGE_ARCHITECTURE}/netboot"
135
136
137
138
139
				;;
		esac

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

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

147
		DI_REMOTE_BASE="cdrom"
148
		;;
149
150
151
	*)
		case "${DI_IMAGE_TYPE}" in
			netboot)
152
153
				DI_REMOTE_BASE="netboot/debian-installer/${LIVE_IMAGE_ARCHITECTURE}"
				DI_REMOTE_BASE_GTK="netboot/gtk/debian-installer/${LIVE_IMAGE_ARCHITECTURE}"
154
155
156
157
158
159
160
161
162
163
				DI_REMOTE_KERNEL="linux"
				;;

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

166
Check_multiarchitectures
167

168
Install_file() {
169
170
171
	local FILE
	FILE="${1}"

172
173
174
175
176
177
178
179
180
181
	local ARCHIVE_AREA
	ARCHIVE_AREA="$(dpkg -I ${FILE} | awk '/^.*Section: / { print $2 }')"

	if echo "${ARCHIVE_AREA}" | grep -qs '/'
	then
		ARCHIVE_AREA="$(echo ${ARCHIVE_AREA} | awk -F/ '{ print $1 }')"
	else
		ARCHIVE_AREA="main"
	fi

182
	local TARGET
183
	TARGET="${2}/${ARCHIVE_AREA}"
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

	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}"
}

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

Download_file () {
214
215
	local _LB_TARGET
	_LB_TARGET="${1}"
216

217
218
	local _LB_URL
	_LB_URL="${2}"
219

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

222
	if [ ! -f "${_LB_CACHE_FILE}" ]
223
	then
224
225
		mkdir -p ${_LB_CACHE_DIR}
		if ! wget ${WGET_OPTIONS} -O "${_LB_CACHE_FILE}" "${_LB_URL}"
226
		then
227
			rm -f "${_LB_CACHE_FILE}"
228

229
			Echo_error "Could not download file: %s" "${_LB_URL}"
230
231
232
233
			exit 1
		fi
	fi

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

239
	cp -f ${CP_OPTIONS} -- "${_LB_CACHE_FILE}" "${_LB_TARGET}"
240
241
}

242
243
244
245
246
247
248
249
VMLINUZ_DI="vmlinuz"
INITRD_DI="initrd.gz"
DESTDIR_DI="${DESTDIR}"

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

250
251
252
253
254
255
case "${LB_DERIVATIVE}" in
	false)
		if [ "${LB_DEBIAN_INSTALLER_DISTRIBUTION}" = "daily" ]
		then
			# FIXME: variable name should be decupled from derivatves
			LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION="sid"
256

257
			# Debian Installer daily builds
258
			URL="http://d-i.debian.org/daily-images/${LIVE_IMAGE_ARCHITECTURE}/daily/"
259
		else
260
			URL="${LB_MIRROR_DEBIAN_INSTALLER}/dists/${LB_DEBIAN_INSTALLER_DISTRIBUTION}/main/installer-${LIVE_IMAGE_ARCHITECTURE}/current/images/"
261
262
263
264
265
266
267
268
269
		fi
		;;

	true)
		if [ "${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}" = "daily" ]
		then
			LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION="sid"

			# Debian Installer daily builds
270
			URL="http://d-i.debian.org/daily-images/${LIVE_IMAGE_ARCHITECTURE}/daily/"
271
		else
272
			URL="${LB_PARENT_MIRROR_DEBIAN_INSTALLER}/dists/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}/main/installer-${LIVE_IMAGE_ARCHITECTURE}/current/images/"
273
		fi
274

275
		if [ "${LB_MODE}" = "progress-linux" ]
276
277
		then
			# FIXME: normal derivatives probably don't rebuild d-i,
278
			# but progress-linux does.
279
			URL="${LB_MIRROR_DEBIAN_INSTALLER}/dists/${LB_DEBIAN_INSTALLER_DISTRIBUTION}/main/installer-${LIVE_IMAGE_ARCHITECTURE}/current/images/"
280
		fi
281
282
		;;
esac
283

284
285
mkdir -p "${DESTDIR_DI}"

286
if [ "${LIVE_IMAGE_ARCHITECTURE}" = "sparc" ] && [ "${DI_IMAGE_TYPE}" = "netboot" ]
287
then
288
289
	# There are no prepared kernel/initrd pairs for sparc netboot so we
	# must unpack them from a mini.iso
290
	Download_file mini.iso ${URL}/mini.iso
291
292

	mkdir mini.tmp
293
	mount -o loop -t iso9660 mini.iso mini.tmp
294
295
296
297

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

298
	umount mini.tmp
299
300
301
	rm -rf mini.tmp mini.iso
else
	# Downloading debian-installer
302
303
	Download_file "${DESTDIR}"/"${VMLINUZ_DI}" ${URL}/${DI_REMOTE_BASE}/${DI_REMOTE_KERNEL}
	Download_file "${DESTDIR}"/"${INITRD_DI}" ${URL}/${DI_REMOTE_BASE}/initrd.gz
304
305
306

	# Downloading graphical-installer
	DOWNLOAD_GTK_INSTALLER=0
307
	if [ "${LB_DEBIAN_INSTALLER_GUI}" = "true" ]
308
	then
309
		case "${LIVE_IMAGE_ARCHITECTURE}" in
310
			amd64|i386)
311
				DOWNLOAD_GTK_INSTALLER=1
312
313
314
				;;

			powerpc)
315
				if [ "${LB_DEBIAN_INSTALLER}" = "netboot" ]
316
317
318
319
320
321
				then
					DOWNLOAD_GTK_INSTALLER=1
				fi
				;;
		esac
	fi
322
323
324
325

	if [ ${DOWNLOAD_GTK_INSTALLER} -eq 1 ]
	then
		mkdir -p "${DESTDIR_GI}"
326
327
		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
328
	fi
329
330
fi

331
# Only download additional packages if appropriate
332
if [ "${DI_IMAGE_TYPE}" != "netboot" ]
333
then
334
335
	# Downloading additional packages
	mkdir -p chroot/binary.deb/archives/partial
336

337
338
	mv chroot/var/lib/dpkg/status chroot/var/lib/dpkg/status.tmp
	touch chroot/var/lib/dpkg/status
339

340
	case "${LIVE_IMAGE_ARCHITECTURE}" in
341
		amd64)
342
			DI_REQ_PACKAGES="lilo grub-pc"
343

344
			case "${LB_MODE}" in
345
				ubuntu)
346
					DI_PACKAGES="${DI_REQ_PACKAGES} linux-generic"
347
348
349
					;;

				*)
350
					DI_PACKAGES="${DI_REQ_PACKAGES} linux-image-amd64"
351
352
					;;
			esac
353
			;;
354

355
		i386)
356
			DI_REQ_PACKAGES="elilo lilo grub-pc"
357

358
			case "${LB_MODE}" in
359
				ubuntu)
360
361
362
363
					case "${LB_DISTRIBUTION}" in
						precise)
							DI_PACKAGES="${DI_REQ_PACKAGES} linux-generic-pae"
							;;
364

365
366
367
368
						*)
							DI_PACKAGES="${DI_REQ_PACKAGES} linux-generic"
							;;
					esac
369
370
371
					;;

				*)
372
					DI_PACKAGES="${DI_REQ_PACKAGES} linux-image-486 linux-image-686-pae"
373
374
					;;
			esac
375
			;;
376

377
		sparc)
378
			DI_REQ_PACKAGES="silo"
379
			case "${LB_MODE}" in
380
				ubuntu)
381
382
383
384
					DI_PACKAGES="${DI_REQ_PACKAGES} linux-sparc64"
					;;

				*)
385
					DI_PACKAGES="${DI_REQ_PACKAGES} linux-image-sparc64 linux-image-sparc64-smp"
386
387
					;;
			esac
388
389
			;;

390
		powerpc)
391
			DI_REQ_PACKAGES="yaboot"
392
			case "${LB_MODE}" in
393
				ubuntu)
394
					DI_PACKAGES="${DI_REQ_PACKAGES} linux-image-powerpc-smp linux-image-powerpc64-smp linux-image-powerpc-e500 linux-image-powerpc-e500mc"
395
396
397
					;;

				*)
398
					DI_PACKAGES="${DI_REQ_PACKAGES} linux-image-powerpc linux-image-powerpc64 linux-image-powerpc-smp"
399
400
					;;
			esac
401
402
403
			;;
	esac

404
	DI_PACKAGES="${DI_PACKAGES} busybox cryptsetup mdadm lvm2 xfsprogs jfsutils"
405

406
407
	case "${LB_MODE}" in
		debian)
408
409
			DI_REQ_PACKAGES="${DI_REQ_PACKAGES} console-setup keyboard-configuration kbd"
			DI_PACKAGES="${DI_PACKAGES} console-setup keyboard-configuration kbd"
410
411
			;;
	esac
412
413
414
415
416
417
	# Include firmware packages
	if [ "${LB_FIRMWARE_BINARY}" = "true" ]
	then
		# Assumption: firmware packages install files into /lib/firmware

		# Get all firmware packages names
418
419
420
		mkdir -p cache/contents.binary

		FIRMWARE_PACKAGES=""
421

422
		_CONTENTS="$(for _PARENT_ARCHIVE_AREA in ${LIVE_IMAGE_PARENT_ARCHIVE_AREAS}; do echo ${LB_PARENT_MIRROR_CHROOT}/dists/${LB_PARENT_DISTRIBUTION}/${_PARENT_ARCHIVE_AREA}/Contents-${LIVE_IMAGE_ARCHITECTURE}.gz; done)"
423

424
		rm -f cache/contents.chroot/contents.${LB_PARENT_DISTRIBUTION}.${LIVE_IMAGE_ARCHITECTURE}
425

426
427
		for _CONTENT in ${_CONTENTS}
		do
428
			wget ${WGET_OPTIONS} ${_CONTENT} -O - | gunzip -c >> cache/contents.chroot/contents.${LB_PARENT_DISTRIBUTION}.${LIVE_IMAGE_ARCHITECTURE}
429

430
			FIRMWARE_PACKAGES="${FIRMWARE_PACKAGES} $(awk '/^lib\/firmware/ { print $2 }' cache/contents.chroot/contents.${LB_PARENT_DISTRIBUTION}.${LIVE_IMAGE_ARCHITECTURE} | sort -u)"
431
		done
432

433
		if echo ${LIVE_IMAGE_PARENT_ARCHIVE_AREAS} | grep -qs "non-free"
434
435
436
437
438
439
		then
			# FIXME: should check that we're building on debian through e.g. a 'derivative-is-based-on' variable or somesuch.
			# Manually add firmware-linux/non-free meta package
			FIRMWARE_PACKAGES="${FIRMWARE_PACKAGES} firmware-linux"
		fi

440
		if [ "${LB_DERIVATIVE}" = "true" ]
441
		then
442
			# FIXME: account for the fact that PARENT_DISTRIBUTION and DISTRIBUTION might be the same (to not have overlapping cache files for contents).
443

444
			_CONTENTS="$(for _ARCHIVE_AREA in ${LIVE_IMAGE_ARCHIVE_AREAS}; do echo ${LB_MIRROR_CHROOT}/dists/${LB_DISTRIBUTION}/${_ARCHIVE_AREA}/Contents-${LIVE_IMAGE_ARCHITECTURE}.gz; done)"
445

446
			rm -f cache/contents.chroot/contents.${LB_DISTRIBUTION}.${LIVE_IMAGE_ARCHITECTURE}
447
448

			for _CONTENT in ${_CONTENTS}
449
			do
450
				wget ${WGET_OPTIONS} ${_CONTENT} -O - | gunzip -c >> cache/contents.chroot/contents.${LB_DISTRIBUTION}.${LIVE_IMAGE_ARCHITECTURE}
451

452
				FIRMWARE_PACKAGES="${FIRMWARE_PACKAGES} $(awk '/^lib\/firmware/ { print $2 }' cache/contents.chroot/contents.${LB_DISTRIBUTION}.${LIVE_IMAGE_ARCHITECTURE} | sort -u)"
453
			done
454
455
456
457
458
459
460
461
462
		fi

		# Drop section and keep package names only
		for _PACKAGE in ${FIRMWARE_PACKAGES}
		do
			DI_FIRMWARE_PACKAGES="${DI_FIRMWARE_PACKAGES} $(echo ${_PACKAGE} | awk -F/ '{ print $NF }')"
		done
	fi

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

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

475
476
		# Download .debs of the required packages
		Chroot chroot ${_LB_APT_COMMAND} install ${DI_PACKAGES} ${DI_FIRMWARE_PACKAGES} ${DI_REQ_PACKAGES}
477
478
479

		# Drop the packages already installed that d-i doesn't explicitely need
		_REMAINING_PACKAGES="$(echo ${DI_FIRMWARE_PACKAGES} ${DI_REQ_PACKAGES} | sed -e 's# #|#g')"
480
		_REMAINING_PACKAGES="$(sed -n -e 's|Package: ||p' chroot/var/lib/dpkg/status.tmp | grep -E -v \"^${_REMAINING_PACKAGES}$\")"
481
482
483
484
485

		for _PACKAGE in ${_REMAINING_PACKAGES}
		do
			rm -f "chroot/binary.deb/archives/${_PACKAGE}_*.deb"
		done
486
487
	else
		# Download .debs of the required packages
488
		Chroot chroot ${_LB_APT_COMMAND} install ${DI_PACKAGES} ${DI_FIRMWARE_PACKAGES}
489
	fi
490

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

494
495
	mv chroot/binary.deb ./

496
	for _ARCHIVE_AREA in $(echo ${LIVE_IMAGE_PARENT_ARCHIVE_AREAS} ${LIVE_IMAGE_ARCHIVE_AREAS})
497
498
499
500
	do
		mkdir -p binary/pool/${_ARCHIVE_AREA}
	done

501
	if Find_files binary.deb/archives/*.deb
502
	then
503
		for FILE in binary.deb/archives/*.deb
504
		do
505
506
507
508
			Install_file "${FILE}" "binary/pool"
		done
	fi

509
	if [ "${LB_DEBIAN_INSTALLER}" != "live" ]
510
511
	then
		# Including base debian packages
512
		if ls cache/packages.bootstrap/*.deb > /dev/null 2>&1
513
		then
514
			for FILE in cache/packages.bootstrap/*.deb
515
			do
516
				Install_file "${FILE}" "binary/pool"
517
518
			done
		else
519
			Echo_error "Could not find packages in cache/packages.bootstrap."
520
			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."
521
522
			exit 1
		fi
523
	fi
524

525
	# Including local debs
526
	if Find_files config/packages.binary/*_"${LIVE_IMAGE_ARCHITECTURE}".deb || Find_files config/packages/*_"${LIVE_IMAGE_ARCHITECTURE}".deb
527
	then
528
		for FILE in config/packages.binary/*_"${LIVE_IMAGE_ARCHITECTURE}".deb config/packages/*_"${LIVE_IMAGE_ARCHITECTURE}".deb
529
		do
530
531
			if [ -e "${FILE}" ]
			then
532
				Install_file "${FILE}" "binary/pool"
533
			fi
534
535
		done
	fi
536

537
	if Find_files config/packages.binary/*_all.deb || Find_files config/packages/*_all.deb
538
	then
539
		for FILE in config/packages.binary/*_all.deb config/packages/*_all.deb
540
		do
541
542
			if [ -e "${FILE}" ]
			then
543
				Install_file "${FILE}" "binary/pool"
544
			fi
545
546
		done
	fi
547

548
	# Generating deb indices
549
550
	for _ARCHIVE_AREA in $(cd binary/pool && ls)
	do
551
		mkdir -p binary/dists/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}/${_ARCHIVE_AREA}/binary-${LIVE_IMAGE_ARCHITECTURE}
552

553
		mv binary chroot/root
554
		echo "cd /root/binary && apt-ftparchive packages pool/${_ARCHIVE_AREA} > dists/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}/${_ARCHIVE_AREA}/binary-${LIVE_IMAGE_ARCHITECTURE}/Packages" > chroot/binary.sh
555
556
557
		Chroot chroot "sh binary.sh"
		rm -f chroot/binary.sh
		mv chroot/root/binary ./
558

559
		gzip -9 -c binary/dists/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}/${_ARCHIVE_AREA}/binary-${LIVE_IMAGE_ARCHITECTURE}/Packages > binary/dists/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}/${_ARCHIVE_AREA}/binary-${LIVE_IMAGE_ARCHITECTURE}/Packages.gz
560

561
		# Fetching release
562
		Download_file binary/dists/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}/${_ARCHIVE_AREA}/binary-${LIVE_IMAGE_ARCHITECTURE}/Release "${LB_PARENT_MIRROR_CHROOT}"/dists/"${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}"/${_ARCHIVE_AREA}/binary-"${LIVE_IMAGE_ARCHITECTURE}"/Release
563
	done
564

565
566
567
568
569
570
571
572
573
574
	# Symlink firmware packages to /firmware
	if [ -n "${DI_FIRMWARE_PACKAGES}" ]
	then
		mkdir -p binary/firmware
		cd binary/firmware

		for _PACKAGE in ${DI_FIRMWARE_PACKAGES}
		do
			for _FILE in $(find ../pool -name "${_PACKAGE}_*.deb")
			do
575
				ln -sf ${_FILE} ./
576
577
578
579
580
581
			done
		done

		cd "${OLDPWD}"
	fi

582
	# Udeb handling
583
584
	mkdir binary.udeb
	cd binary.udeb
585

586
	# Downloading udeb indices
587
	Download_file Packages.gz "${LB_PARENT_MIRROR_CHROOT}"/dists/"${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}"/main/debian-installer/binary-"${LIVE_IMAGE_ARCHITECTURE}"/Packages.gz
588
	gunzip -c Packages.gz > Packages
589

590
591
	if [ "${LB_DERIVATIVE}" = "true" ]
	then
592
		Download_file Packages.derivative.gz "${LB_MIRROR_CHROOT}"/dists/"${LB_DEBIAN_INSTALLER_DISTRIBUTION}"/main/debian-installer/binary-"${LIVE_IMAGE_ARCHITECTURE}"/Packages.gz
593
594
595
		gunzip -c Packages.derivative.gz > Packages.derivative
	fi

596
	# Sorting udebs
597
598
599
600
601
602
	if [ "${LB_DERIVATIVE}" = true ]
	then
		UDEBS="$(awk '/Filename: / { print $2 }' Packages.derivative)"
	fi

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

604
605
606
607
608
609
610
611
	# Downloading udebs packages
	Echo_message "Downloading udebs..."

	if [ "${LB_DERIVATIVE}" = "true" ]
	then
		Echo_message "Building in derivative mode in debian+ layout.. a lot of 404 errors are ok here."
	fi

612
613
	for UDEB in ${UDEBS}
	do
614
		if [ -f ../cache/packages.installer_debian-installer.udeb/"$(basename ${UDEB})" ]
615
616
		then
			# Copying cached udebs
617
			cp ../cache/packages.installer_debian-installer.udeb/"$(basename ${UDEB})" ./
618
619
		else
			# Downloading udebs
620
621
622
623
			if ! ls "$(basename ${UDEB} | awk -F_ '{ print $1 }')"_* > /dev/null 2>&1
			then
				wget ${WGET_OPTIONS} "${LB_MIRROR_CHROOT}"/${UDEB} || wget ${WGET_OPTIONS} "${LB_PARENT_MIRROR_CHROOT}"/${UDEB}
			fi
624
625
626
627
		fi
	done

	# Caching udebs
628
629
630
	rm -rf ../cache/packages.installer_debian-installer.udeb
	mkdir -p ../cache/packages.installer_debian-installer.udeb
	cp *.udeb ../cache/packages.installer_debian-installer.udeb
631
632

	# Including local udebs
633
	if Find_files ../config/packages.binary/*_"${LIVE_IMAGE_ARCHITECTURE}".udeb || Find_files ../config/packages/*_"${LIVE_IMAGE_ARCHITECTURE}".udeb
634
	then
635
		for FILE in ../config/packages.binary/*_"${LIVE_IMAGE_ARCHITECTURE}".udeb ../config/packages/*_"${LIVE_IMAGE_ARCHITECTURE}".udeb
636
		do
637
638
			if [ -e "${FILE}" ]
			then
639
				Install_file "${FILE}" "pool"
640

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

647
	if Find_files ../config/packages.binary/*_all.udeb || Find_files ../config/packages/*_all.udeb
648
	then
649
		for FILE in ../config/packages.binary/*_all.udeb ../config/packages/*_all.udeb
650
		do
651
652
			if [ -e "${FILE}" ]
			then
653
				Install_file "${FILE}" "pool"
654

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

661
	# Excluding udebs
662
663
664
665
666
667
	for LOCATION in "${LIVE_BUILD}/data/debian-cd" /usr/share/live/build/data/debian-cd
	do
		if [ -e "${LOCATION}" ]
		then
			grep -v "^#" "${LOCATION}/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}/udeb_exclude" > exclude || true
	grep -v "^#" "${LOCATION}/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}/exclude-udebs" >> exclude || true
668
	grep -v "^#" "${LOCATION}/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}/exclude-udebs-${LIVE_IMAGE_ARCHITECTURE}" >> exclude || true
669
670
671
672

			continue
		fi
	done
673

674
	# Local exclude file
675
	if [ -e ../config/debian-installer/udeb_exclude ]
676
	then
677
		cat ../config/debian-installer/udeb_exclude >> exclude
678
	fi
679

680
681
682
	# 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

683
	while read EXCLUDE
684
	do
685
		if [ "${LB_DEBIAN_INSTALLER}" = "live" ] && [ "${EXCLUDE}" = "live-installer" ]
686
687
688
689
		then
			continue
		fi

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

693
694
695
696
697
698
699
700
701
	# Moving udebs
	for UDEB in ${UDEBS}
	do
		if [ -f "$(basename ${UDEB})" ]
		then
			mkdir -p $(dirname ${UDEB})
			mv "$(basename ${UDEB})" "$(dirname ${UDEB})"
		fi
	done
702

703
	# Creating udeb indices
704
	mkdir -p dists/"${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}"/main/debian-installer/binary-"${LIVE_IMAGE_ARCHITECTURE}"
705
706
707
	cd "${OLDPWD}"

	mv binary.udeb chroot/root
708
	echo "cd /root/binary.udeb && apt-ftparchive packages pool/main > dists/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}/main/debian-installer/binary-${LIVE_IMAGE_ARCHITECTURE}/Packages" > chroot/binary.sh
709
710
711
712
713
	Chroot chroot "sh binary.sh"
	rm -f chroot/binary.sh
	mv chroot/root/binary.udeb ./

	cd binary.udeb
714
	gzip -9 -c dists/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}/main/debian-installer/binary-${LIVE_IMAGE_ARCHITECTURE}/Packages > dists/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}/main/debian-installer/binary-${LIVE_IMAGE_ARCHITECTURE}/Packages.gz
715
716
717
718
719
720
721
722
723

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

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

	# Generating release file
724
725
	mv binary chroot/root

726
	eval _VERSION="$`echo RELEASE_${LB_PARENT_DISTRIBUTION}`"
727

728
	case "${LB_PARENT_DISTRIBUTION}" in
729
730
731
732
733
		sid)
			_SUITE="unstable"
			;;

		*)
734
			_SUITE="${LB_PARENT_DISTRIBUTION}"
735
736
737
			;;
	esac

738
739
740
741
cat > chroot/binary.sh << EOF
cd /root/binary && apt-ftparchive \
	-o APT::FTPArchive::Release::Origin="Debian" \
	-o APT::FTPArchive::Release::Label="Debian" \
742
743
	-o APT::FTPArchive::Release::Suite="${_SUITE}" \
	-o APT::FTPArchive::Release::Version="${_VERSION}" \
744
	-o APT::FTPArchive::Release::Codename="${LB_PARENT_DISTRIBUTION}" \
745
	-o APT::FTPArchive::Release::Date="$(date -R)" \
746
747
	-o APT::FTPArchive::Release::Architectures="${LIVE_IMAGE_ARCHITECTURE}" \
	-o APT::FTPArchive::Release::Components="${LIVE_IMAGE_PARENT_ARCHIVE_AREAS}" \
748
	-o APT::FTPArchive::Release::Description="Last updated: $(date -R)" \
749
	release dists/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION} > dists/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}/Release
750
751
752
753
754
EOF

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

756
757
	case "${LB_PARENT_DISTRIBUTION}" in
		wheezy)
758
			DISTRIBUTIONS="stable"
759
760
761
762
763
764
			;;

		*)
			DISTRIBUTIONS="stable testing unstable"
			;;
	esac
765

766
	if [ "${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}" != "${LB_PARENT_DISTRIBUTION}" ]
767
	then
768
		DISTRIBUTIONS="${DISTRIBUTIONS} ${LB_PARENT_DISTRIBUTION}"
769
	fi
770

771
	case "${LIVE_IMAGE_TYPE}" in
772
		hdd)
773
			case "${LB_BINARY_FILESYSTEM}" in
774
				fat*|ntfs)
775
776
777
					# Creating dist directories
					for DISTRIBUTION in ${DISTRIBUTIONS}
					do
778
						cp -a binary/dists/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION} binary/dists/${DISTRIBUTION}
779
780
781
					done
					;;
			esac
782
783
784
			;;

		*)
785
786
787
			# Creating dist symlinks
			for DISTRIBUTION in ${DISTRIBUTIONS}
			do
788
				ln -s ${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION} binary/dists/${DISTRIBUTION}
789
790
			done

791
792
793
			ln -s . binary/debian
			;;
	esac
794
fi
795

796
797
Repack_initrd()
{
798
	local TARGET_INITRD
799
	local INCLUDE_PATH
800
	TARGET_INITRD="${1}"
801
	INCLUDE_PATH="${2}"
802
	REPACK_TMPDIR="unpacked-initrd"
803

804
805
806
807
808
	if [ -d "${INCLUDE_PATH}" ]
	then
		INCLUDE_PATH=$(readlink -f ${INCLUDE_PATH})
	fi

809
810
811
812
813
	# 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
814
815
816
	if [ ! -d "${INCLUDE_PATH}" ]
	then
		# Invoked the old way, just copy the preseeds
817
818
819
820
821
822
823
		for _FILE in ../config/preseed/*.cfg ../config/preseed/*.cfg.installer
		do
			if [ -e "${_FILE}" ]
			then
				cp "${_FILE}" .
			fi
		done
824
825
826
827
828
829
830
831
	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}
832
833
834
835
836
837

	cd ..
	rm -rf ${REPACK_TMPDIR}
}

# Preseed d-i by repacking the initrd in certain situations
838
if [ "${DI_IMAGE_TYPE}" = "netboot" ] && ( ls config/preseed/*.cfg > /dev/null 2>&1 || ls config/preseed/*.cfg.installer > /dev/null 2>&1 )
839
then
840
	Repack_initrd "${DESTDIR}"/"${INITRD_DI}"
841
842
843

	if [ -e "${DESTDIR}"/"${INITRD_GI}" ]
	then
844
		Repack_initrd "${DESTDIR}"/"${INITRD_GI}"
845
	fi
846
847
fi

848
849
# Include content of config/includes.installer if exists and not empty
if [ -d config/includes.installer ] && [ -n "$(ls -A config/includes.installer)" ]
850
then
851
	Repack_initrd "${DESTDIR}"/"${INITRD_DI}" config/includes.installer
852
853
854

	if [ -e "${DESTDIR}"/"${INITRD_GI}" ]
	then
855
		Repack_initrd "${DESTDIR}"/"${INITRD_GI}" config/includes.installer
856
857
858
	fi
fi

859
860
861
862
863
864
865
866
case "${LB_MODE}" in
	progress-linux)
		mv binary/install binary/installer

		rm -f binary/debian

		for _DIRECTORY in dists pool project firmware
		do
867
			if [ -e "binary/${_DIRECTORY}" ]
868
869
870
871
872
873
874
			then
				mv binary/"${_DIRECTORY}" binary/installer
			fi
		done
		;;
esac

875
# Saving cache
876
Save_cache cache/packages.binary
877
878
879
880

# Removing depends
Remove_package

881
# Creating stage file
882
Create_stagefile .build/installer_debian-installer