1
|
#!/bin/sh
|
2
|
#
|
3
|
# builder_common.sh
|
4
|
#
|
5
|
# Copyright (c) 2004-2015 Electric Sheep Fencing, LLC
|
6
|
# Copyright (C) 2014 Ermal Luçi
|
7
|
# All rights reserved.
|
8
|
#
|
9
|
# NanoBSD portions of the code
|
10
|
# Copyright (c) 2005 Poul-Henning Kamp.
|
11
|
# and copied from nanobsd.sh
|
12
|
# All rights reserved.
|
13
|
#
|
14
|
# FreeSBIE portions of the code
|
15
|
# Copyright (c) 2005 Dario Freni
|
16
|
# and copied from FreeSBIE project
|
17
|
# All rights reserved.
|
18
|
#
|
19
|
# Redistribution and use in source and binary forms, with or without
|
20
|
# modification, are permitted provided that the following conditions
|
21
|
# are met:
|
22
|
#
|
23
|
# 1. Redistributions of source code must retain the above copyright
|
24
|
# notice, this list of conditions and the following disclaimer.
|
25
|
#
|
26
|
# 2. Redistributions in binary form must reproduce the above copyright
|
27
|
# notice, this list of conditions and the following disclaimer in the
|
28
|
# documentation and/or other materials provided with the distribution.
|
29
|
#
|
30
|
# THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
31
|
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
32
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
33
|
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
34
|
# ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
35
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
36
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
37
|
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
38
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
39
|
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
40
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
41
|
# OF THE POSSIBILITY OF SUCH DAMAGE.
|
42
|
# Redistribution and use in source and binary forms, with or without
|
43
|
# modification, are permitted provided that the following conditions are met:
|
44
|
#
|
45
|
|
46
|
if [ -n "${IMAGES_FINAL_DIR}" -a "${IMAGES_FINAL_DIR}" != "/" ]; then
|
47
|
mkdir -p ${IMAGES_FINAL_DIR}
|
48
|
else
|
49
|
echo "IMAGES_FINAL_DIR is not defined"
|
50
|
print_error_pfS
|
51
|
fi
|
52
|
|
53
|
lc() {
|
54
|
echo "${1}" | tr '[[:upper:]]' '[[:lower:]]'
|
55
|
}
|
56
|
|
57
|
git_last_commit() {
|
58
|
export CURRENT_COMMIT=$(git -C ${BUILDER_ROOT} log -1 --format='%H')
|
59
|
export CURRENT_AUTHOR=$(git -C ${BUILDER_ROOT} log -1 --format='%an')
|
60
|
echo ">>> Last known commit $CURRENT_AUTHOR - $CURRENT_COMMIT"
|
61
|
echo "$CURRENT_COMMIT" > $SCRATCHDIR/build_commit_info.txt
|
62
|
}
|
63
|
|
64
|
# Create core pkg repository
|
65
|
core_pkg_create_repo() {
|
66
|
if [ ! -d "${CORE_PKG_PATH}/All" ]; then
|
67
|
return
|
68
|
fi
|
69
|
|
70
|
echo -n ">>> Creating core packages repository... "
|
71
|
if pkg repo -q -o "${CORE_PKG_PATH}" "${CORE_PKG_PATH}/All"; then
|
72
|
echo "Done!"
|
73
|
else
|
74
|
echo "Failed!"
|
75
|
print_error_pfS
|
76
|
fi
|
77
|
}
|
78
|
|
79
|
# Create core pkg (base, kernel)
|
80
|
core_pkg_create() {
|
81
|
local _template="${1}"
|
82
|
local _flavor="${2}"
|
83
|
local _version="${3}"
|
84
|
local _root="${4}"
|
85
|
|
86
|
[ -d "${CORE_PKG_TMP}" ] \
|
87
|
&& rm -rf ${CORE_PKG_TMP}
|
88
|
|
89
|
local _templates_path=${BUILDER_TOOLS}/templates/core_pkg/${_template}
|
90
|
local _template_metadir=${_templates_path}/metadir
|
91
|
local _metadir=${CORE_PKG_TMP}/${_template}_metadir
|
92
|
|
93
|
if [ ! -d ${_template_metadir} ]; then
|
94
|
echo "ERROR: Template dir not found for pkg ${_template}"
|
95
|
exit
|
96
|
fi
|
97
|
|
98
|
mkdir -p ${CORE_PKG_TMP}
|
99
|
|
100
|
cp -r ${_template_metadir} ${_metadir}
|
101
|
|
102
|
local _manifest=${_metadir}/+MANIFEST
|
103
|
local _plist=${CORE_PKG_TMP}/${_template}_plist
|
104
|
local _exclude_plist=${CORE_PKG_TMP}/${_template}_exclude_plist
|
105
|
|
106
|
if [ -f "${_templates_path}/pkg-plist" ]; then
|
107
|
cp ${_templates_path}/pkg-plist ${_plist}
|
108
|
else
|
109
|
(cd ${_root} && find . -type f -or -type l | sed 's,^.,,' | sort -u) > ${_plist}
|
110
|
fi
|
111
|
|
112
|
if [ -f "${_templates_path}/exclude_plist" ]; then
|
113
|
cp ${_templates_path}/exclude_plist ${_exclude_plist}
|
114
|
else
|
115
|
touch ${_exclude_plist}
|
116
|
fi
|
117
|
|
118
|
sed \
|
119
|
-i '' \
|
120
|
-e "s,%%PRODUCT_NAME%%,${PRODUCT_NAME},g" \
|
121
|
-e "s,%%PRODUCT_URL%%,${PRODUCT_URL},g" \
|
122
|
-e "s,%%FLAVOR%%,${_flavor},g" \
|
123
|
-e "s,%%VERSION%%,${_version},g" \
|
124
|
${_metadir}/* \
|
125
|
${_plist} \
|
126
|
${exclude_plist}
|
127
|
|
128
|
if [ -f "${_exclude_plist}" ]; then
|
129
|
sort -u ${_exclude_plist} > ${_plist}.exclude
|
130
|
mv ${_plist} ${_plist}.tmp
|
131
|
comm -23 ${_plist}.tmp ${_plist}.exclude > ${_plist}
|
132
|
rm -f ${_plist}.tmp ${plist}.exclude
|
133
|
fi
|
134
|
|
135
|
mkdir -p ${CORE_PKG_PATH}/All
|
136
|
if ! pkg create -o ${CORE_PKG_PATH}/All -p ${_plist} -r ${_root} -m ${_metadir}; then
|
137
|
echo ">>> ERROR: Error building package ${_template} ${_flavor}"
|
138
|
print_error_pfS
|
139
|
fi
|
140
|
}
|
141
|
|
142
|
# This routine will output that something went wrong
|
143
|
print_error_pfS() {
|
144
|
echo
|
145
|
echo "####################################"
|
146
|
echo "Something went wrong, check errors!" >&2
|
147
|
echo "####################################"
|
148
|
echo
|
149
|
echo "NOTE: a lot of times you can run './build.sh --clean-builder' to resolve."
|
150
|
echo
|
151
|
if [ "$1" != "" ]; then
|
152
|
echo $1
|
153
|
fi
|
154
|
[ -n "${LOGFILE:-}" -a -f "${LOGFILE}" ] && \
|
155
|
echo "Log saved on ${LOGFILE}" && \
|
156
|
tail -n20 ${LOGFILE} >&2
|
157
|
echo
|
158
|
echo "Press enter to continue."
|
159
|
read ans
|
160
|
kill $$
|
161
|
exit 1
|
162
|
}
|
163
|
|
164
|
prestage_on_ram_setup() {
|
165
|
[ -d "${STAGE_CHROOT_DIR}" ] \
|
166
|
|| mkdir -p ${STAGE_CHROOT_DIR}
|
167
|
[ -d "${FINAL_CHROOT_DIR}" ] \
|
168
|
|| mkdir -p ${FINAL_CHROOT_DIR}
|
169
|
|
170
|
_AVAIL_MEM=$(($(sysctl -n hw.usermem) / 1024 / 1024))
|
171
|
if [ $_AVAIL_MEM -lt 2000 ]; then
|
172
|
echo ">>> Builder has less than 2GiB RAM skipping memory disks"
|
173
|
return
|
174
|
else
|
175
|
echo "######################################################################################"
|
176
|
echo
|
177
|
echo ">>> Builder has more than 2GiB RAM enabling memory disks"
|
178
|
echo ">>> WARNING: Remember to remove these memory disks by running $0 --disable-memorydisks"
|
179
|
echo
|
180
|
echo "######################################################################################"
|
181
|
fi
|
182
|
|
183
|
if df /dev/ufs/prestagebacking >/dev/null 2>&1; then
|
184
|
echo ">>> Detected preexisting memory disk enabled for ${STAGE_CHROOT_DIR}."
|
185
|
else
|
186
|
mdconfig -a -t swap -u 10001 -s ${MEMORYDISK_SIZE}
|
187
|
newfs -L prestagebacking -U /dev/md10001
|
188
|
mount /dev/ufs/prestagebacking ${STAGE_CHROOT_DIR}
|
189
|
fi
|
190
|
|
191
|
if df /dev/ufs/finalstagebacking >/dev/null 2>&1; then
|
192
|
echo ">>> Detected preexisting memory disk enabled for ${FINAL_CHROOT_DIR}."
|
193
|
else
|
194
|
mdconfig -a -t swap -u 10002 -s ${MEMORYDISK_SIZE}
|
195
|
newfs -L finalstagebacking -U /dev/md10002
|
196
|
mount /dev/ufs/finalstagebacking ${FINAL_CHROOT_DIR}
|
197
|
fi
|
198
|
}
|
199
|
|
200
|
prestage_on_ram_cleanup() {
|
201
|
if [ -c /dev/md10001 ]; then
|
202
|
if [ -d ${STAGE_CHROOT_DIR} ]; then
|
203
|
umount ${STAGE_CHROOT_DIR}
|
204
|
fi
|
205
|
mdconfig -d -u 10001
|
206
|
fi
|
207
|
if [ -c /dev/md10002 ]; then
|
208
|
if [ -d ${FINAL_CHROOT_DIR} ]; then
|
209
|
umount ${FINAL_CHROOT_DIR}
|
210
|
fi
|
211
|
mdconfig -d -u 10002
|
212
|
fi
|
213
|
}
|
214
|
|
215
|
# This routine will verify that the kernel has been
|
216
|
# installed OK to the staging area.
|
217
|
ensure_kernel_exists() {
|
218
|
if [ ! -f "$1/boot/kernel/kernel.gz" ]; then
|
219
|
echo ">>> ERROR: Could not locate $1/boot/kernel.gz"
|
220
|
print_error_pfS
|
221
|
fi
|
222
|
KERNEL_SIZE=$(stat -f "%z" $1/boot/kernel/kernel.gz)
|
223
|
if [ "$KERNEL_SIZE" -lt 3500 ]; then
|
224
|
echo ">>> ERROR: Kernel $1/boot/kernel.gz appears to be smaller than it should be: $KERNEL_SIZE"
|
225
|
print_error_pfS
|
226
|
fi
|
227
|
}
|
228
|
|
229
|
get_pkg_name() {
|
230
|
echo "${PRODUCT_NAME}-${1}-${CORE_PKG_VERSION}"
|
231
|
}
|
232
|
|
233
|
# This routine builds all related kernels
|
234
|
build_all_kernels() {
|
235
|
# Set KERNEL_BUILD_PATH if it has not been set
|
236
|
if [ -z "${KERNEL_BUILD_PATH}" ]; then
|
237
|
KERNEL_BUILD_PATH=$SCRATCHDIR/kernels
|
238
|
echo ">>> KERNEL_BUILD_PATH has not been set. Setting to ${KERNEL_BUILD_PATH}!"
|
239
|
fi
|
240
|
|
241
|
[ -d "${KERNEL_BUILD_PATH}" ] \
|
242
|
&& rm -rf ${KERNEL_BUILD_PATH}
|
243
|
|
244
|
# Build embedded kernel
|
245
|
for BUILD_KERNEL in $BUILD_KERNELS; do
|
246
|
unset KERNCONF
|
247
|
unset KERNEL_DESTDIR
|
248
|
unset KERNELCONF
|
249
|
unset KERNEL_NAME
|
250
|
export KERNCONF=$BUILD_KERNEL
|
251
|
export KERNEL_DESTDIR="$KERNEL_BUILD_PATH/$BUILD_KERNEL"
|
252
|
export KERNELCONF="${FREEBSD_SRC_DIR}/sys/${TARGET}/conf/$BUILD_KERNEL"
|
253
|
export KERNEL_NAME=${BUILD_KERNEL}
|
254
|
|
255
|
LOGFILE="${BUILDER_LOGS}/kernel.${KERNCONF}.${TARGET}.log"
|
256
|
echo ">>> Building $BUILD_KERNEL kernel." | tee -a ${LOGFILE}
|
257
|
|
258
|
if [ ! -e "${FREEBSD_SRC_DIR}/sys/${TARGET}/conf/${BUILD_KERNEL}" ]; then
|
259
|
echo ">>> ERROR: Could not find $KERNELCONF"
|
260
|
print_error_pfS
|
261
|
fi
|
262
|
|
263
|
if [ -n "${NO_BUILDKERNEL:-}" -a -f "${CORE_PKG_PATH}/All/$(get_pkg_name kernel-${KERNEL_NAME}).txz" ]; then
|
264
|
echo ">>> NO_BUILDKERNEL set, skipping build" | tee -a ${LOGFILE}
|
265
|
continue
|
266
|
fi
|
267
|
|
268
|
export SRC_CONF=${SRC_CONF}
|
269
|
buildkernel
|
270
|
|
271
|
echo ">>> Staging $BUILD_KERNEL kernel..." | tee -a ${LOGFILE}
|
272
|
installkernel
|
273
|
|
274
|
ensure_kernel_exists $KERNEL_DESTDIR
|
275
|
|
276
|
echo -n ">>> Creating pkg of $KERNEL_NAME kernel to staging area..." | tee -a ${LOGFILE}
|
277
|
core_pkg_create kernel ${KERNEL_NAME} ${CORE_PKG_VERSION} ${KERNEL_DESTDIR}
|
278
|
|
279
|
rm -rf $KERNEL_DESTDIR 2>&1 1>/dev/null
|
280
|
|
281
|
echo ".Done" | tee -a ${LOGFILE}
|
282
|
done
|
283
|
}
|
284
|
|
285
|
install_default_kernel() {
|
286
|
if [ -z "${1}" ]; then
|
287
|
echo ">>> ERROR: install_default_kernel called without a kernel config name"| tee -a ${LOGFILE}
|
288
|
print_error_pfS
|
289
|
fi
|
290
|
|
291
|
export KERNEL_NAME="${1}"
|
292
|
|
293
|
echo -n ">>> Installing kernel to be used by image ${KERNEL_NAME}..." | tee -a ${LOGFILE}
|
294
|
|
295
|
# Copy kernel package to chroot, otherwise pkg won't find it to install
|
296
|
if ! pkg_chroot_add ${FINAL_CHROOT_DIR} kernel-${KERNEL_NAME}; then
|
297
|
echo ">>> ERROR: Error installing kernel package $(get_pkg_name kernel-${KERNEL_NAME}).txz" | tee -a ${LOGFILE}
|
298
|
print_error_pfS
|
299
|
fi
|
300
|
|
301
|
# Lock kernel to avoid user end up removing it for any reason
|
302
|
pkg_chroot ${FINAL_CHROOT_DIR} lock -q -y $(get_pkg_name kernel-${KERNEL_NAME})
|
303
|
|
304
|
if [ ! -f $FINAL_CHROOT_DIR/boot/kernel/kernel.gz ]; then
|
305
|
echo ">>> ERROR: No kernel installed on $FINAL_CHROOT_DIR and the resulting image will be unusable. STOPPING!" | tee -a ${LOGFILE}
|
306
|
print_error_pfS
|
307
|
fi
|
308
|
mkdir -p $FINAL_CHROOT_DIR/pkgs
|
309
|
if [ -z "${2}" -o -n "${INSTALL_EXTRA_KERNELS}" ]; then
|
310
|
cp ${CORE_PKG_PATH}/All/$(get_pkg_name kernel-${KERNEL_NAME}).txz $FINAL_CHROOT_DIR/pkgs
|
311
|
if [ -n "${INSTALL_EXTRA_KERNELS}" ]; then
|
312
|
for _EXTRA_KERNEL in $INSTALL_EXTRA_KERNELS; do
|
313
|
_EXTRA_KERNEL_PATH=${CORE_PKG_PATH}/All/$(get_pkg_name kernel-${_EXTRA_KERNEL}).txz
|
314
|
if [ -f "${_EXTRA_KERNEL_PATH}" ]; then
|
315
|
echo -n ". adding ${_EXTRA_KERNEL_PATH} on image /pkgs folder"
|
316
|
cp ${_EXTRA_KERNEL_PATH} $FINAL_CHROOT_DIR/pkgs
|
317
|
else
|
318
|
echo ">>> ERROR: Requested kernel $(get_pkg_name kernel-${_EXTRA_KERNEL}).txz was not found to be put on image /pkgs folder!"
|
319
|
print_error_pfS
|
320
|
fi
|
321
|
done
|
322
|
fi
|
323
|
fi
|
324
|
echo "Done." | tee -a ${LOGFILE}
|
325
|
|
326
|
unset KERNEL_NAME
|
327
|
}
|
328
|
|
329
|
# Items that need to be fixed up that are
|
330
|
# specific to nanobsd builds
|
331
|
cust_fixup_nanobsd() {
|
332
|
local _NANO_WITH_VGA="${1}"
|
333
|
|
334
|
echo ">>> Fixing up NanoBSD Specific items..." | tee -a ${LOGFILE}
|
335
|
|
336
|
echo "nanobsd" > $FINAL_CHROOT_DIR/etc/platform
|
337
|
|
338
|
local BOOTCONF=${FINAL_CHROOT_DIR}/boot.config
|
339
|
local LOADERCONF=${FINAL_CHROOT_DIR}/boot/loader.conf
|
340
|
|
341
|
if [ "${_NANO_WITH_VGA}" = "nanobsd" ]; then
|
342
|
# Tell loader to use serial console early.
|
343
|
echo "-S115200 -h" >> ${BOOTCONF}
|
344
|
fi
|
345
|
|
346
|
# Remove old console options if present.
|
347
|
[ -f "${LOADERCONF}" ] \
|
348
|
&& sed -i "" -Ee "/(console|boot_multicons|boot_serial|hint.uart)/d" ${LOADERCONF}
|
349
|
# Activate serial console+video console in loader.conf
|
350
|
echo 'autoboot_delay="5"' >> ${LOADERCONF}
|
351
|
echo 'loader_color="NO"' >> ${LOADERCONF}
|
352
|
echo 'beastie_disable="YES"' >> ${LOADERCONF}
|
353
|
echo 'boot_serial="YES"' >> ${LOADERCONF}
|
354
|
echo 'console="comconsole"' >> ${LOADERCONF}
|
355
|
echo 'comconsole_speed="115200"' >> ${LOADERCONF}
|
356
|
}
|
357
|
|
358
|
# Creates a full update file
|
359
|
create_Full_update_tarball() {
|
360
|
mkdir -p $UPDATESDIR
|
361
|
|
362
|
customize_stagearea_for_image "fullupdate"
|
363
|
install_default_kernel ${DEFAULT_KERNEL}
|
364
|
|
365
|
rm -rf ${FINAL_CHROOT_DIR}/cf
|
366
|
rm -rf ${FINAL_CHROOT_DIR}/conf
|
367
|
rm -f ${FINAL_CHROOT_DIR}/etc/rc.conf
|
368
|
rm -f ${FINAL_CHROOT_DIR}/etc/pwd.db 2>/dev/null
|
369
|
rm -f ${FINAL_CHROOT_DIR}/etc/group 2>/dev/null
|
370
|
rm -f ${FINAL_CHROOT_DIR}/etc/spwd.db 2>/dev/null
|
371
|
rm -f ${FINAL_CHROOT_DIR}/etc/passwd 2>/dev/null
|
372
|
rm -f ${FINAL_CHROOT_DIR}/etc/master.passwd 2>/dev/null
|
373
|
rm -f ${FINAL_CHROOT_DIR}/etc/fstab 2>/dev/null
|
374
|
rm -f ${FINAL_CHROOT_DIR}/etc/bogons 2>/dev/null
|
375
|
# Remove loader.conf and friends. Ticket #560
|
376
|
rm ${FINAL_CHROOT_DIR}/boot/loader.conf 2>/dev/null
|
377
|
rm ${FINAL_CHROOT_DIR}/boot/loader.conf.local 2>/dev/null
|
378
|
|
379
|
echo ">>> Creating ${UPDATES_TARBALL_FILENAME} ..." | tee -a ${LOGFILE}
|
380
|
tar --exclude=./dev -czPf ${UPDATES_TARBALL_FILENAME} -C ${FINAL_CHROOT_DIR} .
|
381
|
}
|
382
|
|
383
|
# Outputs various set variables aka env
|
384
|
print_flags() {
|
385
|
|
386
|
echo
|
387
|
printf " Product version: %s\n" $PRODUCT_VERSION
|
388
|
printf " Stage DIR: %s\n" $STAGE_CHROOT_DIR
|
389
|
printf " Updates dir: %s\n" $UPDATESDIR
|
390
|
printf " Image Preparation Stage DIR: %s\n" $FINAL_CHROOT_DIR
|
391
|
printf " Source DIR: %s\n" $FREEBSD_SRC_DIR
|
392
|
printf " FreeBSD repository: %s\n" $FREEBSD_REPO_BASE
|
393
|
printf " FreeBSD-src branch: %s\n" $FREEBSD_BRANCH
|
394
|
printf " FreeBSD original branch: %s\n" $FREEBSD_PARENT_BRANCH
|
395
|
printf " BUILD_KERNELS: %s\n" $BUILD_KERNELS
|
396
|
printf " Git Branch or Tag: %s\n" $GIT_REPO_BRANCH_OR_TAG
|
397
|
printf " MODULES_OVERRIDE: %s\n" $MODULES_OVERRIDE
|
398
|
printf " VMDK_DISK_CAPACITY_IN_GB: %s\n" $VMDK_DISK_CAPACITY_IN_GB
|
399
|
printf " OVA_FIRST_PART_SIZE_IN_GB: %s\n" $OVA_FIRST_PART_SIZE_IN_GB
|
400
|
printf " OVA_SWAP_PART_SIZE_IN_GB: %s\n" $OVA_SWAP_PART_SIZE_IN_GB
|
401
|
printf " OVFTEMPLATE: %s\n" $OVFTEMPLATE
|
402
|
printf " OVFVMDK: %s\n" $OVFVMDK
|
403
|
printf " SRC_CONF: %s\n" $SRC_CONF
|
404
|
printf " ISOPATH: %s\n" $ISOPATH
|
405
|
printf " MEMSTICKPATH: %s\n" $MEMSTICKPATH
|
406
|
printf " UPDATES_TARBALL_FILENAME: %s\n" $UPDATES_TARBALL_FILENAME
|
407
|
if [ -n "$SHOW_ENV" ]; then
|
408
|
for LINE in $(env | egrep -v '(terminal|PASS|NAME|USER|SSH|GROUP|HOST)'); do
|
409
|
echo "SHOW_ENV: $LINE"
|
410
|
done
|
411
|
fi
|
412
|
echo
|
413
|
}
|
414
|
|
415
|
# This builds FreeBSD (make buildworld)
|
416
|
# Imported from FreeSBIE
|
417
|
make_world() {
|
418
|
|
419
|
LOGFILE=${BUILDER_LOGS}/buildworld.${TARGET}
|
420
|
if [ -n "${NO_BUILDWORLD:-}" ]; then
|
421
|
echo ">>> NO_BUILDWORLD set, skipping build" | tee -a ${LOGFILE}
|
422
|
return
|
423
|
fi
|
424
|
|
425
|
# Set SRC_CONF variable if it's not already set.
|
426
|
if [ -z "${SRC_CONF:-}" ]; then
|
427
|
echo ">>> SRC_CONF is unset make sure this is what you want!" | tee -a ${LOGFILE}
|
428
|
else
|
429
|
echo ">>> Setting SRC_CONF to $SRC_CONF" | tee -a ${LOGFILE}
|
430
|
fi
|
431
|
|
432
|
# Set default parameters
|
433
|
export MAKE_ARGS="${MAKEJ_WORLD:-} __MAKE_CONF=${MAKE_CONF} SRCCONF=${SRC_CONF} TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}"
|
434
|
|
435
|
echo ">>> LOGFILE set to $LOGFILE." | tee -a ${LOGFILE}
|
436
|
makeargs="${MAKE_ARGS}"
|
437
|
echo ">>> Building world for ${TARGET} architecture... (Starting - $(LC_ALL=C date))" | tee -a ${LOGFILE}
|
438
|
echo ">>> Builder is running the command: env LOCAL_ITOOLS=\"${EXTRA_TOOLS}\" script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR} -DNO_CLEAN ${makeargs:-} buildworld" | tee -a ${LOGFILE}
|
439
|
(env LOCAL_ITOOLS="${EXTRA_TOOLS}" script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR} -DNO_CLEAN ${makeargs:-} buildworld || print_error_pfS;) | egrep '^>>>' | tee -a ${LOGFILE}
|
440
|
echo ">>> Building world for ${TARGET} architecture... (Finished - $(LC_ALL=C date))" | tee -a ${LOGFILE}
|
441
|
|
442
|
LOGFILE=${BUILDER_LOGS}/installworld.${TARGET}
|
443
|
echo ">>> LOGFILE set to $LOGFILE." | tee -a ${LOGFILE}
|
444
|
# Create if cleaned up
|
445
|
makeargs="${MAKE_ARGS} DESTDIR=${STAGE_CHROOT_DIR} WITHOUT_TOOLCHAIN=1"
|
446
|
echo ">>> Installing world for ${TARGET} architecture... (Starting - $(LC_ALL=C date))" | tee -a ${LOGFILE}
|
447
|
echo ">>> Builder is running the command: env LOCAL_ITOOLS=\"${EXTRA_TOOLS}\" script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR} ${makeargs:-} installworld" | tee -a ${LOGFILE}
|
448
|
(env LOCAL_ITOOLS="${EXTRA_TOOLS}" script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR} ${makeargs:-} installworld || print_error_pfS;) | egrep '^>>>' | tee -a ${LOGFILE}
|
449
|
echo ">>> Installing world for ${TARGET} architecture... (Finished - $(LC_ALL=C date))" | tee -a ${LOGFILE}
|
450
|
|
451
|
makeargs="${MAKE_ARGS} DESTDIR=${STAGE_CHROOT_DIR}"
|
452
|
echo ">>> Distribution world for ${TARGET} architecture... (Starting - $(LC_ALL=C date))" | tee -a ${LOGFILE}
|
453
|
echo ">>> Builder is running the command: script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR} ${makeargs:-} distribution " | tee -a ${LOGFILE}
|
454
|
(script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR} ${makeargs:-} distribution || print_error_pfS;) | egrep '^>>>' | tee -a ${LOGFILE}
|
455
|
echo ">>> Distribution world for ${TARGET} architecture... (Finished - $(LC_ALL=C date))" | tee -a ${LOGFILE}
|
456
|
|
457
|
[ -d "${STAGE_CHROOT_DIR}/usr/local/bin" ] \
|
458
|
|| mkdir -p ${STAGE_CHROOT_DIR}/usr/local/bin
|
459
|
makeargs="${MAKE_ARGS} DESTDIR=${STAGE_CHROOT_DIR}"
|
460
|
echo ">>> Building and installing crypto tools and athstats for ${TARGET} architecture... (Starting - $(LC_ALL=C date))" | tee -a ${LOGFILE}
|
461
|
echo ">>> Builder is running the command: script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR}/tools/tools/crypto ${makeargs:-} clean all install " | tee -a ${LOGFILE}
|
462
|
(script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR}/tools/tools/crypto ${makeargs:-} clean all install || print_error_pfS;) | egrep '^>>>' | tee -a ${LOGFILE}
|
463
|
echo ">>> Builder is running the command: script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR}/tools/tools/ath/athstats ${makeargs:-} clean" | tee -a ${LOGFILE}
|
464
|
(script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR}/tools/tools/ath/athstats ${makeargs:-} clean || print_error_pfS;) | egrep '^>>>' | tee -a ${LOGFILE}
|
465
|
echo ">>> Builder is running the command: script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR}/tools/tools/ath/athstats ${makeargs:-} all" | tee -a ${LOGFILE}
|
466
|
(script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR}/tools/tools/ath/athstats ${makeargs:-} all || print_error_pfS;) | egrep '^>>>' | tee -a ${LOGFILE}
|
467
|
echo ">>> Builder is running the command: script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR}/tools/tools/ath/athstats ${makeargs:-} install" | tee -a ${LOGFILE}
|
468
|
(script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR}/tools/tools/ath/athstats ${makeargs:-} install || print_error_pfS;) | egrep '^>>>' | tee -a ${LOGFILE}
|
469
|
echo ">>> Building and installing crypto tools and athstats for ${TARGET} architecture... (Finished - $(LC_ALL=C date))" | tee -a ${LOGFILE}
|
470
|
|
471
|
unset makeargs
|
472
|
}
|
473
|
|
474
|
# This routine originated in nanobsd.sh
|
475
|
nanobsd_set_flash_details () {
|
476
|
a1=$(echo $1 | tr '[:upper:]' '[:lower:]')
|
477
|
|
478
|
# Source:
|
479
|
# SanDisk CompactFlash Memory Card
|
480
|
# Product Manual
|
481
|
# Version 10.9
|
482
|
# Document No. 20-10-00038
|
483
|
# April 2005
|
484
|
# Table 2-7
|
485
|
# NB: notice math error in SDCFJ-4096-388 line.
|
486
|
#
|
487
|
case "${a1}" in
|
488
|
1024|1024m|1024mb|1g)
|
489
|
NANO_MEDIASIZE=$((997129216/512))
|
490
|
;;
|
491
|
2048|2048m|2048mb|2g)
|
492
|
NANO_MEDIASIZE=$((1989999616/512))
|
493
|
;;
|
494
|
4096|4096m|4096mb|4g)
|
495
|
NANO_MEDIASIZE=$((3989999616/512))
|
496
|
;;
|
497
|
8192|8192m|8192mb|8g)
|
498
|
NANO_MEDIASIZE=$((7989999616/512))
|
499
|
;;
|
500
|
16384|16384m|16384mb|16g)
|
501
|
NANO_MEDIASIZE=$((15989999616/512))
|
502
|
;;
|
503
|
*)
|
504
|
echo "Unknown Flash capacity"
|
505
|
exit 2
|
506
|
;;
|
507
|
esac
|
508
|
|
509
|
NANO_HEADS=16
|
510
|
NANO_SECTS=63
|
511
|
|
512
|
echo ">>> [nanoo] $1"
|
513
|
echo ">>> [nanoo] NANO_MEDIASIZE: $NANO_MEDIASIZE"
|
514
|
echo ">>> [nanoo] NANO_HEADS: $NANO_HEADS"
|
515
|
echo ">>> [nanoo] NANO_SECTS: $NANO_SECTS"
|
516
|
echo ">>> [nanoo] NANO_BOOT0CFG: $NANO_BOOT0CFG"
|
517
|
}
|
518
|
|
519
|
# This routine originated in nanobsd.sh
|
520
|
create_nanobsd_diskimage () {
|
521
|
if [ -z "${1}" ]; then
|
522
|
echo ">>> ERROR: Type of image has not been specified"
|
523
|
print_error_pfS
|
524
|
fi
|
525
|
if [ -z "${2}" ]; then
|
526
|
echo ">>> ERROR: Size of image has not been specified"
|
527
|
print_error_pfS
|
528
|
fi
|
529
|
|
530
|
if [ "${1}" = "nanobsd" ]; then
|
531
|
# It's serial
|
532
|
export NANO_BOOTLOADER="boot/boot0sio"
|
533
|
elif [ "${1}" = "nanobsd-vga" ]; then
|
534
|
# It's vga
|
535
|
export NANO_BOOTLOADER="boot/boot0"
|
536
|
else
|
537
|
echo ">>> ERROR: Type of image to create unknown"
|
538
|
print_error_pfS
|
539
|
fi
|
540
|
|
541
|
if [ -z "${2}" ]; then
|
542
|
echo ">>> ERROR: Media size(s) not specified."
|
543
|
print_error_pfS
|
544
|
fi
|
545
|
|
546
|
if [ -z "${2}" ]; then
|
547
|
echo ">>> ERROR: FLASH_SIZE is not set."
|
548
|
print_error_pfS
|
549
|
fi
|
550
|
|
551
|
LOGFILE=${BUILDER_LOGS}/${1}.${TARGET}
|
552
|
# Prepare folder to be put in image
|
553
|
customize_stagearea_for_image "${1}"
|
554
|
install_default_kernel ${DEFAULT_KERNEL} "no"
|
555
|
|
556
|
# Must be run after customize_stagearea_for_image
|
557
|
cust_fixup_nanobsd ${1}
|
558
|
|
559
|
for _NANO_MEDIASIZE in ${2}; do
|
560
|
if [ -z "${_NANO_MEDIASIZE}" ]; then
|
561
|
continue;
|
562
|
fi
|
563
|
|
564
|
echo ">>> building NanoBSD(${1}) disk image with size ${_NANO_MEDIASIZE} for platform (${TARGET})..." | tee -a ${LOGFILE}
|
565
|
echo "" > $BUILDER_LOGS/nanobsd_cmds.sh
|
566
|
|
567
|
IMG="${IMAGES_FINAL_DIR}/${PRODUCT_NAME}-${PRODUCT_VERSION}-${_NANO_MEDIASIZE}-${TARGET}-${1}${TIMESTAMP_SUFFIX}.img"
|
568
|
IMGUPDATE="${IMAGES_FINAL_DIR}/${PRODUCT_NAME}-${PRODUCT_VERSION}-${_NANO_MEDIASIZE}-${TARGET}-${1}-upgrade${TIMESTAMP_SUFFIX}.img"
|
569
|
|
570
|
nanobsd_set_flash_details ${_NANO_MEDIASIZE}
|
571
|
|
572
|
# These are defined in FlashDevice and on builder_default.sh
|
573
|
echo $NANO_MEDIASIZE \
|
574
|
$NANO_IMAGES \
|
575
|
$NANO_SECTS \
|
576
|
$NANO_HEADS \
|
577
|
$NANO_CODESIZE \
|
578
|
$NANO_CONFSIZE \
|
579
|
$NANO_DATASIZE |
|
580
|
awk '
|
581
|
{
|
582
|
printf "# %s\n", $0
|
583
|
|
584
|
# size of cylinder in sectors
|
585
|
cs = $3 * $4
|
586
|
|
587
|
# number of full cylinders on media
|
588
|
cyl = int ($1 / cs)
|
589
|
|
590
|
# output fdisk geometry spec, truncate cyls to 1023
|
591
|
if (cyl <= 1023)
|
592
|
print "g c" cyl " h" $4 " s" $3
|
593
|
else
|
594
|
print "g c" 1023 " h" $4 " s" $3
|
595
|
|
596
|
if ($7 > 0) {
|
597
|
# size of data partition in full cylinders
|
598
|
dsl = int (($7 + cs - 1) / cs)
|
599
|
} else {
|
600
|
dsl = 0;
|
601
|
}
|
602
|
|
603
|
# size of config partition in full cylinders
|
604
|
csl = int (($6 + cs - 1) / cs)
|
605
|
|
606
|
if ($5 == 0) {
|
607
|
# size of image partition(s) in full cylinders
|
608
|
isl = int ((cyl - dsl - csl) / $2)
|
609
|
} else {
|
610
|
isl = int (($5 + cs - 1) / cs)
|
611
|
}
|
612
|
|
613
|
# First image partition start at second track
|
614
|
print "p 1 165 " $3, isl * cs - $3
|
615
|
c = isl * cs;
|
616
|
|
617
|
# Second image partition (if any) also starts offset one
|
618
|
# track to keep them identical.
|
619
|
if ($2 > 1) {
|
620
|
print "p 2 165 " $3 + c, isl * cs - $3
|
621
|
c += isl * cs;
|
622
|
}
|
623
|
|
624
|
# Config partition starts at cylinder boundary.
|
625
|
print "p 3 165 " c, csl * cs
|
626
|
c += csl * cs
|
627
|
|
628
|
# Data partition (if any) starts at cylinder boundary.
|
629
|
if ($7 > 0) {
|
630
|
print "p 4 165 " c, dsl * cs
|
631
|
} else if ($7 < 0 && $1 > c) {
|
632
|
print "p 4 165 " c, $1 - c
|
633
|
} else if ($1 < c) {
|
634
|
print "Disk space overcommitted by", \
|
635
|
c - $1, "sectors" > "/dev/stderr"
|
636
|
exit 2
|
637
|
}
|
638
|
|
639
|
# Force slice 1 to be marked active. This is necessary
|
640
|
# for booting the image from a USB device to work.
|
641
|
print "a 1"
|
642
|
}
|
643
|
' > ${IMAGES_FINAL_DIR}/_.fdisk
|
644
|
|
645
|
MNT=${IMAGES_FINAL_DIR}/_.mnt
|
646
|
mkdir -p ${MNT}
|
647
|
|
648
|
dd if=/dev/zero of=${IMG} bs=${NANO_SECTS}b \
|
649
|
count=0 seek=$((${NANO_MEDIASIZE}/${NANO_SECTS})) 2>&1 >> ${LOGFILE}
|
650
|
|
651
|
MD=$(mdconfig -a -t vnode -f ${IMG} -x ${NANO_SECTS} -y ${NANO_HEADS})
|
652
|
trap "mdconfig -d -u ${MD}; return" 1 2 15 EXIT
|
653
|
|
654
|
fdisk -i -f ${IMAGES_FINAL_DIR}/_.fdisk ${MD} 2>&1 >> ${LOGFILE}
|
655
|
fdisk ${MD} 2>&1 >> ${LOGFILE}
|
656
|
|
657
|
boot0cfg -B -b ${FINAL_CHROOT_DIR}/${NANO_BOOTLOADER} ${NANO_BOOT0CFG} ${MD} 2>&1 >> ${LOGFILE}
|
658
|
|
659
|
# Create first image
|
660
|
bsdlabel -m i386 -w -B -b ${FINAL_CHROOT_DIR}/boot/boot ${MD}s1 2>&1 >> ${LOGFILE}
|
661
|
bsdlabel -m i386 ${MD}s1 2>&1 >> ${LOGFILE}
|
662
|
local _label=$(lc ${PRODUCT_NAME})
|
663
|
newfs -L ${_label}0 ${NANO_NEWFS} /dev/${MD}s1a 2>&1 >> ${LOGFILE}
|
664
|
mount /dev/ufs/${_label}0 ${MNT}
|
665
|
if [ $? -ne 0 ]; then
|
666
|
echo ">>> ERROR: Something wrong happened during mount of first slice image creation. STOPPING!" | tee -a ${LOGFILE}
|
667
|
print_error_pfS
|
668
|
fi
|
669
|
# Consider the unmounting as well
|
670
|
trap "umount /dev/ufs/${_label}0; mdconfig -d -u ${MD}; return" 1 2 15 EXIT
|
671
|
|
672
|
clone_directory_contents ${FINAL_CHROOT_DIR} ${MNT}
|
673
|
|
674
|
# Set NanoBSD image size
|
675
|
echo "${_NANO_MEDIASIZE}" > ${MNT}/etc/nanosize.txt
|
676
|
rm -f $MNT/cf/conf/* 2>/dev/null
|
677
|
|
678
|
echo "/dev/ufs/${_label}0 / ufs ro,sync,noatime 1 1" > ${MNT}/etc/fstab
|
679
|
if [ $NANO_CONFSIZE -gt 0 ] ; then
|
680
|
echo "/dev/ufs/cf /cf ufs ro,sync,noatime 1 1" >> ${MNT}/etc/fstab
|
681
|
fi
|
682
|
|
683
|
umount ${MNT}
|
684
|
# Restore the original trap
|
685
|
trap "mdconfig -d -u ${MD}; return" 1 2 15 EXIT
|
686
|
|
687
|
# Setting NANO_IMAGES to 1 and NANO_INIT_IMG2 will tell
|
688
|
# NanoBSD to only create one partition. We default to 2
|
689
|
# partitions in case anything happens to the first the
|
690
|
# operator can boot from the 2nd and should be OK.
|
691
|
|
692
|
# Before just going to use dd for duplicate think!
|
693
|
# The images are created as sparse so lets take advantage
|
694
|
# of that by just exec some commands.
|
695
|
if [ $NANO_IMAGES -gt 1 -a $NANO_INIT_IMG2 -gt 0 ] ; then
|
696
|
# Duplicate to second image (if present)
|
697
|
echo ">>> Creating NanoBSD second slice by duplicating first slice." | tee -a ${LOGFILE}
|
698
|
# Create second image
|
699
|
dd if=/dev/${MD}s1 of=/dev/${MD}s2 conv=sparse bs=64k 2>&1 >> ${LOGFILE}
|
700
|
tunefs -L ${_label}1 /dev/${MD}s2a 2>&1 >> ${LOGFILE}
|
701
|
mount /dev/ufs/${_label}1 ${MNT}
|
702
|
if [ $? -ne 0 ]; then
|
703
|
echo ">>> ERROR: Something wrong happened during mount of second slice image creation. STOPPING!" | tee -a ${LOGFILE}
|
704
|
print_error_pfS
|
705
|
fi
|
706
|
# Consider the unmounting as well
|
707
|
trap "umount /dev/ufs/${_label}1; mdconfig -d -u ${MD}; return" 1 2 15 EXIT
|
708
|
|
709
|
echo "/dev/ufs/${_label}1 / ufs ro,sync,noatime 1 1" > ${MNT}/etc/fstab
|
710
|
if [ $NANO_CONFSIZE -gt 0 ] ; then
|
711
|
echo "/dev/ufs/cf /cf ufs ro,sync,noatime 1 1" >> ${MNT}/etc/fstab
|
712
|
fi
|
713
|
|
714
|
umount ${MNT}
|
715
|
# Restore the trap back
|
716
|
trap "mdconfig -d -u ${MD}; return" 1 2 15 EXIT
|
717
|
fi
|
718
|
|
719
|
# Create Data slice, if any.
|
720
|
# Note the changing of the variable to NANO_CONFSIZE
|
721
|
# from NANO_DATASIZE. We also added glabel support
|
722
|
# and populate the Product configuration from the /cf
|
723
|
# directory located in FINAL_CHROOT_DIR
|
724
|
if [ $NANO_CONFSIZE -gt 0 ] ; then
|
725
|
echo ">>> Creating /cf area to hold config.xml"
|
726
|
newfs -L cf ${NANO_NEWFS} /dev/${MD}s3 2>&1 >> ${LOGFILE}
|
727
|
# Mount data partition and copy contents of /cf
|
728
|
# Can be used later to create custom default config.xml while building
|
729
|
mount /dev/ufs/cf ${MNT}
|
730
|
if [ $? -ne 0 ]; then
|
731
|
echo ">>> ERROR: Something wrong happened during mount of cf slice image creation. STOPPING!" | tee -a ${LOGFILE}
|
732
|
print_error_pfS
|
733
|
fi
|
734
|
# Consider the unmounting as well
|
735
|
trap "umount /dev/ufs/cf; mdconfig -d -u ${MD}; return" 1 2 15 EXIT
|
736
|
|
737
|
clone_directory_contents ${FINAL_CHROOT_DIR}/cf ${MNT}
|
738
|
|
739
|
umount ${MNT}
|
740
|
# Restore the trap back
|
741
|
trap "mdconfig -d -u ${MD}; return" 1 2 15 EXIT
|
742
|
else
|
743
|
">>> [nanoo] NANO_CONFSIZE is not set. Not adding a /conf partition.. You sure about this??" | tee -a ${LOGFILE}
|
744
|
fi
|
745
|
|
746
|
echo ">>> [nanoo] Creating NanoBSD upgrade file from first slice..." | tee -a ${LOGFILE}
|
747
|
dd if=/dev/${MD}s1 of=$IMGUPDATE conv=sparse bs=64k 2>&1 >> ${LOGFILE}
|
748
|
|
749
|
mdconfig -d -u $MD
|
750
|
# Restore default action
|
751
|
trap "-" 1 2 15 EXIT
|
752
|
|
753
|
# Check each image and ensure that they are over
|
754
|
# 3 megabytes. If either image is under 20 megabytes
|
755
|
# in size then error out.
|
756
|
IMGSIZE=$(stat -f "%z" ${IMG})
|
757
|
IMGUPDATESIZE=$(stat -f "%z" ${IMGUPDATE})
|
758
|
CHECKSIZE="20040710"
|
759
|
if [ "$IMGSIZE" -lt "$CHECKSIZE" ]; then
|
760
|
echo ">>> ERROR: Something went wrong when building NanoBSD. The image size is under 20 megabytes!" | tee -a ${LOGFILE}
|
761
|
print_error_pfS
|
762
|
fi
|
763
|
if [ "$IMGUPDATESIZE" -lt "$CHECKSIZE" ]; then
|
764
|
echo ">>> ERROR: Something went wrong when building NanoBSD upgrade image. The image size is under 20 megabytes!" | tee -a ${LOGFILE}
|
765
|
print_error_pfS
|
766
|
fi
|
767
|
|
768
|
# Wrap up the show, Johnny
|
769
|
echo ">>> NanoBSD Image completed for size: $_NANO_MEDIASIZE." | tee -a ${LOGFILE}
|
770
|
|
771
|
gzip -f $IMG &
|
772
|
gzip -f $IMGUPDATE &
|
773
|
done
|
774
|
|
775
|
unset IMG
|
776
|
unset IMGUPDATE
|
777
|
unset IMGUPDATESIZE
|
778
|
unset IMGSIZE
|
779
|
|
780
|
ls -lah $IMAGES_FINAL_DIR
|
781
|
}
|
782
|
|
783
|
# This routine creates a ova image that contains
|
784
|
# a ovf and vmdk file. These files can be imported
|
785
|
# right into vmware or virtual box.
|
786
|
# (and many other emulation platforms)
|
787
|
# http://www.vmware.com/pdf/ovf_whitepaper_specification.pdf
|
788
|
create_ova_image() {
|
789
|
# XXX create a .ovf php creator that you can pass:
|
790
|
# 1. populatedSize
|
791
|
# 2. license
|
792
|
# 3. product name
|
793
|
# 4. version
|
794
|
# 5. number of network interface cards
|
795
|
# 6. allocationUnits
|
796
|
# 7. capacity
|
797
|
# 8. capacityAllocationUnits
|
798
|
|
799
|
LOGFILE=${BUILDER_LOGS}/ova.${TARGET}.log
|
800
|
|
801
|
[ -d "${OVA_TMP}" ] \
|
802
|
&& rm -rf ${OVA_TMP}
|
803
|
|
804
|
mkdir -p ${OVA_TMP}
|
805
|
|
806
|
# Prepare folder to be put in image
|
807
|
customize_stagearea_for_image "ova"
|
808
|
install_default_kernel ${DEFAULT_KERNEL} "no"
|
809
|
|
810
|
# Fill fstab
|
811
|
echo ">>> Installing platform specific items..." | tee -a ${LOGFILE}
|
812
|
echo "/dev/gpt/${PRODUCT_NAME} / ufs rw 0 0" > ${FINAL_CHROOT_DIR}/etc/fstab
|
813
|
echo "/dev/gpt/swap0 none swap sw 0 0" >> ${FINAL_CHROOT_DIR}/etc/fstab
|
814
|
|
815
|
# Create / partition
|
816
|
echo -n ">>> Creating / partition... " | tee -a ${LOGFILE}
|
817
|
makefs \
|
818
|
-B little \
|
819
|
-o label=${PRODUCT_NAME} \
|
820
|
-s ${OVA_FIRST_PART_SIZE_IN_GB}g \
|
821
|
${OVA_TMP}/${OVFUFS} \
|
822
|
${FINAL_CHROOT_DIR} 2>&1 >> ${LOGFILE}
|
823
|
|
824
|
if [ $? -ne 0 -o ! -f ${OVA_TMP}/${OVFUFS} ]; then
|
825
|
if [ -f ${OVA_TMP}/${OVFUFS} ]; then
|
826
|
rm -f ${OVA_TMP}/${OVFUFS}
|
827
|
fi
|
828
|
echo "Failed!" | tee -a ${LOGFILE}
|
829
|
echo ">>> ERROR: Error creating vmdk / partition. STOPPING!" | tee -a ${LOGFILE}
|
830
|
print_error_pfS
|
831
|
fi
|
832
|
echo "Done!" | tee -a ${LOGFILE}
|
833
|
|
834
|
# Create raw disk
|
835
|
echo -n ">>> Creating raw disk... " | tee -a ${LOGFILE}
|
836
|
mkimg \
|
837
|
-s gpt \
|
838
|
-f raw \
|
839
|
-b /boot/pmbr \
|
840
|
-p freebsd-boot:=/boot/gptboot \
|
841
|
-p freebsd-ufs/${PRODUCT_NAME}:=${OVA_TMP}/${OVFUFS} \
|
842
|
-p freebsd-swap/swap0::${OVA_SWAP_PART_SIZE} \
|
843
|
-o ${OVA_TMP}/${OVFRAW} 2>&1 >> ${LOGFILE}
|
844
|
|
845
|
if [ $? -ne 0 -o ! -f ${OVA_TMP}/${OVFRAW} ]; then
|
846
|
if [ -f ${OVA_TMP}/${OVFUFS} ]; then
|
847
|
rm -f ${OVA_TMP}/${OVFUFS}
|
848
|
fi
|
849
|
if [ -f ${OVA_TMP}/${OVFRAW} ]; then
|
850
|
rm -f ${OVA_TMP}/${OVFRAW}
|
851
|
fi
|
852
|
echo "Failed!" | tee -a ${LOGFILE}
|
853
|
echo ">>> ERROR: Error creating temporary vmdk image. STOPPING!" | tee -a ${LOGFILE}
|
854
|
print_error_pfS
|
855
|
fi
|
856
|
echo "Done!" | tee -a ${LOGFILE}
|
857
|
|
858
|
# We don't need it anymore
|
859
|
rm -f ${OVA_TMP}/${OVFUFS} >/dev/null 2>&1
|
860
|
|
861
|
# Convert raw to vmdk
|
862
|
echo -n ">>> Creating vmdk disk... " | tee -a ${LOGFILE}
|
863
|
vmdktool -z9 -v ${OVA_TMP}/${OVFVMDK} ${OVA_TMP}/${OVFRAW}
|
864
|
|
865
|
if [ $? -ne 0 -o ! -f ${OVA_TMP}/${OVFVMDK} ]; then
|
866
|
if [ -f ${OVA_TMP}/${OVFRAW} ]; then
|
867
|
rm -f ${OVA_TMP}/${OVFRAW}
|
868
|
fi
|
869
|
if [ -f ${OVA_TMP}/${OVFVMDK} ]; then
|
870
|
rm -f ${OVA_TMP}/${OVFVMDK}
|
871
|
fi
|
872
|
echo "Failed!" | tee -a ${LOGFILE}
|
873
|
echo ">>> ERROR: Error creating vmdk image. STOPPING!" | tee -a ${LOGFILE}
|
874
|
print_error_pfS
|
875
|
fi
|
876
|
echo "Done!" | tee -a ${LOGFILE}
|
877
|
|
878
|
rm -f ${OVA_TMP}/i${OVFRAW}
|
879
|
|
880
|
ova_setup_ovf_template
|
881
|
|
882
|
echo -n ">>> Writing final ova image... " | tee -a ${LOGFILE}
|
883
|
# Create OVA file for vmware
|
884
|
gtar -C ${OVA_TMP} -cpf ${OVAPATH} ${PRODUCT_NAME}.ovf ${OVFVMDK}
|
885
|
echo "Done!" | tee -a ${LOGFILE}
|
886
|
rm -f ${OVA_TMP}/${OVFVMDK} >/dev/null 2>&1
|
887
|
|
888
|
echo ">>> OVA created: $(LC_ALL=C date)" | tee -a ${LOGFILE}
|
889
|
}
|
890
|
|
891
|
# called from create_ova_image
|
892
|
ova_setup_ovf_template() {
|
893
|
if [ ! -f ${OVFTEMPLATE} ]; then
|
894
|
echo ">>> ERROR: OVF template file (${OVFTEMPLATE}) not found."
|
895
|
print_error_pfS
|
896
|
fi
|
897
|
|
898
|
# OperatingSystemSection (${PRODUCT_NAME}.ovf)
|
899
|
# 42 FreeBSD 32-Bit
|
900
|
# 78 FreeBSD 64-Bit
|
901
|
if [ "${TARGET}" = "amd64" ]; then
|
902
|
local _os_id="78"
|
903
|
local _os_type="freebsd64Guest"
|
904
|
local _os_descr="FreeBSD 64-Bit"
|
905
|
elif [ "${TARGET}" = "i386" ]; then
|
906
|
local _os_id="42"
|
907
|
local _os_type="freebsdGuest"
|
908
|
local _os_descr="FreeBSD"
|
909
|
else
|
910
|
echo ">>> ERROR: Platform not supported for OVA (${TARGET})"
|
911
|
print_error_pfS
|
912
|
fi
|
913
|
|
914
|
local POPULATED_SIZE=$(du -d0 -k $FINAL_CHROOT_DIR | cut -f1)
|
915
|
local POPULATED_SIZE_IN_BYTES=$((${POPULATED_SIZE}*1024))
|
916
|
local VMDK_FILE_SIZE=$(stat -f "%z" ${OVA_TMP}/${OVFVMDK})
|
917
|
|
918
|
sed \
|
919
|
-e "s,%%VMDK_FILE_SIZE%%,${VMDK_FILE_SIZE},g" \
|
920
|
-e "s,%%VMDK_DISK_CAPACITY_IN_GB%%,${VMDK_DISK_CAPACITY_IN_GB},g" \
|
921
|
-e "s,%%POPULATED_SIZE_IN_BYTES%%,${POPULATED_SIZE_IN_BYTES},g" \
|
922
|
-e "s,%%OS_ID%%,${_os_id},g" \
|
923
|
-e "s,%%OS_TYPE%%,${_os_type},g" \
|
924
|
-e "s,%%OS_DESCR%%,${_os_descr},g" \
|
925
|
-e "s,%%PRODUCT_NAME%%,${PRODUCT_NAME},g" \
|
926
|
-e "s,%%PRODUCT_VERSION%%,${PRODUCT_VERSION},g" \
|
927
|
-e "s,%%PRODUCT_URL%%,${PRODUCT_URL},g" \
|
928
|
-e "/^%%PRODUCT_LICENSE%%/r ${BUILDER_ROOT}/license.txt" \
|
929
|
-e "/^%%PRODUCT_LICENSE%%/d" \
|
930
|
${OVFTEMPLATE} > ${OVA_TMP}/${PRODUCT_NAME}.ovf
|
931
|
}
|
932
|
|
933
|
# Cleans up previous builds
|
934
|
clean_builder() {
|
935
|
# Clean out directories
|
936
|
echo ">>> Cleaning up previous build environment...Please wait!"
|
937
|
|
938
|
staginareas_clean_each_run
|
939
|
|
940
|
if [ -d "${STAGE_CHROOT_DIR}" ]; then
|
941
|
BASENAME=$(basename ${STAGE_CHROOT_DIR})
|
942
|
echo -n ">>> Cleaning ${STAGE_CHROOT_DIR} ..."
|
943
|
chflags -R noschg ${STAGE_CHROOT_DIR} 2>&1 >/dev/null
|
944
|
rm -rf ${STAGE_CHROOT_DIR}/* 2>/dev/null
|
945
|
echo "Done."
|
946
|
fi
|
947
|
|
948
|
if [ -z "${NO_CLEAN_FREEBSD_OBJ}" -a -d "${FREEBSD_SRC_DIR}" ]; then
|
949
|
OBJTREE=$(env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} make -C ${FREEBSD_SRC_DIR} -V OBJTREE)
|
950
|
if [ -d "${OBJTREE}" ]; then
|
951
|
echo -n ">>> Cleaning FreeBSD objects dir staging..."
|
952
|
echo -n "."
|
953
|
chflags -R noschg ${OBJTREE} 2>&1 >/dev/null
|
954
|
echo -n "."
|
955
|
rm -rf ${OBJTREE}/*
|
956
|
echo "Done!"
|
957
|
fi
|
958
|
if [ -d "${KERNEL_BUILD_PATH}" ]; then
|
959
|
echo -n ">>> Cleaning previously built kernel stage area..."
|
960
|
rm -rf $KERNEL_BUILD_PATH/*
|
961
|
echo "Done!"
|
962
|
fi
|
963
|
fi
|
964
|
mkdir -p $KERNEL_BUILD_PATH
|
965
|
|
966
|
echo -n ">>> Cleaning previously built images..."
|
967
|
rm -rf $IMAGES_FINAL_DIR/*
|
968
|
rm -rf $STAGINGAREA/*
|
969
|
echo "Done!"
|
970
|
|
971
|
if [ -z "${NO_CLEAN_FREEBSD_SRC}" ]; then
|
972
|
if [ -d "$FREEBSD_SRC_DIR" ]; then
|
973
|
echo -n ">>> Ensuring $FREEBSD_SRC_DIR is clean..."
|
974
|
rm -rf ${FREEBSD_SRC_DIR}
|
975
|
echo "Done!"
|
976
|
fi
|
977
|
fi
|
978
|
|
979
|
echo -n ">>> Cleaning previous builder logs..."
|
980
|
if [ -d "$BUILDER_LOGS" ]; then
|
981
|
rm -rf ${BUILDER_LOGS}
|
982
|
fi
|
983
|
mkdir -p ${BUILDER_LOGS}
|
984
|
|
985
|
echo "Done!"
|
986
|
|
987
|
echo ">>> Cleaning of builder environment has finished."
|
988
|
}
|
989
|
|
990
|
clone_directory_contents() {
|
991
|
if [ ! -d "$1" -o ! -d "$2" ]; then
|
992
|
if [ -z "${LOGFILE}" ]; then
|
993
|
echo ">>> ERROR: Argument $1 supplied is not a directory!"
|
994
|
else
|
995
|
echo ">>> ERROR: Argument $1 supplied is not a directory!" | tee -a ${LOGFILE}
|
996
|
fi
|
997
|
print_error_pfS
|
998
|
fi
|
999
|
echo -n ">>> Using TAR to clone $1 to $2 ..."
|
1000
|
tar -C ${1} -c -f - . | tar -C ${2} -x -p -f -
|
1001
|
echo "Done!"
|
1002
|
}
|
1003
|
|
1004
|
clone_to_staging_area() {
|
1005
|
# Clone everything to the final staging area
|
1006
|
echo -n ">>> Cloning everything to ${STAGE_CHROOT_DIR} staging area..."
|
1007
|
LOGFILE=${BUILDER_LOGS}/cloning.${TARGET}.log
|
1008
|
|
1009
|
tar -C ${PRODUCT_SRC} -c -f - . | \
|
1010
|
tar -C ${STAGE_CHROOT_DIR} -x -p -f -
|
1011
|
|
1012
|
if [ -f ${STAGE_CHROOT_DIR}/etc/master.passwd ]; then
|
1013
|
chroot ${STAGE_CHROOT_DIR} cap_mkdb /etc/master.passwd
|
1014
|
chroot ${STAGE_CHROOT_DIR} pwd_mkdb /etc/master.passwd
|
1015
|
fi
|
1016
|
mkdir -p ${STAGE_CHROOT_DIR}/etc/mtree
|
1017
|
mtree -Pcp ${STAGE_CHROOT_DIR}/var > ${STAGE_CHROOT_DIR}/etc/mtree/var.dist
|
1018
|
mtree -Pcp ${STAGE_CHROOT_DIR}/etc > ${STAGE_CHROOT_DIR}/etc/mtree/etc.dist
|
1019
|
if [ -d ${STAGE_CHROOT_DIR}/usr/local/etc ]; then
|
1020
|
mtree -Pcp ${STAGE_CHROOT_DIR}/usr/local/etc > ${STAGE_CHROOT_DIR}/etc/mtree/localetc.dist
|
1021
|
fi
|
1022
|
|
1023
|
## Add buildtime and lastcommit information
|
1024
|
# This is used for detecting updates.
|
1025
|
echo "$BUILTDATESTRING" > $STAGE_CHROOT_DIR/etc/version.buildtime
|
1026
|
# Record last commit info if it is available.
|
1027
|
if [ -f $SCRATCHDIR/build_commit_info.txt ]; then
|
1028
|
cp $SCRATCHDIR/build_commit_info.txt $STAGE_CHROOT_DIR/etc/version.lastcommit
|
1029
|
fi
|
1030
|
|
1031
|
local _exclude_files="${CORE_PKG_TMP}/base_exclude_files"
|
1032
|
sed \
|
1033
|
-e "s,%%PRODUCT_NAME%%,${PRODUCT_NAME},g" \
|
1034
|
-e "s,%%FLAVOR%%,${_flavor},g" \
|
1035
|
-e "s,%%VERSION%%,${_version},g" \
|
1036
|
${BUILDER_TOOLS}/templates/core_pkg/base/exclude_files \
|
1037
|
> ${_exclude_files}
|
1038
|
|
1039
|
mkdir -p ${STAGE_CHROOT_DIR}/usr/local/share/${PRODUCT_NAME} >/dev/null 2>&1
|
1040
|
mtree \
|
1041
|
-c \
|
1042
|
-k uid,gid,mode,size,flags,sha256digest \
|
1043
|
-p ${STAGE_CHROOT_DIR} \
|
1044
|
-X ${_exclude_files} \
|
1045
|
> ${STAGE_CHROOT_DIR}/usr/local/share/${PRODUCT_NAME}/base.mtree
|
1046
|
tar \
|
1047
|
-C ${STAGE_CHROOT_DIR} \
|
1048
|
-cJf ${STAGE_CHROOT_DIR}/usr/local/share/${PRODUCT_NAME}/base.txz \
|
1049
|
-X ${_exclude_files} \
|
1050
|
.
|
1051
|
|
1052
|
core_pkg_create base "" ${CORE_PKG_VERSION} ${STAGE_CHROOT_DIR}
|
1053
|
core_pkg_create default-config "" ${CORE_PKG_VERSION} ${STAGE_CHROOT_DIR}
|
1054
|
|
1055
|
local DEFAULTCONF=${STAGE_CHROOT_DIR}/conf.default/config.xml
|
1056
|
|
1057
|
# Change default interface names to match vmware driver
|
1058
|
sed -i '' -e 's,em0,vmx0,' -e 's,em1,vmx1,' ${DEFAULTCONF}
|
1059
|
core_pkg_create default-config-vmware "" ${CORE_PKG_VERSION} ${STAGE_CHROOT_DIR}
|
1060
|
|
1061
|
# Restore default values to be used by serial package
|
1062
|
sed -i '' -e 's,vmx0,em0,' -e 's,vmx1,em1,' ${DEFAULTCONF}
|
1063
|
|
1064
|
# Activate serial console in config.xml
|
1065
|
# If it was there before, clear the setting to be sure we don't add it twice.
|
1066
|
sed -i "" -e "/ <enableserial\/>/d" ${DEFAULTCONF}
|
1067
|
# Enable serial in the config
|
1068
|
sed -i "" -e "s/ <\/system>/ <enableserial\/>\\$(echo -e \\\n) <\/system>/" ${DEFAULTCONF}
|
1069
|
|
1070
|
echo force > ${STAGE_CHROOT_DIR}/cf/conf/enableserial_force
|
1071
|
|
1072
|
core_pkg_create default-config-serial "" ${CORE_PKG_VERSION} ${STAGE_CHROOT_DIR}
|
1073
|
|
1074
|
rm -f ${STAGE_CHROOT_DIR}/cf/conf/enableserial_force
|
1075
|
rm -f ${STAGE_CHROOT_DIR}/cf/conf/config.xml
|
1076
|
|
1077
|
# Make sure pkg is present
|
1078
|
pkg_bootstrap ${STAGE_CHROOT_DIR}
|
1079
|
|
1080
|
pkg_chroot_add ${STAGE_CHROOT_DIR} base
|
1081
|
|
1082
|
echo "Done!"
|
1083
|
}
|
1084
|
|
1085
|
create_final_staging_area() {
|
1086
|
if [ -z "${FINAL_CHROOT_DIR}" ]; then
|
1087
|
echo ">>> ERROR: FINAL_CHROOT_DIR is not set, cannot continue!" | tee -a ${LOGFILE}
|
1088
|
print_error_pfS
|
1089
|
fi
|
1090
|
|
1091
|
if [ -d "${FINAL_CHROOT_DIR}" ]; then
|
1092
|
echo -n ">>> Previous ${FINAL_CHROOT_DIR} detected cleaning up..." | tee -a ${LOGFILE}
|
1093
|
chflags -R noschg ${FINAL_CHROOT_DIR} 2>&1 1>/dev/null
|
1094
|
rm -rf ${FINAL_CHROOT_DIR}/* 2>&1 1>/dev/null
|
1095
|
echo "Done." | tee -a ${LOGFILE}
|
1096
|
fi
|
1097
|
|
1098
|
echo ">>> Preparing Final image staging area: $(LC_ALL=C date)" 2>&1 | tee -a ${LOGFILE}
|
1099
|
echo ">>> Cloning ${STAGE_CHROOT_DIR} to ${FINAL_CHROOT_DIR}" 2>&1 | tee -a ${LOGFILE}
|
1100
|
clone_directory_contents ${STAGE_CHROOT_DIR} ${FINAL_CHROOT_DIR}
|
1101
|
|
1102
|
if [ ! -f $FINAL_CHROOT_DIR/sbin/init ]; then
|
1103
|
echo ">>> ERROR: Something went wrong during cloning -- Please verify!" 2>&1 | tee -a ${LOGFILE}
|
1104
|
print_error_pfS
|
1105
|
fi
|
1106
|
}
|
1107
|
|
1108
|
customize_stagearea_for_image() {
|
1109
|
# Prepare final stage area
|
1110
|
create_final_staging_area
|
1111
|
|
1112
|
if [ "${1}" = "iso" -o \
|
1113
|
"${1}" = "memstick" -o \
|
1114
|
"${1}" = "memstickserial" -o \
|
1115
|
"${1}" = "memstickadi" ]; then
|
1116
|
install_bsdinstaller
|
1117
|
mkdir -p ${FINAL_CHROOT_DIR}/pkgs
|
1118
|
cp ${CORE_PKG_PATH}/All/*default-config*.txz ${FINAL_CHROOT_DIR}/pkgs
|
1119
|
fi
|
1120
|
|
1121
|
if [ "${1}" = "nanobsd" -o \
|
1122
|
"${1}" = "memstickserial" -o \
|
1123
|
"${1}" = "memstickadi" ]; then
|
1124
|
pkg_chroot_add ${FINAL_CHROOT_DIR} default-config-serial
|
1125
|
elif [ "${1}" = "ova" ]; then
|
1126
|
pkg_chroot_add ${FINAL_CHROOT_DIR} default-config-vmware
|
1127
|
else
|
1128
|
pkg_chroot_add ${FINAL_CHROOT_DIR} default-config
|
1129
|
fi
|
1130
|
}
|
1131
|
|
1132
|
create_distribution_tarball() {
|
1133
|
mkdir -p ${FINAL_CHROOT_DIR}/install
|
1134
|
|
1135
|
tar -C ${FINAL_CHROOT_DIR} --exclude ./install --exclude ./pkgs -cJf ${FINAL_CHROOT_DIR}/install/${PRODUCT_NAME}.txz .
|
1136
|
}
|
1137
|
|
1138
|
create_iso_image() {
|
1139
|
LOGFILE=${BUILDER_LOGS}/isoimage.${TARGET}
|
1140
|
echo ">>> Building bootable ISO image for ${TARGET}" | tee -a ${LOGFILE}
|
1141
|
if [ -z "${DEFAULT_KERNEL}" ]; then
|
1142
|
echo ">>> ERROR: Could not identify DEFAULT_KERNEL to install on image!" | tee -a ${LOGFILE}
|
1143
|
print_error_pfS
|
1144
|
fi
|
1145
|
|
1146
|
customize_stagearea_for_image "iso"
|
1147
|
install_default_kernel ${DEFAULT_KERNEL}
|
1148
|
|
1149
|
echo cdrom > $FINAL_CHROOT_DIR/etc/platform
|
1150
|
|
1151
|
FSLABEL=$(echo ${PRODUCT_NAME} | tr '[:lower:]' '[:upper:]')
|
1152
|
echo "/dev/iso9660/${FSLABEL} / cd9660 ro 0 0" > ${FINAL_CHROOT_DIR}/etc/fstab
|
1153
|
|
1154
|
# This check is for supporting create memstick/ova images
|
1155
|
echo -n ">>> Running command: script -aq $LOGFILE makefs -t cd9660 -o bootimage=\"i386;${FINAL_CHROOT_DIR}/boot/cdboot \"-o no-emul-boot -o rockridge " | tee -a ${LOGFILE}
|
1156
|
echo "-o label=${FSLABEL} -o publisher=\"${PRODUCT_NAME} project.\" $ISOPATH ${FINAL_CHROOT_DIR}" | tee -a ${LOGFILE}
|
1157
|
|
1158
|
create_distribution_tarball
|
1159
|
|
1160
|
# Remove /rescue from iso since cd9660 cannot deal with hardlinks
|
1161
|
rm -rf ${FINAL_CHROOT_DIR}/rescue
|
1162
|
|
1163
|
makefs -t cd9660 -o bootimage="i386;${FINAL_CHROOT_DIR}/boot/cdboot" -o no-emul-boot -o rockridge \
|
1164
|
-o label=${FSLABEL} -o publisher="${PRODUCT_NAME} project." $ISOPATH ${FINAL_CHROOT_DIR} 2>&1 >> ${LOGFILE}
|
1165
|
if [ $? -ne 0 -o ! -f $ISOPATH ]; then
|
1166
|
if [ -f ${ISOPATH} ]; then
|
1167
|
rm -f $ISOPATH
|
1168
|
fi
|
1169
|
echo ">>> ERROR: Something wrong happened during ISO image creation. STOPPING!" | tee -a ${LOGFILE}
|
1170
|
print_error_pfS
|
1171
|
fi
|
1172
|
gzip -qf $ISOPATH &
|
1173
|
|
1174
|
echo ">>> ISO created: $(LC_ALL=C date)" | tee -a ${LOGFILE}
|
1175
|
}
|
1176
|
|
1177
|
create_memstick_image() {
|
1178
|
|
1179
|
LOGFILE=${BUILDER_LOGS}/memstick.${TARGET}
|
1180
|
if [ "${MEMSTICKPATH}" = "" ]; then
|
1181
|
echo ">>> MEMSTICKPATH is empty skipping generation of memstick image!" | tee -a ${LOGFILE}
|
1182
|
return
|
1183
|
fi
|
1184
|
|
1185
|
if [ ! -d ${FINAL_CHROOT_DIR}/boot ]; then
|
1186
|
customize_stagearea_for_image "memstick"
|
1187
|
install_default_kernel ${DEFAULT_KERNEL}
|
1188
|
fi
|
1189
|
|
1190
|
echo cdrom > $FINAL_CHROOT_DIR/etc/platform
|
1191
|
|
1192
|
echo ">>> Creating memstick to ${MEMSTICKPATH}." 2>&1 | tee -a ${LOGFILE}
|
1193
|
echo "/dev/ufs/${PRODUCT_NAME} / ufs ro 0 0" > ${FINAL_CHROOT_DIR}/etc/fstab
|
1194
|
echo "kern.cam.boot_delay=10000" >> ${FINAL_CHROOT_DIR}/boot/loader.conf.local
|
1195
|
|
1196
|
create_distribution_tarball
|
1197
|
|
1198
|
makefs -B little -o label=${PRODUCT_NAME} ${MEMSTICKPATH} ${FINAL_CHROOT_DIR}
|
1199
|
if [ $? -ne 0 ]; then
|
1200
|
if [ -f ${MEMSTICKPATH} ]; then
|
1201
|
rm -f $MEMSTICKPATH
|
1202
|
fi
|
1203
|
echo ">>> ERROR: Something wrong happened during MEMSTICK image creation. STOPPING!" | tee -a ${LOGFILE}
|
1204
|
print_error_pfS
|
1205
|
fi
|
1206
|
MD=$(mdconfig -a -t vnode -f $MEMSTICKPATH)
|
1207
|
# Just in case
|
1208
|
trap "mdconfig -d -u ${MD}" 1 2 15 EXIT
|
1209
|
gpart create -s BSD ${MD} 2>&1 >> ${LOGFILE}|
|
1210
|
gpart bootcode -b ${FINAL_CHROOT_DIR}/boot/boot ${MD} 2>&1 >> ${LOGFILE}
|
1211
|
gpart add -t freebsd-ufs ${MD} 2>&1 >> ${LOGFILE}
|
1212
|
trap "-" 1 2 15 EXIT
|
1213
|
mdconfig -d -u ${MD} 2>&1 | tee -a ${LOGFILE}
|
1214
|
gzip -qf $MEMSTICKPATH &
|
1215
|
|
1216
|
echo ">>> MEMSTICK created: $(LC_ALL=C date)" | tee -a ${LOGFILE}
|
1217
|
}
|
1218
|
|
1219
|
create_memstick_serial_image() {
|
1220
|
LOGFILE=${BUILDER_LOGS}/memstickserial.${TARGET}
|
1221
|
if [ "${MEMSTICKSERIALPATH}" = "" ]; then
|
1222
|
echo ">>> MEMSTICKSERIALPATH is empty skipping generation of memstick image!" | tee -a ${LOGFILE}
|
1223
|
return
|
1224
|
fi
|
1225
|
|
1226
|
if [ ! -d ${FINAL_CHROOT_DIR}/boot ]; then
|
1227
|
customize_stagearea_for_image "memstickserial"
|
1228
|
install_default_kernel ${DEFAULT_KERNEL}
|
1229
|
fi
|
1230
|
|
1231
|
echo cdrom > $FINAL_CHROOT_DIR/etc/platform
|
1232
|
|
1233
|
echo "/dev/ufs/${PRODUCT_NAME} / ufs ro 0 0" > ${FINAL_CHROOT_DIR}/etc/fstab
|
1234
|
echo "kern.cam.boot_delay=10000" >> ${FINAL_CHROOT_DIR}/boot/loader.conf.local
|
1235
|
|
1236
|
echo ">>> Creating serial memstick to ${MEMSTICKSERIALPATH}." 2>&1 | tee -a ${LOGFILE}
|
1237
|
|
1238
|
BOOTCONF=${FINAL_CHROOT_DIR}/boot.config
|
1239
|
LOADERCONF=${FINAL_CHROOT_DIR}/boot/loader.conf
|
1240
|
|
1241
|
echo ">>> Activating serial console..." 2>&1 | tee -a ${LOGFILE}
|
1242
|
# Activate serial console in boot.config
|
1243
|
if [ -f ${BOOTCONF} ]; then
|
1244
|
sed -i "" '/-D$/d' ${BOOTCONF}
|
1245
|
fi
|
1246
|
echo "-S115200 -D" >> ${BOOTCONF}
|
1247
|
|
1248
|
# Remove old console options if present.
|
1249
|
[ -f "${LOADERCONF}" ] \
|
1250
|
&& sed -i "" -Ee "/(console|boot_multicons|boot_serial)/d" ${LOADERCONF}
|
1251
|
# Activate serial console+video console in loader.conf
|
1252
|
echo 'boot_multicons="YES"' >> ${LOADERCONF}
|
1253
|
echo 'boot_serial="YES"' >> ${LOADERCONF}
|
1254
|
echo 'console="comconsole,vidconsole"' >> ${LOADERCONF}
|
1255
|
echo 'comconsole_speed="115200"' >> ${LOADERCONF}
|
1256
|
|
1257
|
create_distribution_tarball
|
1258
|
|
1259
|
makefs -B little -o label=${PRODUCT_NAME} ${MEMSTICKSERIALPATH} ${FINAL_CHROOT_DIR}
|
1260
|
if [ $? -ne 0 ]; then
|
1261
|
if [ -f ${MEMSTICKSERIALPATH} ]; then
|
1262
|
rm -f $MEMSTICKSERIALPATH
|
1263
|
fi
|
1264
|
echo ">>> ERROR: Something wrong happened during MEMSTICKSERIAL image creation. STOPPING!" | tee -a ${LOGFILE}
|
1265
|
print_error_pfS
|
1266
|
fi
|
1267
|
MD=$(mdconfig -a -t vnode -f $MEMSTICKSERIALPATH)
|
1268
|
# Just in case
|
1269
|
trap "mdconfig -d -u ${MD}" 1 2 15 EXIT
|
1270
|
gpart create -s BSD ${MD} 2>&1 >> ${LOGFILE}
|
1271
|
gpart bootcode -b ${FINAL_CHROOT_DIR}/boot/boot ${MD} 2>&1 >> ${LOGFILE}
|
1272
|
gpart add -t freebsd-ufs ${MD} 2>&1 >> ${LOGFILE}
|
1273
|
trap "-" 1 2 15 EXIT
|
1274
|
mdconfig -d -u ${MD} 2>&1 >> ${LOGFILE}
|
1275
|
gzip -qf $MEMSTICKSERIALPATH &
|
1276
|
|
1277
|
echo ">>> MEMSTICKSERIAL created: $(LC_ALL=C date)" | tee -a ${LOGFILE}
|
1278
|
}
|
1279
|
|
1280
|
create_memstick_adi_image() {
|
1281
|
LOGFILE=${BUILDER_LOGS}/memstickadi${TARGET}
|
1282
|
if [ "${MEMSTICKADIPATH}" = "" ]; then
|
1283
|
echo ">>> MEMSTICKADIPATH is empty skipping generation of memstick image!" | tee -a ${LOGFILE}
|
1284
|
return
|
1285
|
fi
|
1286
|
|
1287
|
if [ ! -d ${FINAL_CHROOT_DIR}/boot ]; then
|
1288
|
customize_stagearea_for_image "memstickadi"
|
1289
|
install_default_kernel ${DEFAULT_KERNEL}
|
1290
|
fi
|
1291
|
|
1292
|
echo cdrom > $FINAL_CHROOT_DIR/etc/platform
|
1293
|
|
1294
|
echo "/dev/ufs/${PRODUCT_NAME} / ufs ro 0 0" > ${FINAL_CHROOT_DIR}/etc/fstab
|
1295
|
echo "kern.cam.boot_delay=10000" >> ${FINAL_CHROOT_DIR}/boot/loader.conf.local
|
1296
|
|
1297
|
echo ">>> Creating serial memstick to ${MEMSTICKADIPATH}." 2>&1 | tee -a ${LOGFILE}
|
1298
|
|
1299
|
BOOTCONF=${FINAL_CHROOT_DIR}/boot.config
|
1300
|
LOADERCONF=${FINAL_CHROOT_DIR}/boot/loader.conf
|
1301
|
|
1302
|
echo ">>> Activating serial console..." 2>&1 | tee -a ${LOGFILE}
|
1303
|
# Activate serial console in boot.config
|
1304
|
if [ -f ${BOOTCONF} ]; then
|
1305
|
sed -i "" '/-[Dh]$/d' ${BOOTCONF}
|
1306
|
fi
|
1307
|
echo "-S115200 -h" >> ${BOOTCONF}
|
1308
|
|
1309
|
# Remove old console options if present.
|
1310
|
[ -f "${LOADERCONF}" ] \
|
1311
|
&& sed -i "" -Ee "/(console|boot_multicons|boot_serial|hint.uart)/d" ${LOADERCONF}
|
1312
|
# Activate serial console+video console in loader.conf
|
1313
|
echo 'boot_serial="YES"' >> ${LOADERCONF}
|
1314
|
echo 'console="comconsole"' >> ${LOADERCONF}
|
1315
|
echo 'comconsole_speed="115200"' >> ${LOADERCONF}
|
1316
|
echo 'comconsole_port="0x2F8"' >> ${LOADERCONF}
|
1317
|
echo 'hint.uart.0.flags="0x00"' >> ${LOADERCONF}
|
1318
|
echo 'hint.uart.1.flags="0x10"' >> ${LOADERCONF}
|
1319
|
|
1320
|
create_distribution_tarball
|
1321
|
|
1322
|
makefs -B little -o label=${PRODUCT_NAME} ${MEMSTICKADIPATH} ${FINAL_CHROOT_DIR}
|
1323
|
if [ $? -ne 0 ]; then
|
1324
|
if [ -f ${MEMSTICKADIPATH} ]; then
|
1325
|
rm -f $MEMSTICKADIPATH
|
1326
|
fi
|
1327
|
echo ">>> ERROR: Something wrong happened during MEMSTICKADI image creation. STOPPING!" | tee -a ${LOGFILE}
|
1328
|
print_error_pfS
|
1329
|
fi
|
1330
|
MD=$(mdconfig -a -t vnode -f $MEMSTICKADIPATH)
|
1331
|
# Just in case
|
1332
|
trap "mdconfig -d -u ${MD}" 1 2 15 EXIT
|
1333
|
gpart create -s BSD ${MD} 2>&1 >> ${LOGFILE}
|
1334
|
gpart bootcode -b ${FINAL_CHROOT_DIR}/boot/boot ${MD} 2>&1 >> ${LOGFILE}
|
1335
|
gpart add -t freebsd-ufs ${MD} 2>&1 >> ${LOGFILE}
|
1336
|
trap "-" 1 2 15 EXIT
|
1337
|
mdconfig -d -u ${MD} 2>&1 >> ${LOGFILE}
|
1338
|
gzip -qf $MEMSTICKADIPATH &
|
1339
|
|
1340
|
echo ">>> MEMSTICKADI created: $(LC_ALL=C date)" | tee -a ${LOGFILE}
|
1341
|
}
|
1342
|
|
1343
|
# Create pkg conf on desired place with desired arch/branch
|
1344
|
setup_pkg_repo() {
|
1345
|
if [ -z "${4}" ]; then
|
1346
|
return
|
1347
|
fi
|
1348
|
|
1349
|
local _target="${1}"
|
1350
|
local _arch="${2}"
|
1351
|
local _target_arch="${3}"
|
1352
|
local _branch="${4}"
|
1353
|
|
1354
|
mkdir -p $(dirname ${_target}) >/dev/null 2>&1
|
1355
|
|
1356
|
sed \
|
1357
|
-e "s/%%ARCH%%/${_arch}_${_target_arch}/" \
|
1358
|
-e "s/%%GIT_REPO_BRANCH_OR_TAG%%/${_branch}/g" \
|
1359
|
-e "s,%%PKG_REPO_SERVER%%,${PKG_REPO_SERVER},g" \
|
1360
|
-e "s/%%PRODUCT_NAME%%/${PRODUCT_NAME}/g" \
|
1361
|
${FREEBSD_SRC_DIR}/release/pkg_repos/${PRODUCT_NAME}.conf.template \
|
1362
|
> ${_target}
|
1363
|
}
|
1364
|
|
1365
|
# This routine ensures any ports / binaries that the builder
|
1366
|
# system needs are on disk and ready for execution.
|
1367
|
builder_setup() {
|
1368
|
# If Product-builder is already installed, just leave
|
1369
|
if pkg info -e -q ${PRODUCT_NAME}-builder; then
|
1370
|
return
|
1371
|
fi
|
1372
|
|
1373
|
if [ ! -f /usr/local/etc/pkg/repos/${PRODUCT_NAME}.conf ]; then
|
1374
|
[ -d /usr/local/etc/pkg/repos ] \
|
1375
|
|| mkdir -p /usr/local/etc/pkg/repos
|
1376
|
|
1377
|
local _arch=$(uname -m)
|
1378
|
setup_pkg_repo /usr/local/etc/pkg/repos/${PRODUCT_NAME}.conf ${_arch} ${_arch} ${PKG_REPO_CONF_BRANCH}
|
1379
|
fi
|
1380
|
|
1381
|
pkg install ${PRODUCT_NAME}-builder
|
1382
|
}
|
1383
|
|
1384
|
# Updates FreeBSD sources
|
1385
|
update_freebsd_sources() {
|
1386
|
if [ "${1}" = "full" ]; then
|
1387
|
local _full=1
|
1388
|
local _clone_params=""
|
1389
|
else
|
1390
|
local _full=0
|
1391
|
local _clone_params="--depth 1 --single-branch"
|
1392
|
fi
|
1393
|
|
1394
|
if [ ! -d "${FREEBSD_SRC_DIR}" ]; then
|
1395
|
mkdir -p ${FREEBSD_SRC_DIR}
|
1396
|
fi
|
1397
|
|
1398
|
if [ -n "${NO_BUILDWORLD:-}" -a -n "${NO_BUILDKERNEL:-}" ]; then
|
1399
|
echo ">>> NO_BUILDWORLD and NO_BUILDKERNEL set, skipping update of freebsd sources" | tee -a ${LOGFILE}
|
1400
|
return
|
1401
|
fi
|
1402
|
|
1403
|
echo -n ">>> Obtaining FreeBSD sources ${FREEBSD_BRANCH}..."
|
1404
|
local _FREEBSD_BRANCH=${FREEBSD_BRANCH:-"devel"}
|
1405
|
local _CLONE=1
|
1406
|
|
1407
|
if [ -d "${FREEBSD_SRC_DIR}/.git" ]; then
|
1408
|
CUR_BRANCH=$(cd ${FREEBSD_SRC_DIR} && git branch | grep '^\*' | cut -d' ' -f2)
|
1409
|
if [ ${_full} -eq 0 -a "${CUR_BRANCH}" = "${_FREEBSD_BRANCH}" ]; then
|
1410
|
_CLONE=0
|
1411
|
( cd ${FREEBSD_SRC_DIR} && git clean -fxd; git fetch origin; git reset --hard origin/${_FREEBSD_BRANCH} ) 2>&1 | grep -C3 -i -E 'error|fatal'
|
1412
|
else
|
1413
|
rm -rf ${FREEBSD_SRC_DIR}
|
1414
|
fi
|
1415
|
fi
|
1416
|
|
1417
|
if [ ${_CLONE} -eq 1 ]; then
|
1418
|
( git clone --branch ${_FREEBSD_BRANCH} ${_clone_params} ${FREEBSD_REPO_BASE} ${FREEBSD_SRC_DIR} ) 2>&1 | grep -C3 -i -E 'error|fatal'
|
1419
|
fi
|
1420
|
|
1421
|
if [ ! -d "${FREEBSD_SRC_DIR}/.git" ]; then
|
1422
|
echo ">>> ERROR: It was not possible to clone FreeBSD src repo"
|
1423
|
print_error_pfS
|
1424
|
fi
|
1425
|
|
1426
|
if [ -n "${GIT_FREEBSD_COSHA1}" ]; then
|
1427
|
( cd ${FREEBSD_SRC_DIR} && git checkout ${GIT_FREEBSD_COSHA1} ) 2>&1 | grep -C3 -i -E 'error|fatal'
|
1428
|
fi
|
1429
|
echo "Done!"
|
1430
|
}
|
1431
|
|
1432
|
pkg_chroot() {
|
1433
|
local _root="${1}"
|
1434
|
shift
|
1435
|
|
1436
|
if [ $# -eq 0 ]; then
|
1437
|
return -1
|
1438
|
fi
|
1439
|
|
1440
|
if [ -z "${_root}" -o "${_root}" = "/" -o ! -d "${_root}" ]; then
|
1441
|
return -1
|
1442
|
fi
|
1443
|
|
1444
|
mkdir -p \
|
1445
|
${SCRATCHDIR}/pkg_cache \
|
1446
|
${_root}/var/cache/pkg \
|
1447
|
${_root}/dev
|
1448
|
|
1449
|
/sbin/mount -t nullfs ${SCRATCHDIR}/pkg_cache ${_root}/var/cache/pkg
|
1450
|
/sbin/mount -t devfs devfs ${_root}/dev
|
1451
|
cp -f /etc/resolv.conf ${_root}/etc/resolv.conf
|
1452
|
touch ${BUILDER_LOGS}/install_pkg_install_ports.txt
|
1453
|
script -aq ${BUILDER_LOGS}/install_pkg_install_ports.txt pkg -c ${_root} $@ >/dev/null 2>&1
|
1454
|
rm -f ${_root}/etc/resolv.conf
|
1455
|
/sbin/umount -f ${_root}/dev
|
1456
|
/sbin/umount -f ${_root}/var/cache/pkg
|
1457
|
}
|
1458
|
|
1459
|
|
1460
|
pkg_chroot_add() {
|
1461
|
if [ -z "${1}" -o -z "${2}" ]; then
|
1462
|
return 1
|
1463
|
fi
|
1464
|
|
1465
|
local _target="${1}"
|
1466
|
local _pkg="$(get_pkg_name ${2}).txz"
|
1467
|
|
1468
|
if [ ! -d "${_target}" ]; then
|
1469
|
echo ">>> ERROR: Target dir ${_target} not found"
|
1470
|
print_error_pfS
|
1471
|
fi
|
1472
|
|
1473
|
if [ ! -f ${CORE_PKG_PATH}/All/${_pkg} ]; then
|
1474
|
echo ">>> ERROR: Package ${_pkg} not found"
|
1475
|
print_error_pfS
|
1476
|
fi
|
1477
|
|
1478
|
cp ${CORE_PKG_PATH}/All/${_pkg} ${_target}
|
1479
|
pkg_chroot ${_target} add /${_pkg}
|
1480
|
rm -f ${_target}/${_pkg}
|
1481
|
}
|
1482
|
|
1483
|
pkg_bootstrap() {
|
1484
|
local _root=${1:-"${STAGE_CHROOT_DIR}"}
|
1485
|
|
1486
|
setup_pkg_repo ${_root}/usr/local/etc/pkg/repos/${PRODUCT_NAME}.conf ${TARGET} ${TARGET_ARCH} ${PKG_REPO_CONF_BRANCH}
|
1487
|
|
1488
|
pkg_chroot ${_root} bootstrap -f
|
1489
|
}
|
1490
|
|
1491
|
# This routine assists with installing various
|
1492
|
# freebsd ports files into the pfsenese-fs staging
|
1493
|
# area.
|
1494
|
install_pkg_install_ports() {
|
1495
|
local MAIN_PKG="${1}"
|
1496
|
|
1497
|
if [ -z "${MAIN_PKG}" ]; then
|
1498
|
MAIN_PKG=${PRODUCT_NAME}
|
1499
|
fi
|
1500
|
|
1501
|
echo ">>> Installing pkg repository in chroot (${STAGE_CHROOT_DIR})..."
|
1502
|
|
1503
|
[ -d ${STAGE_CHROOT_DIR}/var/cache/pkg ] || \
|
1504
|
mkdir -p ${STAGE_CHROOT_DIR}/var/cache/pkg
|
1505
|
|
1506
|
[ -d ${SCRATCHDIR}/pkg_cache ] || \
|
1507
|
mkdir -p ${SCRATCHDIR}/pkg_cache
|
1508
|
|
1509
|
echo ">>> Installing built ports (packages) in chroot (${STAGE_CHROOT_DIR})... (starting)"
|
1510
|
pkg_chroot ${STAGE_CHROOT_DIR} install ${MAIN_PKG} ${custom_package_list}
|
1511
|
pkg_chroot ${STAGE_CHROOT_DIR} autoremove
|
1512
|
echo ">>> Installing built ports (packages) in chroot (${STAGE_CHROOT_DIR})... (finshied)"
|
1513
|
}
|
1514
|
|
1515
|
install_bsdinstaller() {
|
1516
|
echo ">>> Installing BSDInstaller in chroot (${FINAL_CHROOT_DIR})... (starting)"
|
1517
|
pkg_chroot ${FINAL_CHROOT_DIR} install -f bsdinstaller ${MAIN_PKG} ${custom_package_list}
|
1518
|
echo ">>> Installing BSDInstaller in chroot (${FINAL_CHROOT_DIR})... (finished)"
|
1519
|
}
|
1520
|
|
1521
|
staginareas_clean_each_run() {
|
1522
|
echo -n ">>> Cleaning build directories: "
|
1523
|
if [ -d "${FINAL_CHROOT_DIR}" ]; then
|
1524
|
BASENAME=$(basename ${FINAL_CHROOT_DIR})
|
1525
|
echo -n "$BASENAME "
|
1526
|
chflags -R noschg ${FINAL_CHROOT_DIR} 2>&1 >/dev/null
|
1527
|
rm -rf ${FINAL_CHROOT_DIR}/* 2>/dev/null
|
1528
|
fi
|
1529
|
echo "Done!"
|
1530
|
}
|
1531
|
|
1532
|
# Imported from FreeSBIE
|
1533
|
buildkernel() {
|
1534
|
if [ -n "${NO_BUILDKERNEL:-}" ]; then
|
1535
|
echo ">>> NO_BUILDKERNEL set, skipping build" | tee -a ${LOGFILE}
|
1536
|
return
|
1537
|
fi
|
1538
|
|
1539
|
if [ -z "${KERNCONF:-}" ]; then
|
1540
|
echo ">>> ERROR: No kernel configuration defined probably this is not what you want! STOPPING!" | tee -a ${LOGFILE}
|
1541
|
print_error_pfS
|
1542
|
fi
|
1543
|
|
1544
|
if [ -n "${KERNELCONF:-}" ]; then
|
1545
|
export KERNCONFDIR=$(dirname ${KERNELCONF})
|
1546
|
export KERNCONF=$(basename ${KERNELCONF})
|
1547
|
fi
|
1548
|
|
1549
|
SRCCONFBASENAME=$(basename ${SRC_CONF})
|
1550
|
echo ">>> KERNCONFDIR: ${KERNCONFDIR}"
|
1551
|
echo ">>> ARCH: ${TARGET}"
|
1552
|
echo ">>> SRC_CONF: ${SRCCONFBASENAME}"
|
1553
|
|
1554
|
makeargs="${MAKEJ_KERNEL:-} SRCCONF=${SRC_CONF} __MAKE_CONF=${MAKE_CONF} TARGET_ARCH=${TARGET_ARCH} TARGET=${TARGET}"
|
1555
|
echo ">>> Builder is running the command: script -aq $LOGFILE make -DNO_KERNELCLEAN $makeargs buildkernel KERNCONF=${KERNCONF}" | tee -a $LOGFILE
|
1556
|
(script -q $LOGFILE make -C ${FREEBSD_SRC_DIR} -DNO_KERNELCLEAN $makeargs buildkernel KERNCONF=${KERNCONF} || print_error_pfS;) | egrep '^>>>'
|
1557
|
}
|
1558
|
|
1559
|
# Imported from FreeSBIE
|
1560
|
installkernel() {
|
1561
|
if [ -z "${KERNCONF:-}" ]; then
|
1562
|
echo ">>> ERROR: No kernel configuration defined probably this is not what you want! STOPPING!" | tee -a ${LOGFILE}
|
1563
|
print_error_pfS
|
1564
|
fi
|
1565
|
|
1566
|
if [ -n "${KERNELCONF:-}" ]; then
|
1567
|
export KERNCONFDIR=$(dirname ${KERNELCONF})
|
1568
|
export KERNCONF=$(basename ${KERNELCONF})
|
1569
|
fi
|
1570
|
|
1571
|
mkdir -p ${STAGE_CHROOT_DIR}/boot
|
1572
|
makeargs="${MAKEJ_KERNEL:-} SRCCONF=${SRC_CONF} __MAKE_CONF=${MAKE_CONF} TARGET_ARCH=${TARGET_ARCH} TARGET=${TARGET} DESTDIR=${KERNEL_DESTDIR}"
|
1573
|
echo ">>> Builder is running the command: script -aq $LOGFILE make ${makeargs:-} installkernel KERNCONF=${KERNCONF}" | tee -a $LOGFILE
|
1574
|
(script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR} ${makeargs:-} installkernel KERNCONF=${KERNCONF} || print_error_pfS;) | egrep '^>>>'
|
1575
|
gzip -f9 $KERNEL_DESTDIR/boot/kernel/kernel
|
1576
|
}
|
1577
|
|
1578
|
# Launch is ran first to setup a few variables that we need
|
1579
|
# Imported from FreeSBIE
|
1580
|
launch() {
|
1581
|
if [ "$(id -u)" != "0" ]; then
|
1582
|
echo "Sorry, this must be done as root."
|
1583
|
fi
|
1584
|
|
1585
|
echo ">>> Operation $0 has started at $(date)"
|
1586
|
}
|
1587
|
|
1588
|
finish() {
|
1589
|
echo ">>> Operation $0 has ended at $(date)"
|
1590
|
}
|
1591
|
|
1592
|
pkg_repo_rsync() {
|
1593
|
local _repo_path="${1}"
|
1594
|
|
1595
|
if [ -z "${DO_NOT_UPLOAD}" -o -z "${_repo_path}" -o ! -d "${_repo_path}" ]; then
|
1596
|
return
|
1597
|
fi
|
1598
|
|
1599
|
if [ -z "${LOGFILE}" ]; then
|
1600
|
local _logfile="/dev/null"
|
1601
|
else
|
1602
|
local _logfile="${LOGFILE}"
|
1603
|
fi
|
1604
|
|
1605
|
echo -n ">>> Sending updated repository to ${PKG_RSYNC_HOSTNAME}... " | tee -a ${_logfile}
|
1606
|
if script -aq ${_logfile} rsync -ave "ssh -p ${PKG_RSYNC_SSH_PORT}" \
|
1607
|
--timeout=60 --delete-delay ${_repo_path} \
|
1608
|
${PKG_RSYNC_USERNAME}@${PKG_RSYNC_HOSTNAME}:${PKG_RSYNC_DESTDIR} >/dev/null 2>&1
|
1609
|
then
|
1610
|
echo "Done!" | tee -a ${_logfile}
|
1611
|
else
|
1612
|
echo "Failed!" | tee -a ${_logfile}
|
1613
|
echo ">>> ERROR: An error occurred sending repo to remote hostname"
|
1614
|
print_error_pfS
|
1615
|
fi
|
1616
|
}
|
1617
|
|
1618
|
poudriere_create_patch() {
|
1619
|
local _jail_patch="${SCRATCHDIR}/poudriere_jail.${GIT_REPO_BRANCH_OR_TAG}.patch"
|
1620
|
|
1621
|
if [ -z "${FREEBSD_PARENT_BRANCH}" ]; then
|
1622
|
echo ">>> ERROR: FREEBSD_PARENT_BRANCH is not set"
|
1623
|
fi
|
1624
|
|
1625
|
LOGFILE=${BUILDER_LOGS}/poudriere.log
|
1626
|
|
1627
|
# Get FreeBSD source and apply patches
|
1628
|
update_freebsd_sources full
|
1629
|
|
1630
|
[ -f "${_jail_patch}" ] && \
|
1631
|
rm -f "${_jail_patch}"
|
1632
|
|
1633
|
# Create a big patch with all our changes to use on jail
|
1634
|
( \
|
1635
|
cd ${FREEBSD_SRC_DIR} && \
|
1636
|
git diff $(git merge-base origin/${FREEBSD_PARENT_BRANCH} ${FREEBSD_BRANCH}) > ${_jail_patch}
|
1637
|
) >/dev/null 2>&1
|
1638
|
|
1639
|
# Check if patch was created
|
1640
|
if [ ! -s "${_jail_patch}" ]; then
|
1641
|
echo ">>> ERROR: Patch does not exist or is empty, aborting..." | tee -a ${LOGFILE}
|
1642
|
print_error_pfS
|
1643
|
fi
|
1644
|
}
|
1645
|
|
1646
|
poudriere_possible_archs() {
|
1647
|
local _arch=$(uname -m)
|
1648
|
local _archs="i386.i386"
|
1649
|
|
1650
|
# IF host is amd64, we'll create both repos, and if possible armv6
|
1651
|
if [ "${_arch}" = "amd64" ]; then
|
1652
|
_archs="amd64.amd64 ${_archs}"
|
1653
|
|
1654
|
if [ -f /usr/local/bin/qemu-arm-static ]; then
|
1655
|
# Make sure binmiscctl is ok
|
1656
|
/usr/local/etc/rc.d/qemu_user_static forcestart >/dev/null 2>&1
|
1657
|
|
1658
|
if binmiscctl lookup armv6 >/dev/null 2>&1; then
|
1659
|
_archs="${_archs} arm.armv6"
|
1660
|
fi
|
1661
|
fi
|
1662
|
fi
|
1663
|
|
1664
|
echo ${_archs}
|
1665
|
}
|
1666
|
|
1667
|
poudriere_jail_name() {
|
1668
|
local _jail_arch="${1}"
|
1669
|
|
1670
|
if [ -z "${_jail_arch}" ]; then
|
1671
|
return 1
|
1672
|
fi
|
1673
|
|
1674
|
# Poudriere doesn't like periods in jail names
|
1675
|
_jail_arch=$(echo "${_jail_arch}" | tr '.' '_')
|
1676
|
|
1677
|
echo "${PRODUCT_NAME}_${GIT_REPO_BRANCH_OR_TAG}_${_jail_arch}"
|
1678
|
}
|
1679
|
|
1680
|
poudriere_create_ports_tree() {
|
1681
|
LOGFILE=${BUILDER_LOGS}/poudriere.log
|
1682
|
|
1683
|
if ! poudriere ports -l | grep -q -E "^${POUDRIERE_PORTS_NAME}[[:blank:]]"; then
|
1684
|
local _branch=""
|
1685
|
if [ -z "${POUDRIERE_PORTS_GIT_URL}" ]; then
|
1686
|
echo ">>> ERROR: POUDRIERE_PORTS_GIT_URL is not defined"
|
1687
|
print_error_pfS
|
1688
|
fi
|
1689
|
if [ -n "${POUDRIERE_PORTS_GIT_BRANCH}" ]; then
|
1690
|
_branch="-B ${POUDRIERE_PORTS_GIT_BRANCH}"
|
1691
|
fi
|
1692
|
echo -n ">>> Creating poudriere ports tree, it may take some time... " | tee -a ${LOGFILE}
|
1693
|
if ! script -aq ${LOGFILE} poudriere ports -c -p "${POUDRIERE_PORTS_NAME}" -m git ${_branch} >/dev/null 2>&1; then
|
1694
|
echo "" | tee -a ${LOGFILE}
|
1695
|
echo ">>> ERROR: Error creating poudriere ports tree, aborting..." | tee -a ${LOGFILE}
|
1696
|
print_error_pfS
|
1697
|
fi
|
1698
|
echo "Done!" | tee -a ${LOGFILE}
|
1699
|
fi
|
1700
|
}
|
1701
|
|
1702
|
poudriere_init() {
|
1703
|
local _error=0
|
1704
|
local _archs=$(poudriere_possible_archs)
|
1705
|
local _jail_patch="${SCRATCHDIR}/poudriere_jail.${GIT_REPO_BRANCH_OR_TAG}.patch"
|
1706
|
|
1707
|
LOGFILE=${BUILDER_LOGS}/poudriere.log
|
1708
|
|
1709
|
# Sanity checks
|
1710
|
if [ -z "${ZFS_TANK}" ]; then
|
1711
|
echo ">>> ERROR: \$ZFS_TANK is empty" | tee -a ${LOGFILE}
|
1712
|
error=1
|
1713
|
fi
|
1714
|
|
1715
|
if [ -z "${ZFS_ROOT}" ]; then
|
1716
|
echo ">>> ERROR: \$ZFS_ROOT is empty" | tee -a ${LOGFILE}
|
1717
|
error=1
|
1718
|
fi
|
1719
|
|
1720
|
if [ -z "${POUDRIERE_PORTS_NAME}" ]; then
|
1721
|
echo ">>> ERROR: \$POUDRIERE_PORTS_NAME is empty" | tee -a ${LOGFILE}
|
1722
|
error=1
|
1723
|
fi
|
1724
|
|
1725
|
if [ ${_error} -eq 1 ]; then
|
1726
|
print_error_pfS
|
1727
|
fi
|
1728
|
|
1729
|
# Check if zpool exists
|
1730
|
if ! zpool list ${ZFS_TANK} >/dev/null 2>&1; then
|
1731
|
echo ">>> ERROR: ZFS tank ${ZFS_TANK} not found, please create it and try again..." | tee -a ${LOGFILE}
|
1732
|
print_error_pfS
|
1733
|
fi
|
1734
|
|
1735
|
# Check if zfs rootfs exists
|
1736
|
if ! zfs list ${ZFS_TANK}${ZFS_ROOT} >/dev/null 2>&1; then
|
1737
|
echo ">>> ERROR: ZFS filesystem ${ZFS_TANK}${ZFS_ROOT} not found, please create it and try again..." | tee -a ${LOGFILE}
|
1738
|
print_error_pfS
|
1739
|
fi
|
1740
|
|
1741
|
# Make sure poudriere is installed
|
1742
|
if ! pkg info --quiet poudriere; then
|
1743
|
echo ">>> Installing poudriere..." | tee -a ${LOGFILE}
|
1744
|
if ! pkg install poudriere >/dev/null 2>&1; then
|
1745
|
echo ">>> ERROR: poudriere was not installed, aborting..." | tee -a ${LOGFILE}
|
1746
|
print_error_pfS
|
1747
|
fi
|
1748
|
fi
|
1749
|
|
1750
|
# Create poudriere.conf
|
1751
|
if [ -z "${POUDRIERE_PORTS_GIT_URL}" ]; then
|
1752
|
echo ">>> ERROR: POUDRIERE_PORTS_GIT_URL is not defined"
|
1753
|
print_error_pfS
|
1754
|
fi
|
1755
|
echo ">>> Creating poudriere.conf" | tee -a ${LOGFILE}
|
1756
|
cat <<EOF >/usr/local/etc/poudriere.conf
|
1757
|
ZPOOL=${ZFS_TANK}
|
1758
|
ZROOTFS=${ZFS_ROOT}
|
1759
|
RESOLV_CONF=/etc/resolv.conf
|
1760
|
BASEFS=/usr/local/poudriere
|
1761
|
USE_PORTLINT=no
|
1762
|
USE_TMPFS=yes
|
1763
|
NOLINUX=yes
|
1764
|
DISTFILES_CACHE=/usr/ports/distfiles
|
1765
|
CHECK_CHANGED_OPTIONS=yes
|
1766
|
CHECK_CHANGED_DEPS=yes
|
1767
|
ATOMIC_PACKAGE_REPOSITORY=yes
|
1768
|
COMMIT_PACKAGES_ON_FAILURE=no
|
1769
|
GIT_URL="${POUDRIERE_PORTS_GIT_URL}"
|
1770
|
EOF
|
1771
|
|
1772
|
# Remove old jails
|
1773
|
for jail_arch in ${_archs}; do
|
1774
|
jail_name=$(poudriere_jail_name ${jail_arch})
|
1775
|
|
1776
|
if poudriere jail -i -j "${jail_name}" >/dev/null 2>&1; then
|
1777
|
echo ">>> Poudriere jail ${jail_name} already exists, deleting it..." | tee -a ${LOGFILE}
|
1778
|
poudriere jail -d -j "${jail_name}" >/dev/null 2>&1
|
1779
|
fi
|
1780
|
done
|
1781
|
|
1782
|
# Remove old ports tree
|
1783
|
if poudriere ports -l | grep -q -E "^${POUDRIERE_PORTS_NAME}[[:blank:]]"; then
|
1784
|
echo ">>> Poudriere ports tree ${POUDRIERE_PORTS_NAME} already exists, deleting it..." | tee -a ${LOGFILE}
|
1785
|
poudriere ports -d -p "${POUDRIERE_PORTS_NAME}"
|
1786
|
fi
|
1787
|
|
1788
|
poudriere_create_patch
|
1789
|
|
1790
|
local native_xtools=""
|
1791
|
# Now we are ready to create jails
|
1792
|
for jail_arch in ${_archs}; do
|
1793
|
jail_name=$(poudriere_jail_name ${jail_arch})
|
1794
|
|
1795
|
if [ "${jail_arch}" = "arm.armv6" ]; then
|
1796
|
native_xtools="-x"
|
1797
|
else
|
1798
|
native_xtools=""
|
1799
|
fi
|
1800
|
|
1801
|
echo -n ">>> Creating jail ${jail_name}, it may take some time... " | tee -a ${LOGFILE}
|
1802
|
# XXX: Change -m to git when it's available in poudriere
|
1803
|
if ! script -aq ${LOGFILE} poudriere jail -c -j "${jail_name}" -v ${FREEBSD_PARENT_BRANCH} \
|
1804
|
-a ${jail_arch} -m svn -P ${_jail_patch} ${native_xtools} >/dev/null 2>&1; then
|
1805
|
echo "" | tee -a ${LOGFILE}
|
1806
|
echo ">>> ERROR: Error creating jail ${jail_name}, aborting..." | tee -a ${LOGFILE}
|
1807
|
print_error_pfS
|
1808
|
fi
|
1809
|
echo "Done!" | tee -a ${LOGFILE}
|
1810
|
done
|
1811
|
|
1812
|
poudriere_create_ports_tree
|
1813
|
|
1814
|
echo ">>> Poudriere is now configured!" | tee -a ${LOGFILE}
|
1815
|
}
|
1816
|
|
1817
|
poudriere_update_jails() {
|
1818
|
local _archs=$(poudriere_possible_archs)
|
1819
|
local _jail_patch="${SCRATCHDIR}/poudriere_jail.${GIT_REPO_BRANCH_OR_TAG}.patch"
|
1820
|
|
1821
|
LOGFILE=${BUILDER_LOGS}/poudriere.log
|
1822
|
|
1823
|
poudriere_create_patch
|
1824
|
|
1825
|
local native_xtools=""
|
1826
|
for jail_arch in ${_archs}; do
|
1827
|
local _run=0
|
1828
|
if [ -n "${ARCH_LIST}" ]; then
|
1829
|
for _arch in ${ARCH_LIST}; do
|
1830
|
if [ "${jail_arch##*.}" = "${_arch}" ]; then
|
1831
|
_run=1
|
1832
|
fi
|
1833
|
done
|
1834
|
else
|
1835
|
_run=1
|
1836
|
fi
|
1837
|
|
1838
|
[ ${_run} -eq 0 ] \
|
1839
|
&& continue
|
1840
|
|
1841
|
jail_name=$(poudriere_jail_name ${jail_arch})
|
1842
|
|
1843
|
if ! poudriere jail -i -j "${jail_name}" >/dev/null 2>&1; then
|
1844
|
echo ">>> Poudriere jail ${jail_name} not found, skipping..." | tee -a ${LOGFILE}
|
1845
|
continue
|
1846
|
fi
|
1847
|
|
1848
|
if [ "${jail_arch}" = "arm.armv6" ]; then
|
1849
|
native_xtools="-x"
|
1850
|
else
|
1851
|
native_xtools=""
|
1852
|
fi
|
1853
|
|
1854
|
echo -n ">>> Updating jail ${jail_name}, it may take some time... " | tee -a ${LOGFILE}
|
1855
|
if ! script -aq ${LOGFILE} poudriere jail -u -j "${jail_name}" -P ${_jail_patch} ${native_xtools} >/dev/null 2>&1; then
|
1856
|
echo "" | tee -a ${LOGFILE}
|
1857
|
echo ">>> ERROR: Error updating jail ${jail_name}, aborting..." | tee -a ${LOGFILE}
|
1858
|
print_error_pfS
|
1859
|
fi
|
1860
|
echo "Done!" | tee -a ${LOGFILE}
|
1861
|
done
|
1862
|
}
|
1863
|
|
1864
|
poudriere_update_ports() {
|
1865
|
LOGFILE=${BUILDER_LOGS}/poudriere.log
|
1866
|
|
1867
|
# Create ports tree if necessary
|
1868
|
if ! poudriere ports -l | grep -q -E "^${POUDRIERE_PORTS_NAME}[[:blank:]]"; then
|
1869
|
poudriere_create_ports_tree
|
1870
|
else
|
1871
|
echo -n ">>> Updating ports tree ${POUDRIERE_PORTS_NAME}... " | tee -a ${LOGFILE}
|
1872
|
script -aq ${LOGFILE} poudriere ports -u -p "${POUDRIERE_PORTS_NAME}" >/dev/null 2>&1
|
1873
|
echo "Done!" | tee -a ${LOGFILE}
|
1874
|
fi
|
1875
|
}
|
1876
|
|
1877
|
poudriere_bulk() {
|
1878
|
local _archs=$(poudriere_possible_archs)
|
1879
|
|
1880
|
LOGFILE=${BUILDER_LOGS}/poudriere.log
|
1881
|
|
1882
|
if [ -z "${DO_NOT_UPLOAD}" -a -z "${PKG_RSYNC_HOSTNAME}" ]; then
|
1883
|
echo ">>> ERROR: PKG_RSYNC_HOSTNAME is not set"
|
1884
|
print_error_pfS
|
1885
|
fi
|
1886
|
|
1887
|
poudriere_create_ports_tree
|
1888
|
|
1889
|
[ -d /usr/local/etc/poudriere.d ] || \
|
1890
|
mkdir -p /usr/local/etc/poudriere.d
|
1891
|
|
1892
|
if [ -f "${BUILDER_TOOLS}/conf/pfPorts/make.conf" ]; then
|
1893
|
cp -f "${BUILDER_TOOLS}/conf/pfPorts/make.conf" /usr/local/etc/poudriere.d/${POUDRIERE_PORTS_NAME}-make.conf
|
1894
|
fi
|
1895
|
|
1896
|
for jail_arch in ${_archs}; do
|
1897
|
jail_name=$(poudriere_jail_name ${jail_arch})
|
1898
|
|
1899
|
if ! poudriere jail -i -j "${jail_name}" >/dev/null 2>&1; then
|
1900
|
echo ">>> Poudriere jail ${jail_name} not found, skipping..." | tee -a ${LOGFILE}
|
1901
|
continue
|
1902
|
fi
|
1903
|
|
1904
|
if [ -f "${POUDRIERE_BULK}.${jail_arch}" ]; then
|
1905
|
_ref_bulk="${POUDRIERE_BULK}.${jail_arch}"
|
1906
|
else
|
1907
|
_ref_bulk="${POUDRIERE_BULK}"
|
1908
|
fi
|
1909
|
|
1910
|
_bulk=${SCRATCHDIR}/poudriere_bulk.${GIT_REPO_BRANCH_OR_TAG}
|
1911
|
sed -e "s,%%PRODUCT_NAME%%,${PRODUCT_NAME},g" ${_ref_bulk} > ${_bulk}
|
1912
|
|
1913
|
if ! poudriere bulk -f ${_bulk} -j ${jail_name} -p ${POUDRIERE_PORTS_NAME}; then
|
1914
|
echo ">>> ERROR: Something went wrong..."
|
1915
|
print_error_pfS
|
1916
|
fi
|
1917
|
|
1918
|
echo ">>> Cleaning up old packages from repo..."
|
1919
|
if ! poudriere pkgclean -f ${_bulk} -j ${jail_name} -p ${POUDRIERE_PORTS_NAME} -y; then
|
1920
|
echo ">>> ERROR: Something went wrong..."
|
1921
|
print_error_pfS
|
1922
|
fi
|
1923
|
|
1924
|
# ./ is intentional, it's a rsync trick to make it chdir to directory before send it
|
1925
|
pkg_repo_rsync "/usr/local/poudriere/data/packages/./${jail_name}-${POUDRIERE_PORTS_NAME}"
|
1926
|
done
|
1927
|
}
|
1928
|
|
1929
|
# This routine is called to write out to stdout
|
1930
|
# a string. The string is appended to $SNAPSHOTSLOGFILE
|
1931
|
# and we scp the log file to the builder host if
|
1932
|
# needed for the real time logging functions.
|
1933
|
snapshots_update_status() {
|
1934
|
if [ -z "${SNAPSHOTS}" -o -z "$1" ]; then
|
1935
|
return
|
1936
|
fi
|
1937
|
echo $1
|
1938
|
echo "`date` -|- $1" >> $SNAPSHOTSLOGFILE
|
1939
|
if [ -z "${DO_NOT_UPLOAD}" -a -n "${RSYNCIP}" ]; then
|
1940
|
LU=`cat $SNAPSHOTSLASTUPDATE`
|
1941
|
CT=`date "+%H%M%S"`
|
1942
|
# Only update every minute
|
1943
|
if [ "$LU" != "$CT" ]; then
|
1944
|
ssh ${RSYNCUSER}@${RSYNCIP} "mkdir -p ${RSYNCLOGS}"
|
1945
|
scp -q $SNAPSHOTSLOGFILE ${RSYNCUSER}@${RSYNCIP}:${RSYNC_LOGS}/build.log
|
1946
|
date "+%H%M%S" > $SNAPSHOTSLASTUPDATE
|
1947
|
fi
|
1948
|
fi
|
1949
|
}
|
1950
|
|
1951
|
# Copy the current log file to $filename.old on
|
1952
|
# the snapshot www server (real time logs)
|
1953
|
snapshots_rotate_logfile() {
|
1954
|
if [ -n "$MASTER_BUILDER_SSH_LOG_DEST" -a -z "${DO_NOT_UPLOAD}" ]; then
|
1955
|
scp -q $SNAPSHOTSLOGFILE ${RSYNCUSER}@${RSYNCIP}:${RSYNC_LOGS}/build.log.old
|
1956
|
fi
|
1957
|
|
1958
|
# Cleanup log file
|
1959
|
echo "" > $SNAPSHOTSLOGFILE
|
1960
|
}
|
1961
|
|
1962
|
snapshots_copy_to_staging_nanobsd() {
|
1963
|
for NANOTYPE in nanobsd nanobsd-vga; do
|
1964
|
for FILESIZE in ${1}; do
|
1965
|
FILENAMEFULL="${PRODUCT_NAME}-${PRODUCT_VERSION}-${FILESIZE}-${TARGET}-${NANOTYPE}${TIMESTAMP_SUFFIX}.img.gz"
|
1966
|
FILENAMEUPGRADE="${PRODUCT_NAME}-${PRODUCT_VERSION}-${FILESIZE}-${TARGET}-${NANOTYPE}-upgrade${TIMESTAMP_SUFFIX}.img.gz"
|
1967
|
mkdir -p $STAGINGAREA/nanobsd
|
1968
|
mkdir -p $STAGINGAREA/nanobsdupdates
|
1969
|
|
1970
|
cp $IMAGES_FINAL_DIR/$FILENAMEFULL $STAGINGAREA/nanobsd/ 2>/dev/null
|
1971
|
cp $IMAGES_FINAL_DIR/$FILENAMEUPGRADE $STAGINGAREA/nanobsdupdates 2>/dev/null
|
1972
|
|
1973
|
if [ -f $STAGINGAREA/nanobsd/$FILENAMEFULL ]; then
|
1974
|
md5 $STAGINGAREA/nanobsd/$FILENAMEFULL > $STAGINGAREA/nanobsd/$FILENAMEFULL.md5 2>/dev/null
|
1975
|
sha256 $STAGINGAREA/nanobsd/$FILENAMEFULL > $STAGINGAREA/nanobsd/$FILENAMEFULL.sha256 2>/dev/null
|
1976
|
fi
|
1977
|
if [ -f $STAGINGAREA/nanobsdupdates/$FILENAMEUPGRADE ]; then
|
1978
|
md5 $STAGINGAREA/nanobsdupdates/$FILENAMEUPGRADE > $STAGINGAREA/nanobsdupdates/$FILENAMEUPGRADE.md5 2>/dev/null
|
1979
|
sha256 $STAGINGAREA/nanobsdupdates/$FILENAMEUPGRADE > $STAGINGAREA/nanobsdupdates/$FILENAMEUPGRADE.sha256 2>/dev/null
|
1980
|
fi
|
1981
|
|
1982
|
# Copy NanoBSD auto update:
|
1983
|
if [ -f $STAGINGAREA/nanobsdupdates/$FILENAMEUPGRADE ]; then
|
1984
|
cp $STAGINGAREA/nanobsdupdates/$FILENAMEUPGRADE $STAGINGAREA/latest-${NANOTYPE}-$FILESIZE.img.gz 2>/dev/null
|
1985
|
sha256 $STAGINGAREA/latest-${NANOTYPE}-$FILESIZE.img.gz > $STAGINGAREA/latest-${NANOTYPE}-$FILESIZE.img.gz.sha256 2>/dev/null
|
1986
|
# NOTE: Updates need a file with output similar to date output
|
1987
|
# Use the file generated at start of snapshots_dobuilds() to be consistent on times
|
1988
|
cp $BUILTDATESTRINGFILE $STAGINGAREA/version-${NANOTYPE}-$FILESIZE
|
1989
|
fi
|
1990
|
done
|
1991
|
done
|
1992
|
}
|
1993
|
|
1994
|
snapshots_copy_to_staging_iso_updates() {
|
1995
|
# Copy ISOs
|
1996
|
md5 ${ISOPATH}.gz > ${ISOPATH}.md5
|
1997
|
sha256 ${ISOPATH}.gz > ${ISOPATH}.sha256
|
1998
|
cp ${ISOPATH}* $STAGINGAREA/ 2>/dev/null
|
1999
|
|
2000
|
# Copy memstick items
|
2001
|
md5 ${MEMSTICKPATH}.gz > ${MEMSTICKPATH}.md5
|
2002
|
sha256 ${MEMSTICKPATH}.gz > ${MEMSTICKPATH}.sha256
|
2003
|
cp ${MEMSTICKPATH}* $STAGINGAREA/ 2>/dev/null
|
2004
|
|
2005
|
md5 ${MEMSTICKSERIALPATH}.gz > ${MEMSTICKSERIALPATH}.md5
|
2006
|
sha256 ${MEMSTICKSERIALPATH}.gz > ${MEMSTICKSERIALPATH}.sha256
|
2007
|
cp ${MEMSTICKSERIALPATH}* $STAGINGAREA/ 2>/dev/null
|
2008
|
|
2009
|
md5 ${MEMSTICKADIPATH}.gz > ${MEMSTICKADIPATH}.md5
|
2010
|
sha256 ${MEMSTICKADIPATH}.gz > ${MEMSTICKADIPATH}.sha256
|
2011
|
cp ${MEMSTICKADIPATH}* $STAGINGAREA/ 2>/dev/null
|
2012
|
|
2013
|
md5 ${UPDATES_TARBALL_FILENAME} > ${UPDATES_TARBALL_FILENAME}.md5
|
2014
|
sha256 ${UPDATES_TARBALL_FILENAME} > ${UPDATES_TARBALL_FILENAME}.sha256
|
2015
|
cp ${UPDATES_TARBALL_FILENAME}* $STAGINGAREA/ 2>/dev/null
|
2016
|
# NOTE: Updates need a file with output similar to date output
|
2017
|
# Use the file generated at start of snapshots_dobuilds() to be consistent on times
|
2018
|
if [ -z "${_IS_RELEASE}" ]; then
|
2019
|
cp $BUILTDATESTRINGFILE $STAGINGAREA/version 2>/dev/null
|
2020
|
fi
|
2021
|
}
|
2022
|
|
2023
|
snapshots_scp_files() {
|
2024
|
if [ -z "${RSYNC_COPY_ARGUMENTS:-}" ]; then
|
2025
|
RSYNC_COPY_ARGUMENTS="-ave ssh --timeout=60 --bwlimit=${RSYNCKBYTELIMIT}" #--bwlimit=50
|
2026
|
fi
|
2027
|
snapshots_update_status ">>> Copying files to ${RSYNCIP}"
|
2028
|
|
2029
|
rm -f $SCRATCHDIR/ssh-snapshots*
|
2030
|
|
2031
|
# Ensure directory(s) are available
|
2032
|
ssh ${RSYNCUSER}@${RSYNCIP} "mkdir -p ${RSYNCPATH}/livecd_installer"
|
2033
|
ssh ${RSYNCUSER}@${RSYNCIP} "mkdir -p ${RSYNCPATH}/updates"
|
2034
|
ssh ${RSYNCUSER}@${RSYNCIP} "mkdir -p ${RSYNCPATH}/nanobsd"
|
2035
|
if [ -d $STAGINGAREA/virtualization ]; then
|
2036
|
ssh ${RSYNCUSER}@${RSYNCIP} "mkdir -p ${RSYNCPATH}/virtualization"
|
2037
|
fi
|
2038
|
ssh ${RSYNCUSER}@${RSYNCIP} "mkdir -p ${RSYNCPATH}/.updaters"
|
2039
|
# ensure permissions are correct for r+w
|
2040
|
ssh ${RSYNCUSER}@${RSYNCIP} "chmod -R ug+rw /usr/local/www/snapshots/FreeBSD_${FREEBSD_PARENT_BRANCH}/${TARGET}/."
|
2041
|
ssh ${RSYNCUSER}@${RSYNCIP} "chmod -R ug+rw ${RSYNCPATH}/."
|
2042
|
ssh ${RSYNCUSER}@${RSYNCIP} "chmod -R ug+rw ${RSYNCPATH}/*/."
|
2043
|
rsync $RSYNC_COPY_ARGUMENTS $STAGINGAREA/${PRODUCT_NAME}-*iso* \
|
2044
|
${RSYNCUSER}@${RSYNCIP}:${RSYNCPATH}/livecd_installer/
|
2045
|
rsync $RSYNC_COPY_ARGUMENTS $STAGINGAREA/${PRODUCT_NAME}-memstick* \
|
2046
|
${RSYNCUSER}@${RSYNCIP}:${RSYNCPATH}/livecd_installer/
|
2047
|
rsync $RSYNC_COPY_ARGUMENTS $STAGINGAREA/${PRODUCT_NAME}-*Update* \
|
2048
|
${RSYNCUSER}@${RSYNCIP}:${RSYNCPATH}/updates/
|
2049
|
rsync $RSYNC_COPY_ARGUMENTS $STAGINGAREA/nanobsd/* \
|
2050
|
${RSYNCUSER}@${RSYNCIP}:${RSYNCPATH}/nanobsd/
|
2051
|
rsync $RSYNC_COPY_ARGUMENTS $STAGINGAREA/nanobsdupdates/* \
|
2052
|
${RSYNCUSER}@${RSYNCIP}:${RSYNCPATH}/updates/
|
2053
|
if [ -d $STAGINGAREA/virtualization ]; then
|
2054
|
rsync $RSYNC_COPY_ARGUMENTS $STAGINGAREA/virtualization/* \
|
2055
|
${RSYNCUSER}@${RSYNCIP}:${RSYNCPATH}/virtualization/
|
2056
|
fi
|
2057
|
|
2058
|
# Rather than copy these twice, use ln to link to the latest one.
|
2059
|
|
2060
|
ssh ${RSYNCUSER}@${RSYNCIP} "rm -f ${RSYNCPATH}/.updaters/latest.tgz"
|
2061
|
ssh ${RSYNCUSER}@${RSYNCIP} "rm -f ${RSYNCPATH}/.updaters/latest.tgz.sha256"
|
2062
|
|
2063
|
LATESTFILENAME="`ls $UPDATESDIR/*.tgz | grep Full | grep -v md5 | grep -v sha256 | tail -n1`"
|
2064
|
LATESTFILENAME=`basename ${LATESTFILENAME}`
|
2065
|
ssh ${RSYNCUSER}@${RSYNCIP} "ln -s ${RSYNCPATH}/updates/${LATESTFILENAME} \
|
2066
|
${RSYNCPATH}/.updaters/latest.tgz"
|
2067
|
ssh ${RSYNCUSER}@${RSYNCIP} "ln -s ${RSYNCPATH}/updates/${LATESTFILENAME}.sha256 \
|
2068
|
${RSYNCPATH}/.updaters/latest.tgz.sha256"
|
2069
|
|
2070
|
for i in "${FLASH_SIZE}"
|
2071
|
do
|
2072
|
ssh ${RSYNCUSER}@${RSYNCIP} "rm -f ${RSYNCPATH}/.updaters/latest-nanobsd-${i}.img.gz"
|
2073
|
ssh ${RSYNCUSER}@${RSYNCIP} "rm -f ${RSYNCPATH}/.updaters/latest-nanobsd-${i}.img.gz.sha256"
|
2074
|
ssh ${RSYNCUSER}@${RSYNCIP} "rm -f ${RSYNCPATH}/.updaters/latest-nanobsd-vga-${i}.img.gz"
|
2075
|
ssh ${RSYNCUSER}@${RSYNCIP} "rm -f ${RSYNCPATH}/.updaters/latest-nanobsd-vga-${i}.img.gz.sha256"
|
2076
|
|
2077
|
FILENAMEUPGRADE="${PRODUCT_NAME}-${PRODUCT_VERSION}-${i}-${TARGET}-nanobsd-upgrade${TIMESTAMP_SUFFIX}.img.gz"
|
2078
|
ssh ${RSYNCUSER}@${RSYNCIP} "ln -s ${RSYNCPATH}/updates/${FILENAMEUPGRADE} \
|
2079
|
${RSYNCPATH}/.updaters/latest-nanobsd-${i}.img.gz"
|
2080
|
ssh ${RSYNCUSER}@${RSYNCIP} "ln -s ${RSYNCPATH}/updates/${FILENAMEUPGRADE}.sha256 \
|
2081
|
${RSYNCPATH}/.updaters/latest-nanobsd-${i}.img.gz.sha256"
|
2082
|
|
2083
|
FILENAMEUPGRADE="${PRODUCT_NAME}-${PRODUCT_VERSION}-${i}-${TARGET}-nanobsd-vga-upgrade${TIMESTAMP_SUFFIX}.img.gz"
|
2084
|
ssh ${RSYNCUSER}@${RSYNCIP} "ln -s ${RSYNCPATH}/updates/${FILENAMEUPGRADE} \
|
2085
|
${RSYNCPATH}/.updaters/latest-nanobsd-vga-${i}.img.gz"
|
2086
|
ssh ${RSYNCUSER}@${RSYNCIP} "ln -s ${RSYNCPATH}/updates/${FILENAMEUPGRADE}.sha256 \
|
2087
|
${RSYNCPATH}/.updaters/latest-nanobsd-vga-${i}.img.gz.sha256"
|
2088
|
done
|
2089
|
|
2090
|
rsync $RSYNC_COPY_ARGUMENTS $STAGINGAREA/version* \
|
2091
|
${RSYNCUSER}@${RSYNCIP}:${RSYNCPATH}/.updaters
|
2092
|
snapshots_update_status ">>> Finished copying files."
|
2093
|
}
|