Projet

Général

Profil

Télécharger (10,6 ko) Statistiques
| Branche: | Révision:

univnautes-tools / builder_scripts / build.sh @ 257549ed

1
#!/bin/sh
2
#
3
# Common functions to be used by build scripts
4
#
5
#  build_iso.sh
6
#  Copyright (C) 2004-2009 Scott Ullrich
7
#  All rights reserved.
8
#  
9
#  Redistribution and use in source and binary forms, with or without
10
#  modification, are permitted provided that the following conditions are met:
11
#  
12
#  1. Redistributions of source code must retain the above copyright notice,
13
#     this list of conditions and the following disclaimer.
14
#  
15
#  2. Redistributions in binary form must reproduce the above copyright
16
#     notice, this list of conditions and the following disclaimer in the
17
#     documentation and/or other materials provided with the distribution.
18
#  
19
#  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
#  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
#  AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
#  AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
#  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
#  POSSIBILITY OF SUCH DAMAGE.
29
#
30
# Crank up error reporting, debugging.
31
#  set -e 
32
#  set -x
33

    
34
set +e
35
usage() {
36
	echo "Usage $0 [options] [ iso | nanobsd | ova | nanobsd-vga | memstick | memstickserial | fullupdate | all ]"
37
	echo "		all = iso nanobsd nanobsd-vga memstick memstickserial fullupdate"
38
	echo "	[ options ]: "
39
	echo "		--flash-size|-f size(s) - a list of flash sizes to build with nanobsd i.e. '512m 1g'. Default: 512m"
40
	echo "		--flash-vendor|-m vendor - flash vendor type. check the code for supported vendors. Default: sandisk"
41
	echo "		--no-buildworld|-c - Will set NO_BUILDWORLD NO_BUILDKERNEL to not build kernel and world"
42
	echo "		--no-cleanobjdir|--no-cleanrepos|-d - Will not clean FreeBSD object built dir to allow restarting a build with NO_CLEAN"
43
	echo "		--resume-image-build|-r - Includes -c -d and also will just move directly to image creation using pre-staged data"
44
	echo "		--apply-patches - Fetch FreeBSD sources and apply patches"
45
	echo "		--build-pfPorts - Rebuild all ports required to generate an image"
46
	echo "		--build-pfPort port - Rebuild a single port required to generate an image"
47
	echo "		--builder-required-ports - Build ports required from builder tools to operate"
48
	echo "		--update-sources - Refetch all sources"
49
	echo "		--print-flags - Show current builder configuration"
50
	echo "		--clean-builder - clean all builder used data/resources"
51
	echo "		--configure - generate a config file to be used by builder tools"
52
	echo "		--build-kernels - build all configured kernels"
53
	echo "		--build-kernel argument - build specifed kernel. Exampe --build-kernel pfSense_SMP.10"
54
	echo "		--install-extra-kernels argument - Put extra kernel(s) under /kernel image directory. Exampe --install-extra-kernels pfSense_wrap.10.i386"
55
	echo "		--enable-memorydisks - This will put $PFSENSESTAGEDIR and $PFSENSEISODIR as MFS filesystems"
56
	echo "		--disable-memorydisks - Will just teardown these filesystsm created by --enable-memorydisks"
57
	exit 1
58
}
59

    
60
unset _SKIP_REBUILD_PRESTAGE
61
unset pfPORTTOBUILD
62
unset IMAGETYPE
63
BUILDACTION="images"
64

    
65
# Maybe use options for nocleans etc?
66
while test "$1" != ""; do
67
        case "${1}" in
68
	--no-buildworld|-c)
69
		export NO_BUILDWORLD=YES
70
		export NO_BUILDKERNEL=YES
71
	;;
72
	--no-cleanobjdir|--no-cleanrepos|-d)
73
		export NO_CLEANFREEBSDOBJDIR=YES
74
		export NO_CLEANREPOS=YES
75
	;;
76
	--flash-size|-f)
