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