1
|
#!/bin/sh
|
2
|
#
|
3
|
# build.sh
|
4
|
#
|
5
|
# Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
6
|
#
|
7
|
# Redistribution and use in source and binary forms, with or without
|
8
|
# modification, are permitted provided that the following conditions are met:
|
9
|
#
|
10
|
# 1. Redistributions of source code must retain the above copyright notice,
|
11
|
# this list of conditions and the following disclaimer.
|
12
|
#
|
13
|
# 2. Redistributions in binary form must reproduce the above copyright
|
14
|
# notice, this list of conditions and the following disclaimer in
|
15
|
# the documentation and/or other materials provided with the
|
16
|
# distribution.
|
17
|
#
|
18
|
# 3. All advertising materials mentioning features or use of this software
|
19
|
# must display the following acknowledgment:
|
20
|
# "This product includes software developed by the pfSense Project
|
21
|
# for use in the pfSense® software distribution. (http://www.pfsense.org/).
|
22
|
#
|
23
|
# 4. The names "pfSense" and "pfSense Project" must not be used to
|
24
|
# endorse or promote products derived from this software without
|
25
|
# prior written permission. For written permission, please contact
|
26
|
# coreteam@pfsense.org.
|
27
|
#
|
28
|
# 5. Products derived from this software may not be called "pfSense"
|
29
|
# nor may "pfSense" appear in their names without prior written
|
30
|
# permission of the Electric Sheep Fencing, LLC.
|
31
|
#
|
32
|
# 6. Redistributions of any form whatsoever must retain the following
|
33
|
# acknowledgment:
|
34
|
#
|
35
|
# "This product includes software developed by the pfSense Project
|
36
|
# for use in the pfSense software distribution (http://www.pfsense.org/).
|
37
|
#
|
38
|
# THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
39
|
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
40
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
41
|
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
42
|
# ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
43
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
44
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
45
|
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
46
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
47
|
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
48
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
49
|
# OF THE POSSIBILITY OF SUCH DAMAGE.
|
50
|
#
|
51
|
|
52
|
set +e
|
53
|
usage() {
|
54
|
echo "Usage $0 [options] [ iso | nanobsd | ova | nanobsd-vga | memstick | memstickserial | memstickadi | fullupdate | all ]"
|
55
|
echo " all = iso nanobsd nanobsd-vga memstick memstickserial memstickadi fullupdate"
|
56
|
echo " [ options ]: "
|
57
|
echo " --flash-size|-f size(s) - a list of flash sizes to build with nanobsd i.e. '2g 4g'. Default: 2g"
|
58
|
echo " --no-buildworld|-c - Will set NO_BUILDWORLD NO_BUILDKERNEL to not build kernel and world"
|
59
|
echo " --no-cleanobjdir|--no-cleanrepos|-d - Will not clean FreeBSD object built dir to allow restarting a build with NO_CLEAN"
|
60
|
echo " --resume-image-build|-r - Includes -c -d and also will just move directly to image creation using pre-staged data"
|
61
|
echo " --setup - Install required repo and ports builder require to work"
|
62
|
echo " --update-sources - Refetch FreeBSD sources"
|
63
|
echo " --print-flags - Show current builder configuration"
|
64
|
echo " --clean-builder - clean all builder used data/resources"
|
65
|
echo " --build-kernels - build all configured kernels"
|
66
|
echo " --build-kernel argument - build specified kernel. Example --build-kernel KERNEL_NAME"
|
67
|
echo " --install-extra-kernels argument - Put extra kernel(s) under /kernel image directory. Example --install-extra-kernels KERNEL_NAME_WRAP"
|
68
|
echo " --snapshots - Build snapshots and upload them to RSYNCIP"
|
69
|
echo " --poudriere-snapshots - Update poudriere packages and send them to PKG_RSYNC_HOSTNAME"
|
70
|
echo " --enable-memorydisks - This will put stage_dir and iso_dir as MFS filesystems"
|
71
|
echo " --disable-memorydisks - Will just teardown these filesystems created by --enable-memorydisks"
|
72
|
echo " --setup-poudriere - Install poudriere and create necessary jails and ports tree"
|
73
|
echo " --create-unified-patch - Create a big patch with all changes done on FreeBSD"
|
74
|
echo " --update-poudriere-jails [-a ARCH_LIST] - Update poudriere jails using current patch versions"
|
75
|
echo " --update-poudriere-ports [-a ARCH_LIST]- Update poudriere ports tree"
|
76
|
echo " --update-pkg-repo [-a ARCH_LIST]- Rebuild necessary ports on poudriere and update pkg repo"
|
77
|
echo " --do-not-upload|-u - Do not upload pkgs or snapshots"
|
78
|
echo " -V VARNAME - print value of variable VARNAME"
|
79
|
exit 1
|
80
|
}
|
81
|
|
82
|
export BUILDER_ROOT=$(realpath $(dirname ${0}))
|
83
|
export BUILDER_TOOLS="${BUILDER_ROOT}/tools"
|
84
|
|
85
|
unset _SKIP_REBUILD_PRESTAGE
|
86
|
unset _USE_OLD_DATESTRING
|
87
|
unset pfPORTTOBUILD
|
88
|
unset IMAGETYPE
|
89
|
unset DO_NOT_UPLOAD
|
90
|
unset SNAPSHOTS
|
91
|
unset POUDRIERE_SNAPSHOTS
|
92
|
unset ARCH_LIST
|
93
|
BUILDACTION="images"
|
94
|
|
95
|
# Maybe use options for nocleans etc?
|
96
|
while test "$1" != ""; do
|
97
|
case "${1}" in
|
98
|
--no-buildworld|-c)
|
99
|
export NO_BUILDWORLD=YES
|
100
|
export NO_BUILDKERNEL=YES
|
101
|
;;
|
102
|
--no-cleanobjdir|--no-cleanrepos|-d)
|
103
|
export NO_CLEAN_FREEBSD_OBJ=YES
|
104
|
export NO_CLEAN_FREEBSD_SRC=YES
|
105
|
;;
|
106
|
--flash-size|-f)
|
107
|
shift
|
108
|
if [ $# -eq 0 ]; then
|
109
|
echo "--flash-size needs extra parameter."
|
110
|
echo
|
111
|
usage
|
112
|
fi
|
113
|
export FLASH_SIZE="${1}"
|
114
|
;;
|
115
|
--resume-image-build|-r)
|
116
|
export NO_BUILDWORLD=YES
|
117
|
export NO_BUILDKERNEL=YES
|
118
|
export NO_CLEAN_FREEBSD_OBJ=YES
|
119
|
export NO_CLEAN_FREEBSD_SRC=YES
|
120
|
_SKIP_REBUILD_PRESTAGE=YES
|
121
|
_USE_OLD_DATESTRING=YES
|
122
|
;;
|
123
|
--setup)
|
124
|
BUILDACTION="builder_setup"
|
125
|
;;
|
126
|
--build-kernels)
|
127
|
BUILDACTION="buildkernels"
|
128
|
;;
|
129
|
--install-extra-kernels)
|
130
|
shift
|
131
|
if [ $# -eq 0 ]; then
|
132
|
echo "--build-kernel needs extra parameter."
|
133
|
echo
|
134
|
usage
|
135
|
fi
|
136
|
export INSTALL_EXTRA_KERNELS="${1}"
|
137
|
;;
|
138
|
--snapshots)
|
139
|
export SNAPSHOTS=1
|
140
|
IMAGETYPE="all"
|
141
|
;;
|
142
|
--poudriere-snapshots)
|
143
|
export POUDRIERE_SNAPSHOTS=1
|
144
|
;;
|
145
|
--build-kernel)
|
146
|
BUILDACTION="buildkernel"
|
147
|
shift
|
148
|
if [ $# -eq 0 ]; then
|
149
|
echo "--build-kernel needs extra parameter."
|
150
|
echo
|
151
|
usage
|
152
|
fi
|
153
|
export BUILD_KERNELS="${1}"
|
154
|
;;
|
155
|
--update-sources)
|
156
|
BUILDACTION="updatesources"
|
157
|
;;
|
158
|
--print-flags)
|
159
|
BUILDACTION="printflags"
|
160
|
;;
|
161
|
--clean-builder)
|
162
|
BUILDACTION="cleanbuilder"
|
163
|
;;
|
164
|
--enable-memorydisks)
|
165
|
BUILDACTION="enablememorydisk"
|
166
|
;;
|
167
|
--disable-memorydisks)
|
168
|
BUILDACTION="disablememorydisk"
|
169
|
;;
|
170
|
--setup-poudriere)
|
171
|
BUILDACTION="setup_poudriere"
|
172
|
;;
|
173
|
--create-unified-patch)
|
174
|
BUILDACTION="create_unified_patch"
|
175
|
;;
|
176
|
--update-poudriere-jails)
|
177
|
BUILDACTION="update_poudriere_jails"
|
178
|
;;
|
179
|
-a)
|
180
|
shift
|
181
|
if [ $# -eq 0 ]; then
|
182
|
echo "-a needs extra parameter."
|
183
|
echo
|
184
|
usage
|
185
|
fi
|
186
|
export ARCH_LIST="${1}"
|
187
|
;;
|
188
|
--update-poudriere-ports)
|
189
|
BUILDACTION="update_poudriere_ports"
|
190
|
;;
|
191
|
--update-pkg-repo)
|
192
|
BUILDACTION="update_pkg_repo"
|
193
|
;;
|
194
|
--do-not-upload|-u)
|
195
|
export DO_NOT_UPLOAD=1
|
196
|
;;
|
197
|
all|*iso*|*ova*|*memstick*|*memstickserial*|*memstickadi*|*nanobsd*|*nanobsd-vga*|*fullupdate*)
|
198
|
BUILDACTION="images"
|
199
|
IMAGETYPE="${1}"
|
200
|
;;
|
201
|
-V)
|
202
|
shift
|
203
|
[ -n "${1}" ] \
|
204
|
&& var_to_print="${1}"
|
205
|
;;
|
206
|
--snapshot-update-status)
|
207
|
shift
|
208
|
snapshot_status_message="${1}"
|
209
|
BUILDACTION="snapshot_status_message"
|
210
|
;;
|
211
|
*)
|
212
|
usage
|
213
|
esac
|
214
|
shift
|
215
|
done
|
216
|
|
217
|
# Suck in local vars
|
218
|
. ${BUILDER_TOOLS}/builder_defaults.sh
|
219
|
|
220
|
# Suck in script helper functions
|
221
|
. ${BUILDER_TOOLS}/builder_common.sh
|
222
|
|
223
|
# Print var required with -V and exit
|
224
|
if [ -n "${var_to_print}" ]; then
|
225
|
eval "echo \$${var_to_print}"
|
226
|
exit 0
|
227
|
fi
|
228
|
|
229
|
# Update snapshot status and exit
|
230
|
if [ "${BUILDACTION}" = "snapshot_status_message" ]; then
|
231
|
if [ -z "${POUDRIERE_SNAPSHOTS}" ]; then
|
232
|
export SNAPSHOTS=1
|
233
|
fi
|
234
|
snapshots_update_status "${snapshot_status_message}"
|
235
|
exit 0
|
236
|
fi
|
237
|
|
238
|
# This should be run first
|
239
|
launch
|
240
|
|
241
|
case $BUILDACTION in
|
242
|
builder_setup)
|
243
|
builder_setup
|
244
|
;;
|
245
|
buildkernels)
|
246
|
update_freebsd_sources
|
247
|
build_all_kernels
|
248
|
;;
|
249
|
buildkernel)
|
250
|
update_freebsd_sources
|
251
|
build_all_kernels
|
252
|
;;
|
253
|
cleanbuilder)
|
254
|
clean_builder
|
255
|
;;
|
256
|
printflags)
|
257
|
print_flags
|
258
|
;;
|
259
|
images|snapshots)
|
260
|
# It will be handled below
|
261
|
;;
|
262
|
updatesources)
|
263
|
update_freebsd_sources
|
264
|
;;
|
265
|
enablememorydisk)
|
266
|
prestage_on_ram_setup
|
267
|
;;
|
268
|
disablememorydisk)
|
269
|
prestage_on_ram_cleanup
|
270
|
;;
|
271
|
setup_poudriere)
|
272
|
poudriere_init
|
273
|
;;
|
274
|
create_unified_patch)
|
275
|
poudriere_create_patch
|
276
|
;;
|
277
|
update_poudriere_jails)
|
278
|
poudriere_update_jails
|
279
|
;;
|
280
|
update_poudriere_ports)
|
281
|
poudriere_update_ports
|
282
|
;;
|
283
|
update_pkg_repo)
|
284
|
if [ -z "${DO_NOT_UPLOAD}" -a ! -f /usr/local/bin/rsync ]; then
|
285
|
echo "ERROR: rsync is not installed, aborting..."
|
286
|
exit 1
|
287
|
fi
|
288
|
poudriere_bulk
|
289
|
;;
|
290
|
*)
|
291
|
usage
|
292
|
;;
|
293
|
esac
|
294
|
|
295
|
if [ "${BUILDACTION}" != "images" ]; then
|
296
|
finish
|
297
|
exit 0
|
298
|
fi
|
299
|
|
300
|
if [ -n "${SNAPSHOTS}" -a -z "${DO_NOT_UPLOAD}" ]; then
|
301
|
_required=" \
|
302
|
RSYNCIP \
|
303
|
RSYNCUSER \
|
304
|
RSYNCPATH \
|
305
|
RSYNCLOGS \
|
306
|
PKG_RSYNC_HOSTNAME \
|
307
|
PKG_RSYNC_USERNAME \
|
308
|
PKG_RSYNC_SSH_PORT \
|
309
|
PKG_RSYNC_DESTDIR \
|
310
|
PKG_REPO_SERVER \
|
311
|
PKG_REPO_CONF_BRANCH"
|
312
|
|
313
|
for _var in ${_required}; do
|
314
|
eval "_value=\${$_var}"
|
315
|
if [ -z "${_value}" ]; then
|
316
|
echo ">>> ERROR: ${_var} is not defined"
|
317
|
exit 1
|
318
|
fi
|
319
|
done
|
320
|
|
321
|
if [ ! -f /usr/local/bin/rsync ]; then
|
322
|
echo "ERROR: rsync is not installed, aborting..."
|
323
|
exit 1
|
324
|
fi
|
325
|
fi
|
326
|
|
327
|
if [ $# -gt 1 ]; then
|
328
|
echo "ERROR: Too many arguments given."
|
329
|
echo
|
330
|
usage
|
331
|
fi
|
332
|
if [ -z "${IMAGETYPE}" ]; then
|
333
|
echo "ERROR: Need to specify image type to build."
|
334
|
echo
|
335
|
usage
|
336
|
fi
|
337
|
|
338
|
if [ "$IMAGETYPE" = "all" ]; then
|
339
|
_IMAGESTOBUILD="iso fullupdate nanobsd nanobsd-vga memstick memstickserial"
|
340
|
if [ "${TARGET}" = "amd64" ]; then
|
341
|
_IMAGESTOBUILD="${_IMAGESTOBUILD} memstickadi"
|
342
|
fi
|
343
|
else
|
344
|
_IMAGESTOBUILD="${IMAGETYPE}"
|
345
|
fi
|
346
|
|
347
|
echo ">>> Building image type(s): ${_IMAGESTOBUILD}"
|
348
|
|
349
|
if [ -n "${SNAPSHOTS}" ]; then
|
350
|
snapshots_rotate_logfile
|
351
|
|
352
|
snapshots_update_status ">>> Starting snapshot build operations"
|
353
|
|
354
|
if pkg update -r ${PRODUCT_NAME} >/dev/null 2>&1; then
|
355
|
snapshots_update_status ">>> Updating builder packages... "
|
356
|
pkg upgrade -r ${PRODUCT_NAME} -y -q >/dev/null 2>&1
|
357
|
fi
|
358
|
fi
|
359
|
|
360
|
if [ -z "${_SKIP_REBUILD_PRESTAGE}" ]; then
|
361
|
[ -n "${CORE_PKG_TMP}" -a -d "${CORE_PKG_TMP}" ] \
|
362
|
&& rm -rf ${CORE_PKG_TMP}
|
363
|
[ -n "${CORE_PKG_PATH}" -a -d "${CORE_PKG_PATH}" ] \
|
364
|
&& rm -rf ${CORE_PKG_PATH}
|
365
|
|
366
|
# Cleanup environment before start
|
367
|
clean_builder
|
368
|
|
369
|
# Make sure source directories are present.
|
370
|
update_freebsd_sources
|
371
|
git_last_commit
|
372
|
|
373
|
# Ensure binaries are present that builder system requires
|
374
|
builder_setup
|
375
|
|
376
|
# Output build flags
|
377
|
print_flags
|
378
|
|
379
|
# Check to see if pre-staging will be hosted on ram
|
380
|
prestage_on_ram_setup
|
381
|
|
382
|
# Build world, kernel and install
|
383
|
echo ">>> Building world for ISO... $FREEBSD_BRANCH ..."
|
384
|
make_world
|
385
|
|
386
|
# Build kernels
|
387
|
echo ">>> Building kernel configs: $BUILD_KERNELS for FreeBSD: $FREEBSD_BRANCH ..."
|
388
|
build_all_kernels
|
389
|
|
390
|
# Prepare pre-final staging area
|
391
|
clone_to_staging_area
|
392
|
|
393
|
# Install packages needed for Product
|
394
|
install_pkg_install_ports
|
395
|
fi
|
396
|
|
397
|
export DEFAULT_KERNEL=${DEFAULT_KERNEL_ISO:-"${PRODUCT_NAME}"}
|
398
|
|
399
|
# XXX: Figure out why wait is failing and proper fix
|
400
|
# Global variable to keep track of process running in bg
|
401
|
export _bg_pids=""
|
402
|
|
403
|
for _IMGTOBUILD in $_IMAGESTOBUILD; do
|
404
|
# Clean up items that should be cleaned each run
|
405
|
staginareas_clean_each_run
|
406
|
|
407
|
if [ "${_IMGTOBUILD}" = "iso" ]; then
|
408
|
create_iso_image
|
409
|
elif [ "${_IMGTOBUILD}" = "memstick" ]; then
|
410
|
create_memstick_image
|
411
|
elif [ "${_IMGTOBUILD}" = "memstickserial" ]; then
|
412
|
create_memstick_serial_image
|
413
|
elif [ "${_IMGTOBUILD}" = "memstickadi" ]; then
|
414
|
create_memstick_adi_image
|
415
|
elif [ "${_IMGTOBUILD}" = "fullupdate" ]; then
|
416
|
create_Full_update_tarball
|
417
|
elif [ "${_IMGTOBUILD}" = "nanobsd" -o "${_IMGTOBUILD}" = "nanobsd-vga" ]; then
|
418
|
if [ "${TARGET}" = "i386" -a "${_IMGTOBUILD}" = "nanobsd" ]; then
|
419
|
export DEFAULT_KERNEL=${DEFAULT_KERNEL_NANOBSD:-"${PRODUCT_NAME}_wrap"}
|
420
|
elif [ "${TARGET}" = "i386" -a "${_IMGTOBUILD}" = "nanobsd-vga" ]; then
|
421
|
export DEFAULT_KERNEL=${DEFAULT_KERNEL_NANOBSDVGA:-"${PRODUCT_NAME}_wrap_vga"}
|
422
|
elif [ "${TARGET}" = "amd64" ]; then
|
423
|
export DEFAULT_KERNEL=${DEFAULT_KERNEL_NANOBSD:-"${PRODUCT_NAME}"}
|
424
|
fi
|
425
|
# Create the NanoBSD disk image
|
426
|
create_nanobsd_diskimage ${_IMGTOBUILD} "${FLASH_SIZE}"
|
427
|
elif [ "${_IMGTOBUILD}" = "ova" ]; then
|
428
|
install_pkg_install_ports ${PRODUCT_NAME}-vmware
|
429
|
create_ova_image
|
430
|
install_pkg_install_ports
|
431
|
fi
|
432
|
done
|
433
|
|
434
|
core_pkg_create_repo
|
435
|
|
436
|
if [ -n "${_bg_pids}" ]; then
|
437
|
if [ -n "${SNAPSHOTS}" ]; then
|
438
|
snapshots_update_status ">>> NOTE: waiting for jobs: ${_bg_pids} to finish..."
|
439
|
else
|
440
|
echo ">>> NOTE: waiting for jobs: ${_bg_pids} to finish..."
|
441
|
fi
|
442
|
wait
|
443
|
|
444
|
# XXX: For some reason wait is failing, workaround it tracking all PIDs
|
445
|
while [ -n "${_bg_pids}" ]; do
|
446
|
_tmp_pids="${_bg_pids}"
|
447
|
unset _bg_pids
|
448
|
for p in ${_tmp_pids}; do
|
449
|
[ -z "${p}" ] \
|
450
|
&& continue
|
451
|
|
452
|
kill -0 ${p} >/dev/null 2>&1 \
|
453
|
&& _bg_pids="${_bg_pids}${_bg_pids:+ }${p}"
|
454
|
done
|
455
|
[ -n "${_bg_pids}" ] \
|
456
|
&& sleep 1
|
457
|
done
|
458
|
fi
|
459
|
|
460
|
if [ -n "${SNAPSHOTS}" ]; then
|
461
|
snapshots_copy_to_staging_iso_updates
|
462
|
snapshots_copy_to_staging_nanobsd "${FLASH_SIZE}"
|
463
|
# SCP files to snapshot web hosting area
|
464
|
if [ -z "${DO_NOT_UPLOAD}" ]; then
|
465
|
snapshots_scp_files
|
466
|
fi
|
467
|
# Alert the world that we have some snapshots ready.
|
468
|
snapshots_update_status ">>> Builder run is complete."
|
469
|
fi
|
470
|
|
471
|
echo ">>> ${IMAGES_FINAL_DIR} now contains:"
|
472
|
ls -lah ${IMAGES_FINAL_DIR}
|
473
|
|
474
|
set -e
|
475
|
# Run final finish routines
|
476
|
finish
|