77
		shift
78
		if [ $# -eq 0 ]; then
79
			echo "--flash-model needs extra parameter."
80
			echo
81
			usage
82
		fi
83
		export FLASH_SIZE="${1}"
84
	;;
85
	--flash-model|-m)
86
		shift
87
		if [ $# -eq 0 ]; then
88
			echo "--flash-model needs extra parameter."
89
			echo
90
			usage
91
		fi
92
		export FLASH_MODEL="${1}"
93
	;;
94
	--resume-image-build|-r)
95
		export NO_BUILDWORLD=YES
96
                export NO_BUILDKERNEL=YES
97
		export NO_CLEANFREEBSDOBJDIR=YES
98
                export NO_CLEANREPOS=YES
99
		_SKIP_REBUILD_PRESTAGE=YES
100
	;;
101
	--apply-patches)
102
		BUILDACTION="applypatches"
103
	;;
104
	--build-pfPorts)
105
		BUILDACTION="buildpfports"
106
	;;
107
	--build-pfPort)
108
		BUILDACTION="buildpfport"
109
		shift
110
		if [ $# -eq 0 ]; then
111
			echo "--build-pfPort needs extra parameter."
112
			echo 
113
			usage
114
		fi
115
		pfPORTTOBUILD="$1"
116
	;;
117
	--builder-required-ports)
118
		BUILDACTION="builderrequiredports"
119
	;;
120
	--build-kernels)
121
		BUILDACTION="buildkernels"
122
	;;
123
	--install-extra-kernels)
124
		shift
125
		if [ $# -eq 0 ]; then
126
			echo "--build-kernel needs extra parameter."
127
			echo 
128
			usage
129
		fi
130
		export INSTALL_EXTRA_KERNELS="${1}"
131
	;;
132
	--build-kernel)
133
		BUILDACTION="buildkernel"
134
		shift
135
		if [ $# -eq 0 ]; then
136
			echo "--build-kernel needs extra parameter."
137
			echo 
138
			usage
139
		fi
140
		export BUILD_KERNELS="${1}"
141
	;;
142
	--update-sources)
143
		BUILDACTION="updatesources"
144
	;;
145
	--print-flags)
146
		BUILDACTION="printflags"
147
	;;
148
	--clean-builder)
149
		BUILDACTION="cleanbuilder"
150
	;;
151
	--configure)
152
		BUILDACTION="configure"
153
	;;
154
	--test-tweet)
155
		BUILDACTION="testtweet"
156
	;;
157
	--enable-memorydisks)
158
		BUILDACTION="enablememorydisk"
159
	;;
160
	--disable-memorydisks)
161
		BUILDACTION="disablememorydisk"
162
	;;
163
	--includes)
164
		BUILDACTION="includes"
165
	;;
166
	all|*iso*|*ova*|*memstick*|*memstickserial*|*nanobsd*|*nanobsd-vga*|*fullupdate*)
167
		BUILDACTION="images"
168
		IMAGETYPE="${1}"
169
	;;
170
	*)
171
		usage
172
        esac
173
	shift
174
done
175

    
176
# Suck in local vars
177
. ./builder_defaults.sh
178

    
179
_TMPPWD=$(cd .. && basename `pwd`)
180
if [ "${TOOLS_DIR}" != "${_TMPPWD}" ]; then
181
	echo "ERROR: builder tools checkout on ${_TMPPWD} not the same as TOOLS_DIR=${TOOLS_DIR} setting."
182
	exit 1
183
fi
184
unset _TMPPWD
185

    
186
# Suck in script helper functions
187
. ./builder_common.sh
188

    
189
# Define src.conf
190
if [ -z "${SRC_CONF:-}" ]; then
191
	export SRC_CONF="${BUILDER_SCRIPTS}/conf/src/src.conf.$FREEBSD_VERSION"
192
	export SRC_CONF_INSTALL="${BUILDER_SCRIPTS}/conf/src/src.conf.$FREEBSD_VERSION.install"
