summaryrefslogtreecommitdiff
path: root/helpers/lh_buildbinary
blob: 2a11c9bf491e5302d5e79c50c5ceb55f11643830 (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
#!/bin/sh

# lh_buildbinary

if [ ! -f "${LIVE_ROOT}"/.stage/image_binary ]
then
	# Configure chroot
	lh_patchchroot apply
	lh_patchrunlevel apply

	# Configure network
	lh_patchnetwork apply

	mkdir -p "${LIVE_ROOT}"/binary/casper
	for MANIFEST in "${LIVE_ROOT}"/filesystem.manifest*
	do
		if [ -e "${MANIFEST}" ]; then
			mv "${MANIFEST}" "${LIVE_ROOT}"/binary/casper/
		fi
	done

	if [ "${LIVE_TYPE}" = "Net" ]
	then
		# Mount proc
		mount proc-live -t proc "${LIVE_CHROOT}"/proc

		# Installing smbfs
		lh_chroot "aptitude install --assume-yes smbfs"

		# Unmount proc
		umount "${LIVE_CHROOT}"/proc

		if [ "${LIVE_ARCHITECTURE}" = "amd64" ] || [ "${LIVE_ARCHITECTURE}" = "i386" ]
		then
			if [ ! -d "${LIVE_CHROOT}"/etc/initramfs-tools ]
			then
				mkdir "${LIVE_CHROOT}"/etc/initramfs-tools
			fi

			# Configuring initramfs for NFS
cat >> "${LIVE_CHROOT}"/etc/initramfs-tools/initramfs.conf << EOF
MODULES=netboot
BOOT=nfs
NFSROOT=auto
EOF
			lh_chroot "update-initramfs -tu"
		fi
	fi

	lh_cleanapt

	# Switching package indices to default
	if [ "${LIVE_GENERIC_INDICES}" = "yes" ]
	then
		lh_setupapt default
		lh_configapt deapply-proxy
		lh_configapt deapply-recommends
	fi

	# Deconfigure network
	lh_patchnetwork deapply

	# Deconfigure chroot
	lh_patchrunlevel deapply
	lh_patchchroot deapply

	# Generating rootfs image
	lh_genrootfs

	# Configure chroot
	lh_patchchroot apply
	lh_patchrunlevel apply

	# Configure network
	lh_patchnetwork apply

	lh_cleanapt

	# Switching package indices to custom
	lh_setupapt custom
	lh_configapt apply-proxy
	lh_configapt apply-recommends

	case "${LIVE_TYPE}" in
		Iso)
			TYPE=iso
			;;
		Usb)
			TYPE=usb
			;;
		Net)
			TYPE=net
			;;
	esac

	# Mount proc
	mount proc-live -t proc "${LIVE_CHROOT}"/proc

	# Install depends
	lh_depends install $TYPE

	# Installing syslinux
	lh_installsyslinux $TYPE

	# Installing linux-image
	lh_installlinux $TYPE

	# Installing memtest
	lh_installmemtest86+ $TYPE

	# Deconfigure network
	lh_patchnetwork deapply

	# Deconfigure chroot
	lh_patchrunlevel deapply
	lh_patchchroot deapply

	# Installing templates
	if [ "${LIVE_FLAVOUR}" != "minimal" ] || [ "${LIVE_FLAVOUR}" != "mini" ]
	then
		if [ "${TYPE}" != "usb" ]
		then
			cp -r "${LIVE_TEMPLATES}"/common/* "${LIVE_ROOT}"/binary
		fi

		if [ "${TYPE}" = "iso" ] || [ "${TYPE}" = "usb" ]
		then
			cp -r "${LIVE_TEMPLATES}"/iso/* "${LIVE_ROOT}"/binary
		fi
	fi

	# Calculating md5sums
	lh_md5sums

	case "${TYPE}" in
		iso)
			if [ "${LIVE_ARCHITECTURE}" = "amd64" ] || [ "${LIVE_ARCHITECTURE}" = "i386" ]
			then
				# 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}"binary.iso -r -J -l -V "${LIVE_DISK_VOLUME}" -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table "${LIVE_ROOT}"/binary ${LIVE_INCLUDE_IMAGE}
			else
				echo "W: Bootloader on your architecture not yet supported (Continuing in 5 seconds)."
				sleep 5
				# 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}"binary.iso -r -J -l -V "${LIVE_DISK_VOLUME}" "${LIVE_ROOT}"/binary ${LIVE_INCLUDE_IMAGE}
			fi
			;;

		net)
			cd "${LIVE_ROOT}" && \
			mv binary "`basename ${LIVE_SERVER_PATH}`" && \
			cd .. && \
			tar cfz binary.tar.gz "`basename ${LIVE_ROOT}`/`basename ${LIVE_SERVER_PATH}`" "`basename ${LIVE_ROOT}`/tftpboot" && \
			mv binary.tar.gz "${LIVE_ROOT}" && \
			cd "${OLDPWD}" && \
			mv "`basename ${LIVE_SERVER_PATH}`" binary
			;;

		usb)
			# Everything which comes here needs to be cleaned up,
			DU_DIM="`du -ms ${LIVE_ROOT}/binary | 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}"/binary.img bs=1024k count=${REAL_DIM}

			FREELO="`lh_chroot 'losetup -f'`"

			echo "!!! The following error/warning messages can be ignored !!!"
			lh_losetup $FREELO "${LIVE_ROOT}"/binary.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 boot on"
			lh_chroot "parted -s ${FREELO} set 1 lba off"
			set -e
			cat "${LIVE_CHROOT}"/usr/lib/syslinux/mbr.bin > ${FREELO}
			losetup -d ${FREELO}

			lh_losetup $FREELO "${LIVE_ROOT}"/binary.img 1
			lh_chroot "mkfs.msdos -n DEBIAN_LIVE ${FREELO}"
			mkdir "${LIVE_ROOT}"/binary.tmp
			mount ${FREELO} "${LIVE_ROOT}"/binary.tmp
			cp -r "${LIVE_ROOT}"/binary/* "${LIVE_ROOT}"/binary.tmp
			umount "${LIVE_ROOT}"/binary.tmp
			rmdir "${LIVE_ROOT}"/binary.tmp
			lh_chroot "syslinux ${FREELO}"
			losetup -d ${FREELO}

			echo "!!! The above error/warning messages can be ignored !!!"
			;;
	esac

	# Remove depends
	lh_depends remove $TYPE

	# Unmount proc
	umount "${LIVE_CHROOT}"/proc

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