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 " --nocleanobjdir|--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
|
all|*iso*|*ova*|*memstick*|*memstickserial*|*nanobsd*|*nanobsd-vga*|*fullupdate*)
|
164
|
BUILDACTION="images"
|
165
|
IMAGETYPE="${1}"
|
166
|
;;
|
167
|
*)
|
168
|
usage
|
169
|
esac
|
170
|
shift
|
171
|
done
|
172
|
|
173
|
# Suck in local vars
|
174
|
. ./builder_defaults.sh
|
175
|
|
176
|
_TMPPWD=$(cd .. && basename `pwd`)
|
177
|
if [ "${TOOLS_DIR}" != "${_TMPPWD}" ]; then
|
178
|
echo "ERROR: builder tools checkout on ${_TMPPWD} not the same as TOOLS_DIR=${TOOLS_DIR} setting."
|
179
|
exit 1
|
180
|
fi
|
181
|
unset _TMPPWD
|
182
|
|
183
|
# Suck in script helper functions
|
184
|
. ./builder_common.sh
|
185
|
|
186
|
# Define src.conf
|
187
|
if [ -z "${SRC_CONF:-}" ]; then
|
188
|
export SRC_CONF="${BUILDER_SCRIPTS}/conf/src/src.conf.$FREEBSD_VERSION"
|
189
|
export SRC_CONF_INSTALL="${BUILDER_SCRIPTS}/conf/src/src.conf.$FREEBSD_VERSION.install"
|
190
|
fi
|
191
|
|
192
|
if [ ! -z "${CUSTOM_REMOVE_LIST:-}" ]; then
|
193
|
export PRUNE_LIST="${CUSTOM_REMOVE_LIST:-}"
|
194
|
else
|
195
|
export PRUNE_LIST="${BUILDER_SCRIPTS}/conf/rmlist/remove.list.iso.$FREEBSD_VERSION"
|
196
|
fi
|
197
|
|
198
|
# This should be run first
|
199
|
launch
|
200
|
|
201
|
case $BUILDACTION in
|
202
|
applypatches)
|
203
|
update_freebsd_sources_and_apply_patches
|
204
|
;;
|
205
|
buildpfports)
|
206
|
recompile_pfPorts
|
207
|
;;
|
208
|
buildpfport)
|
209
|
recompile_pfPorts $pfPORTTOBUILD
|
210
|
;;
|
211
|
|
212
|
builderrequiredports)
|
213
|
install_required_builder_system_ports
|
214
|
;;
|
215
|
buildkernels)
|
216
|
update_freebsd_sources_and_apply_patches
|
217
|
build_all_kernels
|
218
|
;;
|
219
|
buildkernel)
|
220
|
update_freebsd_sources_and_apply_patches
|
221
|
build_all_kernels
|
222
|
;;
|
223
|
configure)
|
224
|
./scripts/menu.sh
|
225
|
;;
|
226
|
cleanbuilder)
|
227
|
pfSense_clean_obj_dir
|
228
|
;;
|
229
|
printflags)
|
230
|
print_flags
|
231
|
;;
|
232
|
images)
|
233
|
# It will be handled below
|
234
|
;;
|
235
|
testtweet)
|
236
|
post_tweet "Robots need loving too."
|
237
|
;;
|
238
|
updatesources)
|
239
|
ensure_source_directories_present
|
240
|
;;
|
241
|
enablememorydisk)
|
242
|
prestage_on_ram_setup
|
243
|
;;
|
244
|
disablememorydisk)
|
245
|
prestage_on_ram_cleanup
|
246
|
;;
|
247
|
*)
|
248
|
usage
|
249
|
;;
|
250
|
esac
|
251
|
|
252
|
if [ "${BUILDACTION}" != "images" ]; then
|
253
|
# Email that the operation has completed
|
254
|
email_operation_completed
|
255
|
finish
|
256
|
exit 0
|
257
|
fi
|
258
|
|
259
|
if [ $# -gt 1 ]; then
|
260
|
echo "ERROR: Too many argument given."
|
261
|
echo
|
262
|
usage
|
263
|
fi
|
264
|
if [ -z "${IMAGETYPE}" ]; then
|
265
|
echo "ERROR: Need to specify image type to build."
|
266
|
echo
|
267
|
usage
|
268
|
fi
|
269
|
|
270
|
if [ "$IMAGETYPE" = "all" ]; then
|
271
|
_IMAGESTOBUILD="iso fullupdate nanobsd nanobsd-vga memstick memstickserial"
|
272
|
else
|
273
|
_IMAGESTOBUILD="${IMAGETYPE}"
|
274
|
fi
|
275
|
|
276
|
echo ">>> Building image type(s): ${_IMAGESTOBUILD}"
|
277
|
|
278
|
if [ -z "${_SKIP_REBUILD_PRESTAGE}" ]; then
|
279
|
# Cleanup environment before start
|
280
|
pfSense_clean_obj_dir
|
281
|
|
282
|
# Make sure source directories are present.
|
283
|
ensure_source_directories_present
|
284
|
git_last_commit
|
285
|
|
286
|
# Ensure binaries are present that builder system requires
|
287
|
install_required_builder_system_ports
|
288
|
|
289
|
# Output build flags
|
290
|
print_flags
|
291
|
|
292
|
# Check to see if pre-staging will be hosted on ram
|
293
|
prestage_on_ram_setup
|
294
|
|
295
|
# Build world, kernel and install
|
296
|
echo ">>> Building world for ISO... $FREEBSD_VERSION $FREEBSD_BRANCH ..."
|
297
|
make_world
|
298
|
|
299
|
# Build kernels
|
300
|
echo ">>> Building kernel configs: $BUILD_KERNELS for FreeBSD: $FREEBSD_BRANCH ..."
|
301
|
build_all_kernels
|
302
|
|
303
|
# Prepare pre-final staging area
|
304
|
clone_to_staging_area
|
305
|
|
306
|
# Check if we need to force a ports rebuild
|
307
|
check_for_forced_pfPorts_build
|
308
|
|
309
|
# Install packages needed for livecd
|
310
|
install_pkg_install_ports
|
311
|
|
312
|
# Overlay host binaries
|
313
|
cust_overlay_host_binaries
|
314
|
fi
|
315
|
|
316
|
export DEFAULT_KERNEL=${DEFAULT_KERNEL_ISO:-pfSense_SMP.${FREEBSD_VERSION}}
|
317
|
for _IMGTOBUILD in $_IMAGESTOBUILD; do
|
318
|
# Clean up items that should be cleaned each run
|
319
|
staginareas_clean_each_run
|
320
|
|
321
|
# NOTE: This code is needed to support FreeBSD 8(2.*.*) builds that have extra kernels under /kernels than default
|
322
|
if [ $FREEBSD_VERSION -lt 10 -a -z "${INSTALL_EXTRA_KERNELS}" ]; then
|
323
|
if [ "${_IMGTOBUILD}" = "nanobsd-vga" ]; then
|
324
|
export INSTALL_EXTRA_KERNELS="pfSense_SMP.${FREEBSD_VERSION}"
|
325
|
else
|
326
|
export INSTALL_EXTRA_KERNELS="pfSense_wrap.${FREEBSD_VERSION}.${TARGET}"
|
327
|
fi
|
328
|
fi
|
329
|
|
330
|
if [ "${_IMGTOBUILD}" = "iso" ]; then
|
331
|
(create_iso_image)
|
332
|
elif [ "${_IMGTOBUILD}" = "memstick" ]; then
|
333
|
(create_memstick_image)
|
334
|
elif [ "${_IMGTOBUILD}" = "memstickserial" ]; then
|
335
|
(create_memstick_serial_image)
|
336
|
elif [ "${_IMGTOBUILD}" = "fullupdate" ]; then
|
337
|
create_pfSense_Full_update_tarball
|
338
|
elif [ "${_IMGTOBUILD}" = "nanobsd" -o "${_IMGTOBUILD}" = "nanobsd-vga" ]; then
|
339
|
if [ "${TARGET}" = "i386" -a "${_IMGTOBUILD}" = "nanobsd" ]; then
|
340
|
export DEFAULT_KERNEL=${DEFAULT_KERNEL_NANOBSD:-pfSense_wrap.${FREEBSD_VERSION}.${TARGET}}
|
341
|
elif [ "${TARGET}" = "i386" -a "${_IMGTOBUILD}" = "nanobsd-vga" ]; then
|
342
|
export DEFAULT_KERNEL=${DEFAULT_KERNEL_NANOBSDVGA:-pfSense_wrap_vga.${FREEBSD_VERSION}.${TARGET}}
|
343
|
elif [ "${TARGET}" = "amd64" ]; then
|
344
|
export DEFAULT_KERNEL=${DEFAULT_KERNEL_NANOBSD:-pfSense_SMP.${FREEBSD_VERSION}}
|
345
|
fi
|
346
|
# Create the NanoBSD disk image for i386
|
347
|
if [ "$TARGET" = "i386" -o "$TARGET" = "amd64" ]; then
|
348
|
create_nanobsd_diskimage ${_IMGTOBUILD} "${FLASH_SIZE}"
|
349
|
elif [ "$TARGET" = "mips" ]; then
|
350
|
# Create the NanoBSD disk image for mips
|
351
|
export DEFAULT_KERNEL=${DEFAULT_KERNEL_MIPS:-pfSense_SMP.${FREEBSD_VERSION}}
|
352
|
create_mips_diskimage ${_IMGTOBUILD} ${FLASH_SIZE}
|
353
|
fi
|
354
|
elif [ "${_IMGTOBUILD}" = "ova" ]; then
|
355
|
(create_ova_image)
|
356
|
fi
|
357
|
done
|
358
|
|
359
|
echo ">>> NOTE: waiting for jobs: `jobs -l` to finish..."
|
360
|
wait
|
361
|
|
362
|
# Email that the operation has completed
|
363
|
email_operation_completed
|
364
|
|
365
|
echo ">>> $MAKEOBJDIRPREFIXFINAL now contains:"
|
366
|
ls -lah $MAKEOBJDIRPREFIXFINAL
|
367
|
|
368
|
set -e
|
369
|
# Run final finish routines
|
370
|
finish
|