193
fi
194

    
195
if [ ! -z "${CUSTOM_REMOVE_LIST:-}" ]; then
196
	export PRUNE_LIST="${CUSTOM_REMOVE_LIST:-}"
197
else
198
	export PRUNE_LIST="${BUILDER_SCRIPTS}/conf/rmlist/remove.list.iso.$FREEBSD_VERSION"
199
fi
200

    
201
# This should be run first
202
launch
203

    
204
case $BUILDACTION in
205
	applypatches)
206
		update_freebsd_sources_and_apply_patches
207
	;;
208
	buildpfports)
209
		recompile_pfPorts
210
	;;
211
	buildpfport)
212
		recompile_pfPorts $pfPORTTOBUILD
213
	;;
214
	
215
	builderrequiredports)
216
		install_required_builder_system_ports
217
	;;
218
	buildkernels)
219
		update_freebsd_sources_and_apply_patches
220
		build_all_kernels
221
	;;
222
	buildkernel)
223
		update_freebsd_sources_and_apply_patches
224
		build_all_kernels
225
	;;
226
	configure)
227
		./scripts/menu.sh
228
	;;
229
	cleanbuilder)
230
		pfSense_clean_obj_dir
231
	;;
232
	printflags)
233
		print_flags
234
	;;
235
	images)
236
		# It will be handled below
237
	;;
238
	includes)
239
		update_freebsd_sources_and_apply_patches
240
		echo "==> Starting make includes operation..."
241
		( cd $SRCDIR && env SRCCONF=${SRC_CONF} make includes ) | egrep -wi '(^>>>|error)'
242
	;;
243
	testtweet)
244
		post_tweet "Robots need loving too."
245
	;;
246
	updatesources)
247
		ensure_source_directories_present
248
	;;
249
	enablememorydisk)
250
		prestage_on_ram_setup
251
	;;
252
	disablememorydisk)
253
		prestage_on_ram_cleanup
254
	;;
255
	*)
256
		usage
257
	;;
258
esac
259

    
260
if [ "${BUILDACTION}" != "images" ]; then
261
	# Email that the operation has completed
262
	email_operation_completed
263
	finish
264
	exit 0
