summaryrefslogtreecommitdiff
path: root/cron/live-build-cron-images
blob: c76d96ed9d89c09f350b19b39af334bede9594be (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
#!/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

Init ()
{
	if [ -e /etc/live/build-cron.conf ]
	then
		. /etc/live/build-cron.conf
	fi

	if ls /etc/live/build-cron.d/* > /dev/null 2>&1
	then
		for _FILE in /etc/live/build-cron.d/*
		do
			. ${_FILE}
		done
	fi

	if [ "${LIVE_BUILD_CRON_IMAGES}" != "true" ]
	then
		exit 0
	fi

	if [ -z "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}" ]
	then
		exit 1
	fi

	# FIXME: don't hardcode
	BUILDS="daily"
	DATE="$(date +%Y%m%d)"

	ARCHITECTURE="$(dpkg --print-architecture)"
	eval DISTRIBUTIONS="$`echo LIVE_BUILD_CRON_IMAGES_$(echo ${BUILDS} | tr [a-z] [A-Z])_DISTRIBUTIONS`"
	eval FLAVOURS="$`echo LIVE_BUILD_CRON_IMAGES_$(echo ${BUILDS} | tr [a-z] [A-Z])_FLAVOURS`"
}

Setup ()
{
	_TMPDIR="$(mktemp -d -t live-build-cron-images.XXXXXXXX)"

	case "${LIVE_BUILD_CRON_IMAGES_BUILD}" in
		git)
			cd "${_TMPDIR}"
			git clone git://live.debian.net/git/live-build.git
			git checkout debian-old-2.0

			LB_BASE="${_TMPDIR}/live-build"
			export LB_BASE

			PATH="${PATH}:${_TMPDIR}/live-build/scripts/build"
			export PATH
			;;

		release)
			# live-build
			if [ -n "${LIVE_BUILD}" ]
			then
				if [ -x "$(which dget 2>/dev/null)" ]
				then
					dget "http://live.debian.net/archive/packages/live-build/${LIVE_BUILD}/live-build_${LIVE_BUILD}.dsc"
					dpkg-source -x live-build_${LIVE_BUILD}.dsc

					LB_BASE="${_TMPDIR}/live-build-$(echo ${LIVE_BUILD} | awk -F- '{ print $1 }')"
					export LB_BASE

					PATH="${PATH}:${_TMPDIR}/live-build-$(echo ${LIVE_BUILD} | awk -F- '{ print $1 }')/scripts/build"
					export PATH
				else
					echo "E: dget - command not found"
					echo "I: dget can be optained from: "
					echo "I:   http://git.debian.org/?p=devscripts/devscripts.git"
					echo "I: On Debian based systems, dget can be installed with:"
					echo "I:   apt-get install devscripts"

					exit 1
				fi
			fi
			;;
	esac

	mkdir -p "${_TMPDIR}/build"
	cd "${_TMPDIR}/build"

	# live-boot
	if [ -n "${LIVE_BOOT}" ]
	then
		mkdir -p config/chroot_local-packages
		cd config/chroot_local-packages

		wget -c "http://live.debian.net/archive/packages/live-boot/${LIVE_BOOT}/live-boot_${LIVE_BOOT}.dsc"
		wget -c "http://live.debian.net/archive/packages/live-boot/${LIVE_BOOT}/live-boot_${LIVE_BOOT}.diff.gz"
		wget -c "http://live.debian.net/archive/packages/live-boot/${LIVE_BOOT}/live-boot_$(echo ${LIVE_BOOT} | awk -F- '{ print $1 }').orig.tar.gz"
		wget -c "http://live.debian.net/archive/packages/live-boot/${LIVE_BOOT}/live-boot_${LIVE_BOOT}_all.deb"
		wget -c "http://live.debian.net/archive/packages/live-boot/${LIVE_BOOT}/live-boot-initramfs-tools_${LIVE_BOOT}_all.deb"
		wget -c "http://live.debian.net/archive/packages/live-boot/${LIVE_BOOT}/live-initramfs_${LIVE_BOOT}_all.deb"

		cd "${OLDPWD}"
	fi

	# live-config
	if [ -n "${LIVE_CONFIG}" ]
	then
		mkdir -p config/chroot_local-packages
		cd config/chroot_local-packages

		wget -c "http://live.debian.net/archive/packages/live-config/${LIVE_CONFIG}/live-config_${LIVE_CONFIG}.dsc"
		wget -c "http://live.debian.net/archive/packages/live-config/${LIVE_CONFIG}/live-config_${LIVE_CONFIG}.diff.gz"
		wget -c "http://live.debian.net/archive/packages/live-config/${LIVE_CONFIG}/live-config_$(echo ${LIVE_CONFIG} | awk -F- '{ print $1 }').orig.tar.gz"
		wget -c "http://live.debian.net/archive/packages/live-config/${LIVE_CONFIG}/live-config_${LIVE_CONFIG}_all.deb"
		wget -c "http://live.debian.net/archive/packages/live-config/${LIVE_CONFIG}/live-config-sysvinit_${LIVE_CONFIG}_all.deb"

		cd "${OLDPWD}"
	fi

	# live-installer
	if [ -n "${LIVE_INSTALLER}" ]
	then
		mkdir -p config/binary_local-udebs
		cd config/binary_local-udebs

		wget -c "http://ftp.debian.org/debian/pool/main/l/live-installer/live-installer_${LIVE_INSTALLER}.dsc"
		wget -c "http://ftp.debian.org/debian/pool/main/l/live-installer/live-installer_${LIVE_INSTALLER}.tar.gz"
		wget -c "http://ftp.debian.org/debian/pool/main/l/live-installer/live-installer_${LIVE_INSTALLER}_${ARCHITECTURE}.udeb"

		cd "${OLDPWD}"
	fi

	# debian-installer-launcher
	if [ -n "${DI_LAUNCHER}" ]
	then
		mkdir -p config/chroot_local-packages
		cd config/chroot_local-packages

		wget -c "http://ftp.debian.org/debian/pool/main/d/debian-installer-launcher/debian-installer-launcher_${DI_LAUNCHER}.dsc"
		wget -c "http://ftp.debian.org/debian/pool/main/d/debian-installer-launcher/debian-installer-launcher_${DI_LAUNCHER}.tar.gz"
		wget -c "http://ftp.debian.org/debian/pool/main/d/debian-installer-launcher/debian-installer-launcher_${DI_LAUNCHER}_all.deb"

		cd "${OLDPWD}"
	fi
}

Build ()
{
	cd "${_TMPDIR}/build"

	for DISTRIBUTION in ${DISTRIBUTIONS}
	do
		rm -rf cache/stages*

		for FLAVOUR in ${FLAVOURS}
		do
			if [ -e .stage ]
			then
				lb clean
			fi

			rm -rf cache/stages_rootfs
			rm -f config/* || true

			LB_VERSION="$(lb --version | awk '/^live-build, version / { print $3 }')"

			case "${LB_VERSION}" in
				2.0*)
					_PACKAGE_LISTS="--packages-lists ${FLAVOUR}"
					;;

				3.0*)
					_PACKAGE_LISTS="--package-lists ${FLAVOUR}"
					;;
			esac

			# FIXME: cdebootstrap
			lb config --clean \
				--bootstrap cdebootstrap \
				--cache-stages "bootstrap rootfs" \
				--debian-installer ${DEBIAN_INSTALLER} \
				--distribution ${DISTRIBUTION} \
				--mirror-bootstrap ${MIRROR_BOOTSTRAP} \
				--mirror-chroot ${MIRROR_CHROOT} \
				--mirror-chroot-security ${MIRROR_CHROOT_SECURITY} \
				${_PACKAGE_LISTS}

			lb build 2>&1 | tee debian-live-${DISTRIBUTION}-${ARCHITECTURE}-${FLAVOUR}.iso.log

			mv binary*.iso debian-live-${DISTRIBUTION}-${ARCHITECTURE}-${FLAVOUR}.iso
			mv binary.list debian-live-${DISTRIBUTION}-${ARCHITECTURE}-${FLAVOUR}.iso.list
			mv binary.packages debian-live-${DISTRIBUTION}-${ARCHITECTURE}-${FLAVOUR}.iso.packages

			if [ "${ARCHITECTURE}" != "powerpc" ]
			then
				lb clean --binary
				lb config --clean --binary-images usb-hdd
				lb binary 2>&1 | tee debian-live-${DISTRIBUTION}-${ARCHITECTURE}-${FLAVOUR}.img.log

				mv binary.img debian-live-${DISTRIBUTION}-${ARCHITECTURE}-${FLAVOUR}.img
				mv binary.list debian-live-${DISTRIBUTION}-${ARCHITECTURE}-${FLAVOUR}.img.list
				mv binary.packages debian-live-${DISTRIBUTION}-${ARCHITECTURE}-${FLAVOUR}.img.packages
			fi

			if [ "${ARCHITECTURE}" != "powerpc" ]
			then
				lb clean
				rm -rf cache/stages_rootfs
				lb config --clean --binary-images net

				lb build 2>&1 | tee debian-live-${DISTRIBUTION}-${ARCHITECTURE}-${FLAVOUR}.tar.gz.log

				mv binary-net.tar.gz debian-live-${DISTRIBUTION}-${ARCHITECTURE}-${FLAVOUR}.tar.gz
				mv binary.list debian-live-${DISTRIBUTION}-${ARCHITECTURE}-${FLAVOUR}.tar.gz.list
				mv binary.packages debian-live-${DISTRIBUTION}-${ARCHITECTURE}-${FLAVOUR}.tar.gz.packages

				mv binary/*/filesystem.squashfs debian-live-${DISTRIBUTION}-${ARCHITECTURE}-${FLAVOUR}.squashfs
				for memtest in tftpboot/debian-live/${ARCHITECTURE}/memtest*; do cp -f ${memtest} debian-live-${DISTRIBUTION}-${ARCHITECTURE}.$(basename ${memtest}); done || true
				for kernel in tftpboot/debian-live/${ARCHITECTURE}/vmlinuz*; do cp -f ${kernel} debian-live-${DISTRIBUTION}-${ARCHITECTURE}.$(basename ${kernel}); done
				for initrd in tftpboot/debian-live/${ARCHITECTURE}/initrd*; do cp ${initrd} debian-live-${DISTRIBUTION}-${ARCHITECTURE}-${FLAVOUR}.$(basename ${initrd}); done
				cp debian-live-${DISTRIBUTION}-${ARCHITECTURE}-${FLAVOUR}.tar.gz.packages debian-live-${DISTRIBUTION}-${ARCHITECTURE}-${FLAVOUR}.packages
			fi

			if [ "${LIVE_BUILD_CRON_IMAGES_SOURCE}" = "true" ]
			then
				lb config --clean --source true

				lb source 2>&1 | tee debian-live-${DISTRIBUTION}-source-${FLAVOUR}.log

				mv source.debian.tar.gz debian-live-${DISTRIBUTION}-source-${FLAVOUR}.debian.tar.gz
				mv source.debian.list debian-live-${DISTRIBUTION}-source-${FLAVOUR}.debian.tar.gz.list
				mv source.debian-live.tar.gz debian-live-${DISTRIBUTION}-source-${FLAVOUR}.debian-live.tar.gz
				mv source.debian-live.list debian-live-${DISTRIBUTION}-source-${FLAVOUR}.debian-live.tar.gz.list
			fi
		done
	done
}

Install ()
{
	BUILD="1"

	while [ -e "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}/${BUILDS}-builds/${DISTRIBUTION}/${DATE}-${BUILD}/${ARCHITECTURE}" ]
	do
		BUILD="$((${BUILD} + 1))"
	done

	cd "${_TMPDIR}/build"

	# Move iso images
	if ls debian-live-${DISTRIBUTION}-${ARCHITECTURE}-*.iso* > /dev/null 2>&1
	then
		mkdir -p "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}/${BUILDS}-builds/${DISTRIBUTION}/${DATE}-${BUILD}/${ARCHITECTURE}/iso-hybrid"
		mv debian-live-${DISTRIBUTION}-${ARCHITECTURE}-*.iso* "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}/${BUILDS}-builds/${DISTRIBUTION}/${DATE}-${BUILD}/${ARCHITECTURE}/iso-hybrid"
	fi

	# Move hdd images
	if ls debian-live-${DISTRIBUTION}-${ARCHITECTURE}-*.img > /dev/null 2>&1
	then
		mkdir -p "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}/${BUILDS}-builds/${DISTRIBUTION}/${DATE}-${BUILD}/${ARCHITECTURE}/usb-hdd"
		mv debian-live-${DISTRIBUTION}-${ARCHITECTURE}-*.img* "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}/${BUILDS}-builds/${DISTRIBUTION}/${DATE}-${BUILD}/${ARCHITECTURE}/usb-hdd"
	fi

	# Move net images
	if ls debian-live-${DISTRIBUTION}-${ARCHITECTURE}-*.tar.gz* > /dev/null 2>&1
	then
		mkdir -p "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}/${BUILDS}-builds/${DISTRIBUTION}/${DATE}-${BUILD}/${ARCHITECTURE}/net"
		mv debian-live-${DISTRIBUTION}-${ARCHITECTURE}-*.tar.gz* "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}/${BUILDS}-builds/${DISTRIBUTION}/${DATE}-${BUILD}/${ARCHITECTURE}/net"
	fi

	# Move web images
	if ls debian-live-${DISTRIBUTION}-${ARCHITECTURE}-*.squashfs > /dev/null 2>&1
	then
		mkdir -p "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}/${BUILDS}-builds/${DISTRIBUTION}/${DATE}-${BUILD}/${ARCHITECTURE}/web"
		mv debian-live-${DISTRIBUTION}-${ARCHITECTURE}-*.squashfs "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}/${BUILDS}-builds/${DISTRIBUTION}/${DATE}-${BUILD}/${ARCHITECTURE}/web"
		mv debian-live-${DISTRIBUTION}-${ARCHITECTURE}-*.packages* "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}/${BUILDS}-builds/${DISTRIBUTION}/${DATE}-${BUILD}/${ARCHITECTURE}/web"
		mv debian-live-${DISTRIBUTION}-${ARCHITECTURE}-*.vmlinuz* "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}/${BUILDS}-builds/${DISTRIBUTION}/${DATE}-${BUILD}/${ARCHITECTURE}/web"
		mv debian-live-${DISTRIBUTION}-${ARCHITECTURE}-*.initrd.img* "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}/${BUILDS}-builds/${DISTRIBUTION}/${DATE}-${BUILD}/${ARCHITECTURE}/web"
	fi

	# Move source images
	if ls debian-live-${DISTRIBUTION}-source-* > /dev/null 2>&1 && \
	   [ ! -d "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}/${BUILDS}-builds/${DISTRIBUTION}/${DATE}-${BUILD}/source" ]
	then
		mkdir -p "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}/${BUILDS}-builds/${DISTRIBUTION}/${DATE}-${BUILD}/source/tar"
		mv debian-live-${DISTRIBUTION}-source-*  "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}/${BUILDS}-builds/${DISTRIBUTION}/${DATE}-${BUILD}/source/tar"
	fi

	for DIR in "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}/${BUILDS}-builds/${DISTRIBUTION}/${DATE}-${BUILD}/${ARCHITECTURE}"/*  "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}/${BUILDS}-builds/${DISTRIBUTION}/${DATE}-${BUILD}/source"/*
	do
		cd "${DIR}"

		md5sum debian* > MD5SUMS
		sha1sum debian* > SHA1SUMS
		sha256sum debian* > SHA256SUMS
	done

	rm -f "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}/${BUILDS}-builds/${DISTRIBUTION}/current"

	cd "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}/${BUILDS}-builds/${DISTRIBUTION}"
	ln -s ${DATE}-${BUILD} current
}

Clean ()
{
	cd "${_TMPDIR}/build"
	lb clean --purge

	cd "${CURDIR}"
	rm -rf "${_TMPDIR}"
}

Trace ()
{

cat > "${LIVE_BUILD_CRON_IMAGES_DIRECTORY}/${BUILDS}-builds/${BUILDS}-trace" << EOF
${DATE}-${BUILD}
$(LC_ALL=C date -R)
EOF

}

Main ()
{
	Init
	Setup

	Build
	Install
	Clean

	Trace
}

Main