summaryrefslogtreecommitdiff
path: root/helpers/lh_buildsource
blob: 836bd3c09034f92c4ea56205a8029cb02af67fc3 (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
#!/bin/sh

# lh_buildsource.sh <type>

if [ ! -f "${LIVE_ROOT}"/.stage/image_source ] && [ "${LIVE_SOURCE}" = "yes" ]
then
	# Configure chroot
	lh_patchnetwork apply

	# Download sources
	lh_chroot "dpkg --get-selections" | awk '{ print $1 }' > "${LIVE_CHROOT}"/root/dpkg-selection.txt
	lh_chroot "xargs --arg-file=/root/dpkg-selection.txt apt-get source --download-only"
	rm -f "${LIVE_CHROOT}"/root/dpkg-selection.txt

	# Sort sources
	for DSC in "${LIVE_CHROOT}"/*.dsc
	do
		SOURCE="`awk '/Source:/ { print $2; }' ${DSC}`"

		if [ "`echo ${SOURCE} | cut -b 1-3`" == "lib" ]
		then
			LETTER="`echo ${SOURCE} | cut -b 1-4`"
		else
			LETTER="`echo ${SOURCE} | cut -b 1`"
		fi

		# Install directory
		install -d -m 0755 "${LIVE_ROOT}"/source/"${LETTER}"/"${SOURCE}"

		# Move files
		mv "${LIVE_CHROOT}"/"${SOURCE}"_* "${LIVE_ROOT}"/source/"${LETTER}"/"${SOURCE}"
	done

	case "${1}" in
		generic)
			# Create tarball
			tar cf source.tar "$LIVE_ROOT"/source
			;;

		iso)
			# Create image
			${GENISOIMAGE} -A "Debian Live" -p "Debian Live; http://debian-live.alioth.debian.org/; debian-live-devel@lists.alioth.debian.org" -publisher "Debian Live; http://debian-live.alioth.debian.org/; debian-live-devel@lists.alioth.debian.org" -o "${LIVE_ROOT}"/"${LIVE_IMAGE}"source.iso -r -J -l -V "${LIVE_DISK_VOLUME}" "${LIVE_ROOT}"/source
			;;

		net)
			# Create tarball
			tar cfz source.tar.gz "${LIVE_ROOT}"/source
			;;

		usb)
			# Create image
			DU_DIM="`du -ms ${LIVE_ROOT}/source | cut -f1`"
	                REAL_DIM="`expr ${DU_DIM} + ${DU_DIM} / 20`" # Just 5% more to be sure, need something more sophistcated here...
			dd if=/dev/zero of="${LIVE_ROOT}"/source.img bs=1024k count=${REAL_DIM}
			FREELO=`losetup -f`

			echo "!!! The following error/warning messages can be ignored !!!"
			lh_losetup $FREELO "${LIVE_ROOT}"/source.img 0
			set +e
			lh_chroot "parted -s ${FREELO} mklabel msdos"
			lh_chroot "parted -s ${FREELO} mkpartfs primary fat16 0.0 100%"
			lh_chroot "parted -s ${FREELO} set 1 lba off"
			set -e
			losetup -d ${FREELO}

			lh_losetup $FREELO "${LIVE_ROOT}"/source.img 1
			lh_chroot "mkfs.msdos -n DEBIAN_LIVE ${FREELO}"
			mkdir "${LIVE_ROOT}"/source.tmp
			mount ${FREELO} "${LIVE_ROOT}"/source.tmp
			cp -r "${LIVE_ROOT}"/source/* "${LIVE_ROOT}"/source.tmp
			umount "${LIVE_ROOT}"/source.tmp
			rmdir "${LIVE_ROOT}"/source.tmp
			losetup -d ${FREELO}
			echo "!!! The above error/warning messages can be ignored !!!"
			;;
	esac


	# Deconfigure network
	lh_patchnetwork deapply

	# Touching stage file
	touch "${LIVE_ROOT}"/.stage/image_source
fi