265
fi
266

    
267
if [ $# -gt 1 ]; then
268
	echo "ERROR: Too many argument given."
269
	echo
270
	usage
271
fi
272
if [ -z "${IMAGETYPE}" ]; then
273
	echo "ERROR: Need to specify image type to build."
274
	echo
275
	usage
276
fi
277

    
278
if [ "$IMAGETYPE" = "all" ]; then
279
	_IMAGESTOBUILD="iso fullupdate nanobsd nanobsd-vga memstick memstickserial"
280
else
281
	_IMAGESTOBUILD="${IMAGETYPE}"
282
fi
283

    
284
echo ">>> Building image type(s): ${_IMAGESTOBUILD}"
285

    
286
if [ -z "${_SKIP_REBUILD_PRESTAGE}" ]; then
287
	# Cleanup environment before start
288
	pfSense_clean_obj_dir
289

    
290
	# Make sure source directories are present.
291
	ensure_source_directories_present
292
	git_last_commit
293

    
294
	# Ensure binaries are present that builder system requires
295
	install_required_builder_system_ports
296

    
297
	# Output build flags
298
	print_flags
299

    
300
	# Check to see if pre-staging will be hosted on ram
301
	prestage_on_ram_setup
302

    
303
	# Build world, kernel and install
304
	echo ">>> Building world for ISO... $FREEBSD_VERSION  $FREEBSD_BRANCH ..."
305
	make_world
306

    
307
	# Build kernels
308
	echo ">>> Building kernel configs: $BUILD_KERNELS for FreeBSD: $FREEBSD_BRANCH ..."
309
	build_all_kernels
310

    
311
	# Prepare pre-final staging area
312
	clone_to_staging_area
313

    
314
	# Check if we need to force a ports rebuild
315
	check_for_forced_pfPorts_build
316

    
317
	# Install packages needed for livecd
318
	install_pkg_install_ports
319

    
320
	# Overlay host binaries
321
	cust_overlay_host_binaries
322
fi
323

    
324
export DEFAULT_KERNEL=${DEFAULT_KERNEL_ISO:-pfSense_SMP.${FREEBSD_VERSION}}
325
for _IMGTOBUILD in $_IMAGESTOBUILD; do
326
	# Clean up items that should be cleaned each run
327
        staginareas_clean_each_run
328

    
329
	# NOTE: This code is needed to support FreeBSD 8(2.*.*) builds that have extra kernels under /kernels than default
330
	if [ $FREEBSD_VERSION -lt 10 -a -z "${INSTALL_EXTRA_KERNELS}" ]; then
331
		if [ "${_IMGTOBUILD}" = "nanobsd-vga" ]; then
332
			export INSTALL_EXTRA_KERNELS="pfSense_SMP.${FREEBSD_VERSION}"
333
		else
334
			export INSTALL_EXTRA_KERNELS="pfSense_wrap.${FREEBSD_VERSION}.${TARGET}"
335
		fi
336
	fi
337

    
338
	if [ "${_IMGTOBUILD}" = "iso" ]; then
339
		(create_iso_image)
340
	elif [ "${_IMGTOBUILD}" = "memstick" ]; then
341
		(create_memstick_image)
342
	elif [ "${_IMGTOBUILD}" = "memstickserial" ]; then
343
		(create_memstick_serial_image)
344
	elif [ "${_IMGTOBUILD}" = "fullupdate" ]; then
345
		create_pfSense_Full_update_tarball
346
	elif [ "${_IMGTOBUILD}" = "nanobsd" -o "${_IMGTOBUILD}" = "nanobsd-vga" ]; then
347
		if [ "${TARGET}" = "i386" -a "${_IMGTOBUILD}" = "nanobsd" ]; then
348
			export DEFAULT_KERNEL=${DEFAULT_KERNEL_NANOBSD:-pfSense_wrap.${FREEBSD_VERSION}.${TARGET}}
349
		elif [ "${TARGET}" = "i386" -a "${_IMGTOBUILD}" = "nanobsd-vga" ]; then
350
			export DEFAULT_KERNEL=${DEFAULT_KERNEL_NANOBSDVGA:-pfSense_wrap_vga.${FREEBSD_VERSION}.${TARGET}}
351
		elif [ "${TARGET}" = "amd64" ]; then
352
			export DEFAULT_KERNEL=${DEFAULT_KERNEL_NANOBSD:-pfSense_SMP.${FREEBSD_VERSION}}
353
		fi
354
		# Create the NanoBSD disk image for i386
355
		if [ "$TARGET" = "i386" -o "$TARGET" = "amd64" ]; then
356
			create_nanobsd_diskimage ${_IMGTOBUILD} "${FLASH_SIZE}"
357
		elif [ "$TARGET" = "mips" ]; then
358
			# Create the NanoBSD disk image for mips
359
			export DEFAULT_KERNEL=${DEFAULT_KERNEL_MIPS:-pfSense_SMP.${FREEBSD_VERSION}}
360
			create_mips_diskimage ${_IMGTOBUILD} ${FLASH_SIZE}
361
		fi
362
	elif [ "${_IMGTOBUILD}" = "ova" ]; then
363
		(create_ova_image)
364
	fi
365
done
366

    
367
echo ">>> NOTE: waiting for jobs: `jobs -l` to finish..."
368
wait
369

    
370
# Email that the operation has completed
371
email_operation_completed
372

    
373
echo ">>> $MAKEOBJDIRPREFIXFINAL now contains:"
374
ls -lah $MAKEOBJDIRPREFIXFINAL
375

    
376
set -e
377
# Run final finish routines
378
finish
(1-1/7)