#!/bin/sh # Builds the complete corresponding source archive for the guest kernel and # bundled GPL/LGPL guest filesystem tools (e2fsprogs and util-linux). set -eu out=${1:?"usage: scripts/ci/kernel-source.sh "} root=$(cd "$(dirname "$0")/../.." && pwd) cd "$root" case $out in /* | [A-Za-z]:*) ;; *) out=$PWD/$out ;; esac kver=$(sed -n 's/^KVER="${KVER:-\([^}]*\)}"/\1/p' guest/kernel/build.sh) [ -n "$kver" ] || { echo "could not read KVER from guest/kernel/build.sh" >&2; exit 1; } pin_ver() { sed -n "s/^pub const $1: (&str, &str) = (\"\([^\"]*\)\", \"\([0-9a-f]\{64\}\)\");$/\1/p" crates/kiri/src/cli_pins.rs } pin_sha() { sed -n "s/^pub const $1: (&str, &str) = (\"\([^\"]*\)\", \"\([0-9a-f]\{64\}\)\");$/\2/p" crates/kiri/src/cli_pins.rs } check_sha256() { file=$1 want=$2 if command -v sha256sum >/dev/null 2>&1; then got=$(sha256sum "$file" | awk '{print $1}') else got=$(shasum -a 256 "$file" | awk '{print $1}') fi [ "$got" = "$want" ] || { echo "$file: SHA-256 $got, expected $want" >&2; exit 1; } } ever=$(pin_ver E2FSPROGS_SOURCE) esha=$(pin_sha E2FSPROGS_SOURCE) uver=$(pin_ver UTIL_LINUX_SOURCE) usha=$(pin_sha UTIL_LINUX_SOURCE) [ -n "$ever" ] && [ -n "$esha" ] || { echo "could not read E2FSPROGS_SOURCE from cli_pins.rs" >&2; exit 1; } [ -n "$uver" ] && [ -n "$usha" ] || { echo "could not read UTIL_LINUX_SOURCE from cli_pins.rs" >&2; exit 1; } umaj=${uver%.*} tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT curl -fsSL --retry 3 "https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-$kver.tar.xz" -o "$tmp/linux.tar.xz" tar -xJf "$tmp/linux.tar.xz" -C "$tmp" rm -f "$tmp/linux.tar.xz" e2fs_tar="e2fsprogs-$ever.tar.xz" curl -fsSL --retry 3 "https://mirrors.edge.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/v$ever/$e2fs_tar" -o "$tmp/$e2fs_tar" check_sha256 "$tmp/$e2fs_tar" "$esha" util_tar="util-linux-$uver.tar.xz" curl -fsSL --retry 3 "https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v$umaj/$util_tar" -o "$tmp/$util_tar" check_sha256 "$tmp/$util_tar" "$usha" cd "$tmp/linux-$kver" for patch in "$root"/guest/kernel/patches/*.patch; do patch -p1 -s < "$patch" done mkdir kiri cp "$root/guest/kernel/build.sh" "$root/guest/kernel/kiri.config" "$root/guest/kernel/kiri-x86_64.config" kiri/ cp -R "$root/guest/kernel/patches" kiri/ printf '%s\n' \ "Kiri guest kernel and initramfs filesystem tools corresponding source" \ "Kernel upstream: https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-$kver.tar.xz" \ "e2fsprogs upstream: https://mirrors.edge.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/v$ever/$e2fs_tar" \ "util-linux upstream: https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v$umaj/$util_tar" \ "Alpine v3.24 package recipes: https://gitlab.alpinelinux.org/alpine/aports/-/tree/3.24-stable/main" \ "All patches in kiri/patches have already been applied to this kernel tree." \ "Build the kernel with kiri/build.sh as described in the Kiri repository." > kiri/SOURCE mkdir -p "$(dirname "$out")" XZ_OPT=${XZ_OPT:--T0} tar -cJf "$out" -C "$tmp" "linux-$kver" "$e2fs_tar" "$util_tar"