-
Notifications
You must be signed in to change notification settings - Fork 38
/
build
executable file
·168 lines (150 loc) · 6.34 KB
/
build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/sh
#
# Build script for BSD Router Project
# https://bsdrp.net
#
# Copyright (c) 2009-2024, The BSDRP Development Team
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
set -eu
###############################################################################
# Poudriere configurations files are in poudriere.etc/poudriere.d/
# - First build a "builder" jail (BSDRPj), which is a reduced FreeBSD but that
# still needs to have compilers tools to build packages.
# - List of WITHOUT in BSDRPj-src.conf
# - Custom kernel configuration file (amd64 here)
# - Second, from this builder jail, we generate packages:
# - ports list in BSDRP-pkglist
# - ports options in BSDRPj-make.conf
# - Third and last, we generate a nanobsd-like, uefi compliant firmware image
# - No need of compiler tools, more WITHOUT_added in image-BSDRPj-src.conf
# - But FreeBSD some unwanted files are still here, so adding list of them
# in excluded.files
# - All avoiding extracting unwanted files from package using a pkg.conf
# in BSDRP/Files/usr/local/etc/pkg.conf
# - And a post customization script in post-script.sh
###############################################################################
# Variables
logfile="/tmp/BSDRP.build.log"
pkglist="/tmp/BSDRP.pkg.list"
sudo=""
# Functions
#######################################
# Print on STDERR
# Globals:
# None
# Arguments:
# Message to print
#######################################
die() {
echo -n "EXIT: " >&2
echo "$@" >&2
exit 1
}
###### main ######
if [ $(id -u) -ne 0 ]; then
if which -s sudo; then
sudo="sudo -E"
else
die "Need to start as root because sudo not found"
fi
fi
arch=$(uname -m)
localdir=$(realpath $(dirname $0))
echo "Generating BSDRP disk image (logs in: ${logfile})..."
# Download and patches sources, install custom kernel (amd64)
# so kept local patch files method
# XXX Need to put "update" function in a shared lib
echo "[DEBUG] run make -U"
#./make.sh -U
# Create or update the builder jail
# if arm64 sed delete amd kernel module and pkglist
# XXX Need to avoid patching revisionned file
if [ "${arch}" = "arm64" ]; then
for f in amdsbwd amdsmn amdtemp blake2 coretemp cpuctl ichwd ioat qat qat_c2xxx qatfw padlock; do
if grep -q $f ${localdir}/poudriere.etc/poudriere.d/BSDRPj-src.conf; then
echo "${arch} detected, removing $f kernel module..."
sed -i "" -e "/^[[:space:]]${f}/d" ${localdir}/poudriere.etc/poudriere.d/BSDRPj-src.conf
fi
done
fi
if poudriere -e poudriere.etc jail -ln | grep -q BSDRPj; then
path_of_the_jail=$(poudriere -e ${localdir}/poudriere.etc/ jail -j BSDRPj -l | tail -1 | cut -d ' ' -f 10)
if [ -n "$(find ${localdir}/BSDRP/FreeBSD/src -type f -newer ${path_of_the_jail}/boot/kernel/kernel)" ]; then
echo "Find sources newer than kernel, updating poudriere jail..."
echo "XXX BUG: Always trigger this update!!!!"
${sudo} poudriere -e ${localdir}/poudriere.etc jail -u -j BSDRPj -b -m src=${localdir}/BSDRP/FreeBSD/src -K ${arch} > $logfile 2>&1
fi
else
echo "Creating poudriere jail..."
if ! ${sudo} poudriere -e ${localdir}/poudriere.etc jail -c -j BSDRPj -b -m src=${localdir}/BSDRP/FreeBSD/src -K ${arch} >> $logfile 2>&1; then
tail -n 20 $logfile
die "Failed to create the base jail"
fi
fi
# Create or update port tree
# XXX Regression: latest modifications time of dependencies are ignored
if poudriere -e ${localdir}/poudriere.etc ports -ln | grep -q BSDRPp; then
echo "Updating poudriere port tree..."
if ! ${sudo} poudriere -e ${localdir}/poudriere.etc ports -u -p BSDRPp -m null -M ${localdir}/BSDRP/FreeBSD/ports >> $logfile 2>&1; then
tail -n 20 $logfile
die "Failed to update port tree"
fi
else
echo "Creating poudriere port tree.."
if ! ${sudo} poudriere -e ${localdir}/poudriere.etc ports -c -p BSDRPp -m null -M ${localdir}/BSDRP/FreeBSD/ports >> $logfile 2>&1; then
tail -n 20 $logfile
die "Failed to create port tree"
fi
fi
# Build the packages
# Some packages are architectures dependends
cp ${localdir}/poudriere.etc/poudriere.d/BSDRP-pkglist.common ${pkglist}
if [ -f ${localdir}/poudriere.etc/poudriere.d/BSDRP-pkglist.${arch} ]; then
cat ${localdir}/poudriere.etc/poudriere.d/BSDRP-pkglist.${arch} >> ${pkglist}
fi
echo "Building packages..."
if ! ${sudo} poudriere -e ${localdir}/poudriere.etc bulk -j BSDRPj -p BSDRPp \
-f ${pkglist} >> $logfile 2>&1; then
tail -n 20 $logfile
die "Failed to build packages"
fi
# Build the firmware image
# size in bytes
# Notice that we are using a custom pkg.conf files preventing to install useless files
echo "Generating disk image..."
if ! ${sudo} poudriere -e ${localdir}/poudriere.etc image -t firmware -s 4g \
-j BSDRPj -p BSDRPp -n BSDRP -h router.bsdrp.net \
-c ${localdir}/BSDRP/Files/ \
-f ${pkglist} \
-X ${localdir}/poudriere.etc/poudriere.d/excluded.files \
-A ${localdir}/poudriere.etc/poudriere.d/post-script.sh >> $logfile 2>&1; then
tail -n 20 $logfile
die "Failed to generate disk image"
fi
echo "Build done"
echo "- Full disk image: /usr/local/poudriere/data/images/BSDRP.img"
echo "- Upgrade image: /usr/local/poudriere/data/images/BSDRP-upgrade.img"
# Convert image to VHD
# qemu-img convert -f raw -O vpc /usr/local/poudriere/data/images/BSDRP.img BSDRP.vhd