1
|
#!/bin/sh
|
2
|
#
|
3
|
# build.sh
|
4
|
#
|
5
|
# part of pfSense (https://www.pfsense.org)
|
6
|
# Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
|
7
|
# All rights reserved.
|
8
|
#
|
9
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
# you may not use this file except in compliance with the License.
|
11
|
# You may obtain a copy of the License at
|
12
|
#
|
13
|
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
#
|
15
|
# Unless required by applicable law or agreed to in writing, software
|
16
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
# See the License for the specific language governing permissions and
|
19
|
# limitations under the License.
|
20
|
|
21
|
set +e
|
22
|
usage() {
|
23
|
echo "Usage $0 [options] [ iso | ova | memstick | memstickserial | memstickadi | all | none ]"
|
24
|
echo " all = iso memstick memstickserial memstickadi"
|
25
|
echo " none = upgrade only pkg repo"
|
26
|
echo " [ options ]: "
|
27
|
echo " --no-buildworld|-c - Will set NO_BUILDWORLD NO_BUILDKERNEL to not build kernel and world"
|
28
|
echo " --no-cleanobjdir|-d - Will not clean FreeBSD object built dir to allow restarting a build with NO_CLEAN"
|
29
|
echo " --resume-image-build|-r - Includes -c -d and also will just move directly to image creation using pre-staged data"
|
30
|
echo " --setup - Install required repo and ports builder require to work"
|
31
|
echo " --update-sources - Refetch FreeBSD sources"
|
32
|
echo " --rsync-repos - rsync pkg repos"
|
33
|
echo " --rsync-snapshots - rsync snapshots images and pkg repos"
|
34
|
echo " --clean-builder - clean all builder used data/resources"
|
35
|
echo " --build-kernels - build all configured kernels"
|
36
|
echo " --build-kernel argument - build specified kernel. Example --build-kernel KERNEL_NAME"
|
37
|
echo " --install-extra-kernels argument - Put extra kernel(s) under /kernel image directory. Example --install-extra-kernels KERNEL_NAME_WRAP"
|
38
|
echo " --snapshots - Build snapshots"
|
39
|
echo " --poudriere-snapshots - Update poudriere packages and send them to PKG_RSYNC_HOSTNAME"
|
40
|
echo " --setup-poudriere - Install poudriere and create necessary jails and ports tree"
|
41
|
echo " --create-unified-patch - Create a big patch with all changes done on FreeBSD"
|
42
|
echo " --update-poudriere-jails [-a ARCH_LIST] - Update poudriere jails using current patch versions"
|
43
|
echo " --update-poudriere-ports [-a ARCH_LIST]- Update poudriere ports tree"
|
44
|
echo " --update-pkg-repo [-a ARCH_LIST]- Rebuild necessary ports on poudriere and update pkg repo"
|
45
|
echo " --upload|-U - Upload pkgs and/or snapshots"
|
46
|
echo " -V VARNAME - print value of variable VARNAME"
|
47
|
exit 1
|
48
|
}
|
49
|
|
50
|
export BUILDER_ROOT=$(realpath $(dirname ${0}))
|
51
|
export BUILDER_TOOLS="${BUILDER_ROOT}/tools"
|
52
|
|
53
|
unset _SKIP_REBUILD_PRESTAGE
|
54
|
unset _USE_OLD_DATESTRING
|
55
|
unset pfPORTTOBUILD
|
56
|
unset IMAGETYPE
|
57
|
unset UPLOAD
|
58
|
unset SNAPSHOTS
|
59
|
unset POUDRIERE_SNAPSHOTS
|
60
|
unset ARCH_LIST
|
61
|
BUILDACTION="images"
|
62
|
|
63
|
# Maybe use options for nocleans etc?
|
64
|
while test "$1" != ""; do
|
65
|
case "${1}" in
|
66
|
--no-buildworld|-c)
|
67
|
export NO_BUILDWORLD=YES
|
68
|
export NO_BUILDKERNEL=YES
|
69
|
;;
|
70
|
--no-cleanobjdir|-d)
|
71
|
export NO_CLEAN_FREEBSD_OBJ=YES
|
72
|
;;
|
73
|
--resume-image-build|-r)
|
74
|
export NO_BUILDWORLD=YES
|
75
|
export NO_BUILDKERNEL=YES
|
76
|
export NO_CLEAN_FREEBSD_OBJ=YES
|
77
|
export DO_NOT_SIGN_PKG_REPO=YES
|
78
|
_SKIP_REBUILD_PRESTAGE=YES
|
79
|
_USE_OLD_DATESTRING=YES
|
80
|
;;
|
81
|
--setup)
|
82
|
BUILDACTION="builder_setup"
|
83
|
;;
|
84
|
--rsync-repos)
|
85
|
BUILDACTION="rsync_repos"
|
86
|
export DO_NOT_SIGN_PKG_REPO=YES
|
87
|
;;
|
88
|
--rsync-snapshots)
|
89
|
BUILDACTION="rsync_snapshots"
|
90
|
export DO_NOT_SIGN_PKG_REPO=YES
|
91
|
;;
|
92
|
--build-kernels)
|
93
|
BUILDACTION="buildkernels"
|
94
|
;;
|
95
|
--install-extra-kernels)
|
96
|
shift
|
97
|
if [ $# -eq 0 ]; then
|
98
|
echo "--build-kernel needs extra parameter."
|
99
|
echo
|
100
|
usage
|
101
|
fi
|
102
|
export INSTALL_EXTRA_KERNELS="${1}"
|
103
|
;;
|
104
|
--snapshots)
|
105
|
export SNAPSHOTS=1
|
106
|
;;
|
107
|
--poudriere-snapshots)
|
108
|
export POUDRIERE_SNAPSHOTS=1
|
109
|
;;
|
110
|
--build-kernel)
|
111
|
BUILDACTION="buildkernel"
|
112
|
shift
|
113
|
if [ $# -eq 0 ]; then
|
114
|
echo "--build-kernel needs extra parameter."
|
115
|
echo
|
116
|
usage
|
117
|
fi
|
118
|
export BUILD_KERNELS="${1}"
|
119
|
;;
|
120
|
--update-sources)
|
121
|
BUILDACTION="updatesources"
|
122
|
;;
|
123
|
--clean-builder)
|
124
|
BUILDACTION="cleanbuilder"
|
125
|
;;
|
126
|
--setup-poudriere)
|
127
|
BUILDACTION="setup_poudriere"
|
128
|
;;
|
129
|
--create-unified-patch)
|
130
|
BUILDACTION="create_unified_patch"
|
131
|
;;
|
132
|
--update-poudriere-jails)
|
133
|
BUILDACTION="update_poudriere_jails"
|
134
|
;;
|
135
|
-a)
|
136
|
shift
|
137
|
if [ $# -eq 0 ]; then
|
138
|
echo "-a needs extra parameter."
|
139
|
echo
|
140
|
usage
|
141
|
fi
|
142
|
export ARCH_LIST="${1}"
|
143
|
;;
|
144
|
--update-poudriere-ports)
|
145
|
BUILDACTION="update_poudriere_ports"
|
146
|
;;
|
147
|
--update-pkg-repo)
|
148
|
BUILDACTION="update_pkg_repo"
|
149
|
;;
|
150
|
--upload|-U)
|
151
|
export UPLOAD=1
|
152
|
;;
|
153
|
all|none|*iso*|*ova*|*memstick*|*memstickserial*|*memstickadi*)
|
154
|
BUILDACTION="images"
|
155
|
IMAGETYPE="${1}"
|
156
|
;;
|
157
|
-V)
|
158
|
_USE_OLD_DATESTRING=YES
|
159
|
shift
|
160
|
[ -n "${1}" ] \
|
161
|
&& var_to_print="${1}"
|
162
|
;;
|
163
|
--snapshot-update-status)
|
164
|
shift
|
165
|
snapshot_status_message="${1}"
|
166
|
BUILDACTION="snapshot_status_message"
|
167
|
_USE_OLD_DATESTRING=YES
|
168
|
;;
|
169
|
*)
|
170
|
_USE_OLD_DATESTRING=YES
|
171
|
usage
|
172
|
esac
|
173
|
shift
|
174
|
done
|
175
|
|
176
|
# Suck in local vars
|
177
|
. ${BUILDER_TOOLS}/builder_defaults.sh
|
178
|
|
179
|
# Let user define ARCH_LIST in build.conf
|
180
|
[ -z "${ARCH_LIST}" -a -n "${DEFAULT_ARCH_LIST}" ] \
|
181
|
&& ARCH_LIST="${DEFAULT_ARCH_LIST}"
|
182
|
|
183
|
# Suck in script helper functions
|
184
|
. ${BUILDER_TOOLS}/builder_common.sh
|
185
|
|
186
|
# Print var required with -V and exit
|
187
|
if [ -n "${var_to_print}" ]; then
|
188
|
eval "echo \$${var_to_print}"
|
189
|
exit 0
|
190
|
fi
|
191
|
|
192
|
# Update snapshot status and exit
|
193
|
if [ "${BUILDACTION}" = "snapshot_status_message" ]; then
|
194
|
if [ -z "${POUDRIERE_SNAPSHOTS}" ]; then
|
195
|
export SNAPSHOTS=1
|
196
|
fi
|
197
|
snapshots_update_status "${snapshot_status_message}"
|
198
|
exit 0
|
199
|
fi
|
200
|
|
201
|
# This should be run first
|
202
|
launch
|
203
|
|
204
|
case $BUILDACTION in
|
205
|
builder_setup)
|
206
|
builder_setup
|
207
|
;;
|
208
|
buildkernels)
|
209
|
update_freebsd_sources
|
210
|
build_all_kernels
|
211
|
;;
|
212
|
buildkernel)
|
213
|
update_freebsd_sources
|
214
|
build_all_kernels
|
215
|
;;
|
216
|
cleanbuilder)
|
217
|
clean_builder
|
218
|
;;
|
219
|
images)
|
220
|
# It will be handled below
|
221
|
;;
|
222
|
updatesources)
|
223
|
update_freebsd_sources
|
224
|
;;
|
225
|
setup_poudriere)
|
226
|
poudriere_init
|
227
|
;;
|
228
|
create_unified_patch)
|
229
|
poudriere_create_patch
|
230
|
;;
|
231
|
update_poudriere_jails)
|
232
|
poudriere_update_jails
|
233
|
;;
|
234
|
update_poudriere_ports)
|
235
|
poudriere_update_ports
|
236
|
;;
|
237
|
rsync_repos)
|
238
|
export UPLOAD=1
|
239
|
pkg_repo_rsync "${CORE_PKG_PATH}"
|
240
|
;;
|
241
|
rsync_snapshots)
|
242
|
export UPLOAD=1
|
243
|
snapshots_scp_files
|
244
|
;;
|
245
|
update_pkg_repo)
|
246
|
if [ -n "${UPLOAD}" -a ! -f /usr/local/bin/rsync ]; then
|
247
|
echo "ERROR: rsync is not installed, aborting..."
|
248
|
exit 1
|
249
|
fi
|
250
|
poudriere_bulk
|
251
|
;;
|
252
|
*)
|
253
|
usage
|
254
|
;;
|
255
|
esac
|
256
|
|
257
|
if [ "${BUILDACTION}" != "images" ]; then
|
258
|
finish
|
259
|
exit 0
|
260
|
fi
|
261
|
|
262
|
if [ -n "${SNAPSHOTS}" -a -n "${UPLOAD}" ]; then
|
263
|
_required=" \
|
264
|
RSYNCIP \
|
265
|
RSYNCUSER \
|
266
|
RSYNCPATH \
|
267
|
PKG_RSYNC_HOSTNAME \
|
268
|
PKG_RSYNC_USERNAME \
|
269
|
PKG_RSYNC_SSH_PORT \
|
270
|
PKG_RSYNC_DESTDIR \
|
271
|
PKG_REPO_SERVER_DEVEL \
|
272
|
PKG_REPO_SERVER_RELEASE \
|
273
|
PKG_REPO_SERVER_STAGING \
|
274
|
PKG_REPO_BRANCH_DEVEL \
|
275
|
PKG_REPO_BRANCH_RELEASE"
|
276
|
|
277
|
for _var in ${_required}; do
|
278
|
eval "_value=\${$_var}"
|
279
|
if [ -z "${_value}" ]; then
|
280
|
echo ">>> ERROR: ${_var} is not defined"
|
281
|
exit 1
|
282
|
fi
|
283
|
done
|
284
|
|
285
|
if [ ! -f /usr/local/bin/rsync ]; then
|
286
|
echo "ERROR: rsync is not installed, aborting..."
|
287
|
exit 1
|
288
|
fi
|
289
|
fi
|
290
|
|
291
|
if [ $# -gt 1 ]; then
|
292
|
echo "ERROR: Too many arguments given."
|
293
|
echo
|
294
|
usage
|
295
|
fi
|
296
|
|
297
|
if [ -n "${SNAPSHOTS}" -a -z "${IMAGETYPE}" ]; then
|
298
|
IMAGETYPE="all"
|
299
|
fi
|
300
|
|
301
|
if [ -z "${IMAGETYPE}" ]; then
|
302
|
echo "ERROR: Need to specify image type to build."
|
303
|
echo
|
304
|
usage
|
305
|
fi
|
306
|
|
307
|
if [ "$IMAGETYPE" = "none" ]; then
|
308
|
_IMAGESTOBUILD=""
|
309
|
elif [ "$IMAGETYPE" = "all" ]; then
|
310
|
_IMAGESTOBUILD="iso memstick memstickserial"
|
311
|
if [ "${TARGET}" = "amd64" ]; then
|
312
|
_IMAGESTOBUILD="${_IMAGESTOBUILD} memstickadi"
|
313
|
if [ -n "${_IS_RELEASE}" ]; then
|
314
|
_IMAGESTOBUILD="${_IMAGESTOBUILD} ova"
|
315
|
fi
|
316
|
fi
|
317
|
else
|
318
|
_IMAGESTOBUILD="${IMAGETYPE}"
|
319
|
fi
|
320
|
|
321
|
echo ">>> Building image type(s): ${_IMAGESTOBUILD}"
|
322
|
|
323
|
if [ -n "${SNAPSHOTS}" ]; then
|
324
|
snapshots_update_status ">>> Starting snapshot build operations"
|
325
|
|
326
|
if pkg update -r ${PRODUCT_NAME} >/dev/null 2>&1; then
|
327
|
snapshots_update_status ">>> Updating builder packages... "
|
328
|
pkg upgrade -r ${PRODUCT_NAME} -y -q >/dev/null 2>&1
|
329
|
fi
|
330
|
fi
|
331
|
|
332
|
if [ -z "${_SKIP_REBUILD_PRESTAGE}" ]; then
|
333
|
[ -n "${CORE_PKG_PATH}" -a -d "${CORE_PKG_PATH}" ] \
|
334
|
&& rm -rf ${CORE_PKG_PATH}
|
335
|
|
336
|
# Cleanup environment before start
|
337
|
clean_builder
|
338
|
|
339
|
# Make sure source directories are present.
|
340
|
update_freebsd_sources
|
341
|
git_last_commit
|
342
|
|
343
|
# Ensure binaries are present that builder system requires
|
344
|
builder_setup
|
345
|
|
346
|
# Build world, kernel and install
|
347
|
make_world
|
348
|
|
349
|
# Build kernels
|
350
|
build_all_kernels
|
351
|
|
352
|
# Install kernel on installer
|
353
|
installkernel ${INSTALLER_CHROOT_DIR} ${PRODUCT_NAME}
|
354
|
|
355
|
# Prepare pre-final staging area
|
356
|
clone_to_staging_area
|
357
|
|
358
|
# Install packages needed for Product
|
359
|
install_pkg_install_ports
|
360
|
|
361
|
# Create core repo
|
362
|
core_pkg_create_repo
|
363
|
fi
|
364
|
|
365
|
# Send core repo to staging area
|
366
|
pkg_repo_rsync "${CORE_PKG_PATH}" ignore_final_rsync
|
367
|
|
368
|
export DEFAULT_KERNEL=${DEFAULT_KERNEL_ISO:-"${PRODUCT_NAME}"}
|
369
|
|
370
|
# XXX: Figure out why wait is failing and proper fix
|
371
|
# Global variable to keep track of process running in bg
|
372
|
export _bg_pids=""
|
373
|
|
374
|
for _IMGTOBUILD in $_IMAGESTOBUILD; do
|
375
|
# Clean up items that should be cleaned each run
|
376
|
staginareas_clean_each_run
|
377
|
|
378
|
case "${_IMGTOBUILD}" in
|
379
|
iso)
|
380
|
if [ -n "${ISO_VARIANTS}" ]; then
|
381
|
for _variant in ${ISO_VARIANTS}; do
|
382
|
create_iso_image ${_variant}
|
383
|
done
|
384
|
else
|
385
|
create_iso_image
|
386
|
fi
|
387
|
;;
|
388
|
memstick)
|
389
|
if [ -n "${MEMSTICK_VARIANTS}" ]; then
|
390
|
for _variant in ${MEMSTICK_VARIANTS}; do
|
391
|
create_memstick_image ${_variant}
|
392
|
done
|
393
|
else
|
394
|
create_memstick_image
|
395
|
fi
|
396
|
;;
|
397
|
memstickserial)
|
398
|
create_memstick_serial_image
|
399
|
;;
|
400
|
memstickadi)
|
401
|
create_memstick_adi_image
|
402
|
;;
|
403
|
ova)
|
404
|
old_custom_package_list="${custom_package_list}"
|
405
|
export custom_package_list="${custom_package_list} ${PRODUCT_NAME}-pkg-Open-VM-Tools"
|
406
|
install_pkg_install_ports
|
407
|
create_ova_image
|
408
|
export custom_package_list="${old_custom_package_list}"
|
409
|
install_pkg_install_ports
|
410
|
;;
|
411
|
esac
|
412
|
done
|
413
|
|
414
|
if [ -n "${_bg_pids}" ]; then
|
415
|
if [ -n "${SNAPSHOTS}" ]; then
|
416
|
snapshots_update_status ">>> NOTE: waiting for jobs: ${_bg_pids} to finish..."
|
417
|
else
|
418
|
echo ">>> NOTE: waiting for jobs: ${_bg_pids} to finish..."
|
419
|
fi
|
420
|
wait
|
421
|
|
422
|
# XXX: For some reason wait is failing, workaround it tracking all PIDs
|
423
|
while [ -n "${_bg_pids}" ]; do
|
424
|
_tmp_pids="${_bg_pids}"
|
425
|
unset _bg_pids
|
426
|
for p in ${_tmp_pids}; do
|
427
|
[ -z "${p}" ] \
|
428
|
&& continue
|
429
|
|
430
|
kill -0 ${p} >/dev/null 2>&1 \
|
431
|
&& _bg_pids="${_bg_pids}${_bg_pids:+ }${p}"
|
432
|
done
|
433
|
[ -n "${_bg_pids}" ] \
|
434
|
&& sleep 1
|
435
|
done
|
436
|
fi
|
437
|
|
438
|
if [ -n "${SNAPSHOTS}" ]; then
|
439
|
if [ "${IMAGETYPE}" = "none" -a -n "${UPLOAD}" ]; then
|
440
|
pkg_repo_rsync "${CORE_PKG_PATH}"
|
441
|
elif [ "${IMAGETYPE}" != "none" ]; then
|
442
|
snapshots_create_sha256
|
443
|
# SCP files to snapshot web hosting area
|
444
|
if [ -n "${UPLOAD}" ]; then
|
445
|
snapshots_scp_files
|
446
|
fi
|
447
|
fi
|
448
|
# Alert the world that we have some snapshots ready.
|
449
|
snapshots_update_status ">>> Builder run is complete."
|
450
|
fi
|
451
|
|
452
|
echo ">>> ${IMAGES_FINAL_DIR} now contains:"
|
453
|
(cd ${IMAGES_FINAL_DIR} && find ${IMAGES_FINAL_DIR} -type f)
|
454
|
|
455
|
set -e
|
456
|
# Run final finish routines
|
457
|
finish
|