|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 | #
|
3 |
| -# Copyright 2018, 2020 Delphix |
| 3 | +# Copyright 2018, 2025 Delphix |
4 | 4 | #
|
5 | 5 | # Licensed under the Apache License, Version 2.0 (the "License");
|
6 | 6 | # you may not use this file except in compliance with the License.
|
|
23 | 23 | # be overriden.
|
24 | 24 | #
|
25 | 25 |
|
| 26 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 27 | +source "$SCRIPT_DIR/packages/common.sh" |
| 28 | + |
26 | 29 | function fetch() {
|
27 | 30 | logmust fetch_repo_from_git
|
28 | 31 | }
|
@@ -160,6 +163,33 @@ function kernel_build() {
|
160 | 163 | #
|
161 | 164 | logmust fakeroot debian/rules printenv "${debian_rules_args[@]}"
|
162 | 165 |
|
| 166 | + # |
| 167 | + # Download SB keys and configure signing keys/certs before build |
| 168 | + # |
| 169 | + download_keys |
| 170 | + |
| 171 | + FLAVOUR=$platform |
| 172 | + OBJ=debian/build/build-$FLAVOUR |
| 173 | + CERTS=$OBJ/certs |
| 174 | + |
| 175 | + ensure the objdir + certs dir exist |
| 176 | + mkdir -p "$CERTS" |
| 177 | + |
| 178 | + # provide the key the packaging expects INSIDE the objdir |
| 179 | + # (symlink or copy) |
| 180 | + logmust ln -sf "${SB_KEYS_DIR}/signing_key.pem" "$CERTS/signing_key.pem" |
| 181 | + logmust chmod 600 "$CERTS/signing_key.pem" |
| 182 | + |
| 183 | + # create the DER .x509 that sign-file needs from .crt) |
| 184 | + logmust openssl x509 -in "${SB_KEYS_DIR}/db.crt" -outform DER -out "$CERTS/signing_key.x509" |
| 185 | + # sanity checks |
| 186 | + logmust test -s "$CERTS/signing_key.pem" || { echo "missing signing_key.pem"; exit 1; } |
| 187 | + logmust test -s "$CERTS/signing_key.x509" || { echo "missing signing_key.x509"; exit 1; } |
| 188 | + logmust openssl pkey -in "$CERTS/signing_key.pem" -noout >/dev/null || { echo "key unreadable"; exit 1; } |
| 189 | + |
| 190 | + SBSIGN_KEY="${SBSIGN_KEY:-$SB_KEYS_DIR/db.key}" |
| 191 | + SBSIGN_CERT="${SBSIGN_CERT:-$SB_KEYS_DIR/db.crt}" |
| 192 | + |
163 | 193 | #
|
164 | 194 | # The default value of the tool argument for mk-build-deps
|
165 | 195 | # is the following:
|
@@ -203,6 +233,33 @@ function kernel_build() {
|
203 | 233 | # one of the .debs produced
|
204 | 234 | #
|
205 | 235 | logmust test -f "artifacts/linux-image-${kernel_version}_"*.deb
|
| 236 | + |
| 237 | + # |
| 238 | + # After the build, unpackage linux-image package and sign vmlinuz |
| 239 | + # |
| 240 | + linux_deb=$(find artifacts -type f -name "linux-image-${kernel_version}*.deb" | head -n1) |
| 241 | + temp_dir=$(mktemp -d -p "/var/tmp/") |
| 242 | + logmust fakeroot dpkg-deb -R $linux_deb "$temp_dir" |
| 243 | + |
| 244 | + bz="$temp_dir/boot/vmlinuz-${kernel_version}" |
| 245 | + logmust sbsign --key $SBSIGN_KEY --cert $SBSIGN_CERT --output "$bz.signed" "$bz" |
| 246 | + logmust mv "$bz.signed" "$bz" |
| 247 | + logmust sbverify --list "$bz" |
| 248 | + |
| 249 | + # Update md5sums |
| 250 | + # ( cd "$temp_dir" || exit |
| 251 | + # : > DEBIAN/md5sums |
| 252 | + # print paths relative to root of package |
| 253 | +# while IFS= read -r -d '' f; do |
| 254 | +# rel="${f#./}" |
| 255 | +# md5sum "$rel" >> DEBIAN/md5sums |
| 256 | +# done < <(find . -type f ! -path './DEBIAN/*' -print0) |
| 257 | +# ) |
| 258 | + |
| 259 | + # Repack the .deb" |
| 260 | + update_md5sums "$temp_dir" |
| 261 | + repack_deb $linux_deb $temp_dir |
| 262 | + delete_keys |
206 | 263 | }
|
207 | 264 |
|
208 | 265 | #
|
|
0 commit comments