Skip to content

eBPF-based security platform

testing: download the pinned kernel when none is staged

John Fastabendef39b278e66f
diff --git a/.agents/skills/testing/SKILL.md b/.agents/skills/testing/SKILL.md
index 056741c7..06d02de2 100644
--- a/.agents/skills/testing/SKILL.md
+++ b/.agents/skills/testing/SKILL.md
@@ -101,9 +101,12 @@ parser of input from outside the host gets a target in `testing/fuzz/`.
- `vm`, `test-vm-bundle` and every family with target tests require the
kernel artifact from `shirudo-dev/kernel` under
- `artifacts/bpf-next-kernel-debs/`. The CI workflow pins a kernel run
- and its setup script stages that artifact. Local runs need the same
- artifact; they do not build a kernel from this checkout.
+ `artifacts/bpf-next-kernel-debs/`. `testing/vm/kernel-artifact.sh`
+ pins a kernel run; the CI setup script stages its artifact, and a
+ local VM goal that finds no kernel there downloads and stages it with
+ `gh` (`testing/vm/kernel-artifact.sh fetch`). A kernel already staged
+ is left alone: remove the directory to get the pinned one. No goal
+ builds a kernel from this checkout.
- The bundle builds in the build container (`testing/container/`) from
a copy of the files git sees in the checkout, tracked and untracked but
not ignored, so uncommitted changes are tested; edit nothing until the
diff --git a/.github/scripts/tests.sh b/.github/scripts/tests.sh
index d2874d6d..a4ae528d 100755
--- a/.github/scripts/tests.sh
+++ b/.github/scripts/tests.sh
@@ -53,123 +53,6 @@ finish() {
exit "$status"
}
-# The kernel CI build carries the LSM hooks the programs of bpf/ attach to.
-# A kernel built without one passes every other check and then fails init.
-require_lsm_hooks() {
- btf="$1"
- names=$(mktemp) || return 1
- tr '\0' '\n' <"$btf" >"$names"
- missing=$(sed -nE 's/^SEC\("lsm(\.s)?\/([a-z0-9_]+)"\).*/\2/p' bpf/*.c |
- sort -u | while read -r hook; do
- grep -qx "bpf_lsm_$hook" "$names" || printf ' %s' "$hook"
- done)
- rm -f "$names"
- [ -z "$missing" ] && return 0
- printf 'kernel BTF lacks the LSM hooks%s: use a shirudo-dev/kernel build\n' \
- "$missing" >&2
- return 1
-}
-
-validate_kernel_install() {
- source_dir="$1"
- [ -d "$source_dir/boot" ] || {
- echo "kernel artifacts are missing: $source_dir/boot" >&2
- return 1
- }
-
- set -- "$source_dir"/boot/vmlinuz-*
- [ "$#" -eq 1 ] && [ -s "$1" ] || {
- echo "expected one kernel image in $source_dir/boot" >&2
- return 1
- }
- image="$1"
- release=${image##*/vmlinuz-}
- btf="$source_dir/boot/btf-$release"
- config="$source_dir/boot/config-$release"
- modules="$source_dir/lib/modules/$release"
-
- [ -s "$btf" ] || {
- echo "kernel BTF is missing: $btf" >&2
- return 1
- }
- [ -s "$config" ] || {
- echo "kernel config is missing: $config" >&2
- return 1
- }
- [ -d "$modules" ] || {
- echo "kernel modules are missing: $modules" >&2
- return 1
- }
- grep -aq 'signature_size' "$btf" || {
- echo "kernel BTF lacks bpf_attr.signature_size" >&2
- return 1
- }
- require_lsm_hooks "$btf" || return 1
-
- return 0
-}
-
-stage_kernel_install() {
- rm -rf "$kernel/lib/modules" || return 1
- mkdir -p "$kernel/lib/modules" || return 1
- cp "$image" "$kernel/bzImage" || return 1
- cp "$btf" "$kernel/vmlinux.btf" || return 1
- cp "$config" "$kernel/kernel.config" || return 1
- cp -a "$modules" "$kernel/lib/modules/" || return 1
- (
- cd "$kernel" || exit 1
- sha256sum bzImage > bzImage.sha256sum || exit 1
- sha256sum vmlinux.btf > vmlinux.btf.sha256sum || exit 1
- ) || return 1
-}
-
-stage_kernel_ci_artifact() {
- artifact_dir="$1"
- set -- "$artifact_dir"/*/linux-image-*_amd64.deb
- [ "$#" -eq 1 ] && [ -s "$1" ] || {
- echo "expected one x86-64 kernel image package in $artifact_dir" >&2
- return 1
- }
- image_package="$1"
- package_dir=${image_package%/*}
- release=${image_package##*/linux-image-}
- release=${release%%_*}
- btf="$package_dir/vmlinux-$release.btf"
- [ -s "$btf" ] || {
- echo "kernel CI artifact lacks BTF for $release" >&2
- return 1
- }
- mkdir -p "$kernel" || return 1
- cp "$btf" "$kernel/vmlinux.btf" || return 1
- [ "${VM:-1}" != 0 ] || return 0
-
- set -- "$package_dir"/linux-headers-"$release"_*_amd64.deb
- [ "$#" -eq 1 ] && [ -s "$1" ] || {
- echo "expected headers package for kernel $release in $package_dir" >&2
- return 1
- }
- config="$package_dir/config-$release"
- [ -s "$config" ] || {
- echo "kernel CI artifact lacks config for $release" >&2
- return 1
- }
- install_root="$PWD/build/kernel-ci-extract"
- rm -rf "$install_root"
- mkdir -p "$install_root" || return 1
- dpkg-deb -x "$image_package" "$install_root" || return 1
- dpkg-deb -x "$1" "$install_root" || return 1
- image="$install_root/boot/vmlinuz-$release"
- modules="$install_root/lib/modules/$release"
- cp "$btf" "$install_root/boot/btf-$release" || return 1
- cp "$config" "$install_root/boot/config-$release" || return 1
- [ -s "$image" ] && [ -d "$modules" ] || {
- echo "kernel packages did not contain image and modules for $release" >&2
- return 1
- }
- validate_kernel_install "$install_root" || return 1
- stage_kernel_install
-}
-
setup() {
if [ "${VM:-1}" != 0 ]; then
sudo rm -rf /opt/ghc /usr/local/lib/android /usr/share/dotnet
@@ -179,7 +62,7 @@ setup() {
echo 'KERNEL_CI_ARTIFACT_DIR must name the downloaded artifact from github.com/shirudo-dev/kernel' >&2
exit 1
fi
- stage_kernel_ci_artifact "$KERNEL_CI_ARTIFACT_DIR" || exit 1
+ testing/vm/kernel-artifact.sh stage "$KERNEL_CI_ARTIFACT_DIR" || exit 1
# spatch opens libpython3.X.so by that name for the Python of its
# rules, and only the -dev package installs it.
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index f9e8fe96..f166830c 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -8,7 +8,7 @@ on:
workflow_dispatch:
inputs:
kernel_run_id:
- description: Optional override; defaults to kernel run 44367017434
+ description: Optional override; defaults to the run testing/vm/kernel-artifact.sh pins
required: false
type: string
@@ -49,14 +49,7 @@ jobs:
GH_TOKEN: ${{ secrets.KERNEL_REPO_READ_TOKEN }}
REQUESTED_RUN_ID: ${{ inputs.kernel_run_id }}
run: |
- if [ -n "$REQUESTED_RUN_ID" ]; then
- case "$REQUESTED_RUN_ID" in
- *[!0-9]*) echo "kernel_run_id must be numeric" >&2; exit 1 ;;
- esac
- run_id="$REQUESTED_RUN_ID"
- else
- run_id=44367017434
- fi
+ run_id=$(KERNEL_RUN_ID="$REQUESTED_RUN_ID" testing/vm/kernel-artifact.sh run-id)
echo "Using kernel package run $run_id"
echo "run_id=$run_id" >> "$GITHUB_OUTPUT"
diff --git a/Documentation/contribute/testing/testing.rst b/Documentation/contribute/testing/testing.rst
index 240f9356..75893350 100644
--- a/Documentation/contribute/testing/testing.rst
+++ b/Documentation/contribute/testing/testing.rst
@@ -55,7 +55,7 @@ Before you begin
The ``CI suite`` workflow uses the x86-64 CI kernel package from
``shirudo-dev/kernel`` for every trigger: the
``kernel-packages-x86-64-ci`` artifact of the run that
-:src:`.github/workflows/tests.yml` pins, so that a new build of the
+:src:`testing/vm/kernel-artifact.sh` pins, so that a new build of the
kernel does not change what a series is tested on. For a manual run,
set ``kernel_run_id`` to select another run. The run must contain that
artifact. The ``KERNEL_REPO_READ_TOKEN`` secret needs Actions read
@@ -449,15 +449,31 @@ Use a kernel project artifact
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The kernel project publishes the kernel image, BTF, configuration and
-modules together. Download the ``kernel-packages-x86-64-ci`` artifact
-from the run pinned in :src:`.github/workflows/tests.yml` and pass its
-directory to the setup script:
+modules together, as the ``kernel-packages-x86-64-ci`` artifact of a
+run of its package workflow. :src:`testing/vm/kernel-artifact.sh` pins
+the run the tests use, and a goal of ``make -C testing`` that finds no
+kernel under ``artifacts/bpf-next-kernel-debs/`` downloads and stages
+that one: a target VM goal for the kernel it boots, and every goal that
+builds for the BTF the BPF objects are compiled against, unless
+``BPF_VMLINUX_BTF`` or ``BPF_VMLINUX_H`` names another. It
+needs ``gh``, logged in with read access to the kernel repository:
+
+.. code-block:: console
+
+ $ testing/vm/kernel-artifact.sh fetch
+
+``KERNEL_RUN_ID=<run>`` takes another run. A kernel that is staged is
+left as it is, whatever run it came from, and
+``artifacts/bpf-next-kernel-debs/kernel-run-id`` names the run of one
+that was fetched: remove the directory to get the pinned kernel after
+the pin moved. An artifact downloaded by other means is staged with
+``testing/vm/kernel-artifact.sh stage <dir>``, which the setup script
+of the CI runner calls with ``KERNEL_CI_ARTIFACT_DIR``:
.. code-block:: console
$ KERNEL_CI_ARTIFACT_DIR=$HOME/Downloads/kernel-packages-x86-64-ci .github/scripts/tests.sh setup
-Setup stages the kernel under ``artifacts/bpf-next-kernel-debs/``.
Target VM goals require this artifact; they do not build a kernel from
this checkout.
diff --git a/Documentation/start/quickstart.rst b/Documentation/start/quickstart.rst
index 1bd31e94..e65ea9e3 100644
--- a/Documentation/start/quickstart.rst
+++ b/Documentation/start/quickstart.rst
@@ -28,7 +28,7 @@ Before you begin
changing the host's dracut.
- Network access. The first boot downloads an Ubuntu cloud image. Get
the test kernel package artifact from the pinned run in
- ``.github/workflows/tests.yml`` before building the target binary.
+ ``testing/vm/kernel-artifact.sh`` before building the target binary.
- To build shirudo: a C toolchain with ``make`` and ``pkg-config``, a
clang and LLVM 23 with the BPF target, ``clang`` installed as
``/usr/bin/clang``, and the development files of OpenSSL 3.5 or later,
@@ -52,7 +52,7 @@ Use the test kernel artifact
----------------------------
Download the ``kernel-packages-x86-64-ci`` artifact from the run pinned
-in ``.github/workflows/tests.yml``. Stage it and prepare the test host:
+in ``testing/vm/kernel-artifact.sh``. Stage it and prepare the test host:
.. code-block:: console
diff --git a/testing/Makefile b/testing/Makefile
index 2a5a35a7..32130ef5 100644
--- a/testing/Makefile
+++ b/testing/Makefile
@@ -27,7 +27,7 @@ test-vm-arch = $(shell TEST_VM_ARCH='$(TEST_VM_ARCH)'; \
. $(ROOT)/testing/vm/arch.sh && printf '%s' "$$$(1)")
.DEFAULT_GOAL := all
-.PHONY: all help clean unit ci-checks functional end2end build-operator build-unit \
+.PHONY: all help clean unit ci-checks functional end2end build-operator build-unit kernel-btf \
test-helpers \
fuzz afl bundle test-vm-bundle require-vm-kernel vm vm-console vm-ssh vm-enroll vm-sbom vm-stop vm-clean \
vm-operator-end2end
@@ -169,11 +169,16 @@ $(TEST_VM_BUNDLE_STAMP): $(TEST_VM_BUNDLE_INPUTS)
BPF_VMLINUX_BTF="$(abspath $(VM_KERNEL_ARTIFACT_DIR)/vmlinux.btf)" \
flock $(BUILD_LOCK) $(ROOT)/testing/vm/build-bundle.sh
+# A bpf-next kernel that is not staged is downloaded, the run the CI suite
+# pins; one that is staged is left as it is, whatever run it came from.
require-vm-kernel:
$(Q)test -s "$(VM_KERNEL_IMAGE)" -a -s "$(VM_KERNEL_STAMP)" -a \
-s "$(VM_KERNEL_ARTIFACT_DIR)/vmlinux.btf" -a \
-s "$(VM_KERNEL_ARTIFACT_DIR)/kernel.config" -a \
-d "$(VM_KERNEL_ARTIFACT_DIR)/lib/modules" || { \
+ [ "$(VM_KERNEL)" = bpf-next ] && \
+ $(ROOT)/testing/vm/kernel-artifact.sh fetch; \
+ } || { \
echo "kernel artifact is missing; use github.com/shirudo-dev/kernel packages in $(VM_KERNEL_ARTIFACT_DIR)" >&2; \
exit 1; \
}
@@ -359,12 +364,23 @@ build-operator: build-unit
+$(Q)flock $(BUILD_LOCK) $(MAKE) -C $(ROOT) quote-check
+$(Q)flock $(BUILD_LOCK) $(MAKE) -C $(ROOT) -f Makefile.shirudo test-helpers
-build-unit:
+# The BPF objects are compiled against the BTF of the test kernel, which
+# has the signed-loader types a host's own kernel seldom has. Without one
+# staged, and without a BTF or a vmlinux.h the caller names, the pinned
+# kernel is downloaded; where that fails the build takes the BTF of the
+# running kernel, as it did.
+kernel-btf:
+ $(Q)[ -n "$(BPF_VMLINUX_BTF)$(BPF_VMLINUX_H)" ] || \
+ [ -s "$(ROOT)/artifacts/bpf-next-kernel-debs/vmlinux.btf" ] || \
+ VM="$(VM)" $(ROOT)/testing/vm/kernel-artifact.sh fetch || \
+ echo "no kernel artifact: building against the BTF of the running kernel" >&2
+
+build-unit: | kernel-btf
$(Q)mkdir -p $(dir $(BUILD_LOCK))
+$(Q)flock $(BUILD_LOCK) $(MAKE) -C $(ROOT) all
+$(Q)flock $(BUILD_LOCK) $(MAKE) -C $(ROOT) -f Makefile.shirudo unit-tests
-test-helpers:
+test-helpers: | kernel-btf
+$(Q)$(MAKE) -C $(ROOT) config
+$(Q)$(MAKE) -C $(ROOT) -f Makefile.shirudo test-helpers
@@ -375,7 +391,7 @@ test-helpers:
FUZZ_SECONDS ?= 60
FUZZERS ?=
-fuzz:
+fuzz: | kernel-btf
+$(Q)$(MAKE) -C $(ROOT) config
+$(Q)$(MAKE) -C $(ROOT) -f Makefile.shirudo fuzz-targets
$(Q)sh $(ROOT)/testing/fuzz/run.sh $(FUZZ_SECONDS) $(FUZZERS)
@@ -388,7 +404,7 @@ fuzz:
AFL_CC ?= afl-clang-fast
AFL_SECONDS ?= 600
-afl:
+afl: | kernel-btf
+$(Q)$(MAKE) -C $(ROOT) config
+$(Q)$(MAKE) -C $(ROOT) -f Makefile.shirudo fuzz-targets \
FUZZ_CC=$(AFL_CC) FUZZ_OUT=build/fuzz-afl
@@ -412,7 +428,8 @@ help:
' make -C testing fuzz [FUZZ_SECONDS=60] [FUZZ_CORPUS=<dir>] [FUZZERS=<target>...]' \
' make -C testing afl [AFL_SECONDS=600] [FUZZ_CORPUS=<dir>] [FUZZERS=<target>...]' \
' make -C testing vm, vm-console, vm-ssh, vm-enroll, vm-sbom, vm-stop, or vm-clean' \
- ' VM_KERNEL=bpf-next (default) selects the shirudo-dev/kernel artifact' \
+ ' VM_KERNEL=bpf-next (default) selects the shirudo-dev/kernel artifact,' \
+ ' downloaded with gh when artifacts/bpf-next-kernel-debs has none' \
' make -C testing bundle or test-helpers' \
' make -C testing stack-up, oci, telemetry, xtop or stack-down' \
' make -C testing clean'
diff --git a/testing/functional/build/t1007-test-vm-cli.sh b/testing/functional/build/t1007-test-vm-cli.sh
index fdcddacc..a5dde5bc 100755
--- a/testing/functional/build/t1007-test-vm-cli.sh
+++ b/testing/functional/build/t1007-test-vm-cli.sh
@@ -632,7 +632,13 @@ test_expect_success 'test VMs require a kernel project artifact' '
grep -q "github.com/shirudo-dev/kernel" ../testing/Makefile &&
grep -q "^require-vm-kernel:" ../testing/Makefile &&
! grep -q "build-kernel.sh\|KERNEL_CONFIG\|KERNEL_PATCHES" ../testing/Makefile &&
- grep -q "KERNEL_CI_ARTIFACT_DIR" ../.github/scripts/tests.sh
+ grep -q "KERNEL_CI_ARTIFACT_DIR" ../.github/scripts/tests.sh &&
+ grep -q "kernel-artifact.sh fetch" ../testing/Makefile &&
+ id=$(vm/kernel-artifact.sh run-id) &&
+ test "$(KERNEL_RUN_ID=12 vm/kernel-artifact.sh run-id)" = 12 &&
+ test "$id" -gt 0 &&
+ ! KERNEL_RUN_ID=1x vm/kernel-artifact.sh run-id 2>/dev/null &&
+ grep -q "kernel-artifact.sh run-id" ../.github/workflows/tests.yml
'
test_expect_success 'prepared VM runtime includes ripgrep' '
grep -qx "ripgrep" vm/runtime-packages &&
diff --git a/testing/vm/kernel-artifact.sh b/testing/vm/kernel-artifact.sh
new file mode 100755
index 00000000..1c162fd6
--- /dev/null
+++ b/testing/vm/kernel-artifact.sh
@@ -0,0 +1,205 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# testing/vm/kernel-artifact.sh -- the test VM's kernel, which
+# github.com/shirudo-dev/kernel builds and this checkout does not.
+#
+# kernel-artifact.sh fetch download the kernel-packages-x86-64-ci
+# artifact of the pinned run and stage it
+# kernel-artifact.sh stage <dir> stage an artifact already downloaded
+# kernel-artifact.sh run-id print the pinned run
+#
+# Staging extracts the image and headers packages, checks the BTF for the
+# signed-loader ABI and every LSM hook a program of bpf/ attaches to, and
+# puts image, BTF, configuration and modules under
+# artifacts/bpf-next-kernel-debs/, where testing/Makefile looks for them.
+# With VM=0 it stages the BTF alone, which a build needs.
+#
+# KERNEL_RUN_ID another run of the kernel project's package workflow
+# than the pinned one.
+#
+# fetch needs gh, logged in with read access to the kernel repository.
+
+set -eu
+
+# The run every trigger of the CI suite tests on, so that a new build of
+# the kernel does not change what a series is tested on.
+PINNED_RUN_ID=44367017434
+ARTIFACT=kernel-packages-x86-64-ci
+REPOSITORY=shirudo-dev/kernel
+
+# A directory named from where the caller stands.
+[ "${1:-}" != stage ] || [ $# -ne 2 ] || staged_from=$(realpath -- "$2")
+cd "$(dirname "$0")/../.."
+
+kernel=artifacts/bpf-next-kernel-debs
+
+# The kernel CI build carries the LSM hooks the programs of bpf/ attach to.
+# A kernel built without one passes every other check and then fails init.
+require_lsm_hooks() {
+ btf="$1"
+ names=$(mktemp) || return 1
+ tr '\0' '\n' <"$btf" >"$names"
+ missing=$(sed -nE 's/^SEC\("lsm(\.s)?\/([a-z0-9_]+)"\).*/\2/p' bpf/*.c |
+ sort -u | while read -r hook; do
+ grep -qx "bpf_lsm_$hook" "$names" || printf ' %s' "$hook"
+ done)
+ rm -f "$names"
+ [ -z "$missing" ] && return 0
+ printf 'kernel BTF lacks the LSM hooks%s: use a shirudo-dev/kernel build\n' \
+ "$missing" >&2
+ return 1
+}
+
+validate_kernel_install() {
+ source_dir="$1"
+ [ -d "$source_dir/boot" ] || {
+ echo "kernel artifacts are missing: $source_dir/boot" >&2
+ return 1
+ }
+
+ set -- "$source_dir"/boot/vmlinuz-*
+ [ "$#" -eq 1 ] && [ -s "$1" ] || {
+ echo "expected one kernel image in $source_dir/boot" >&2
+ return 1
+ }
+ image="$1"
+ release=${image##*/vmlinuz-}
+ btf="$source_dir/boot/btf-$release"
+ config="$source_dir/boot/config-$release"
+ modules="$source_dir/lib/modules/$release"
+
+ [ -s "$btf" ] || {
+ echo "kernel BTF is missing: $btf" >&2
+ return 1
+ }
+ [ -s "$config" ] || {
+ echo "kernel config is missing: $config" >&2
+ return 1
+ }
+ [ -d "$modules" ] || {
+ echo "kernel modules are missing: $modules" >&2
+ return 1
+ }
+ grep -aq 'signature_size' "$btf" || {
+ echo "kernel BTF lacks bpf_attr.signature_size" >&2
+ return 1
+ }
+ require_lsm_hooks "$btf" || return 1
+
+ return 0
+}
+
+stage_kernel_install() {
+ rm -rf "$kernel/lib/modules" || return 1
+ mkdir -p "$kernel/lib/modules" || return 1
+ cp "$image" "$kernel/bzImage" || return 1
+ cp "$btf" "$kernel/vmlinux.btf" || return 1
+ cp "$config" "$kernel/kernel.config" || return 1
+ cp -a "$modules" "$kernel/lib/modules/" || return 1
+ (
+ cd "$kernel" || exit 1
+ sha256sum bzImage > bzImage.sha256sum || exit 1
+ sha256sum vmlinux.btf > vmlinux.btf.sha256sum || exit 1
+ ) || return 1
+}
+
+stage_kernel_ci_artifact() {
+ artifact_dir="$1"
+ set -- "$artifact_dir"/*/linux-image-*_amd64.deb
+ [ "$#" -eq 1 ] && [ -s "$1" ] || {
+ echo "expected one x86-64 kernel image package in $artifact_dir" >&2
+ return 1
+ }
+ image_package="$1"
+ package_dir=${image_package%/*}
+ release=${image_package##*/linux-image-}
+ release=${release%%_*}
+ btf="$package_dir/vmlinux-$release.btf"
+ [ -s "$btf" ] || {
+ echo "kernel CI artifact lacks BTF for $release" >&2
+ return 1
+ }
+ mkdir -p "$kernel" || return 1
+ cp "$btf" "$kernel/vmlinux.btf" || return 1
+ [ "${VM:-1}" != 0 ] || return 0
+
+ set -- "$package_dir"/linux-headers-"$release"_*_amd64.deb
+ [ "$#" -eq 1 ] && [ -s "$1" ] || {
+ echo "expected headers package for kernel $release in $package_dir" >&2
+ return 1
+ }
+ config="$package_dir/config-$release"
+ [ -s "$config" ] || {
+ echo "kernel CI artifact lacks config for $release" >&2
+ return 1
+ }
+ install_root="$PWD/build/kernel-ci-extract"
+ rm -rf "$install_root"
+ mkdir -p "$install_root" || return 1
+ dpkg-deb -x "$image_package" "$install_root" || return 1
+ dpkg-deb -x "$1" "$install_root" || return 1
+ image="$install_root/boot/vmlinuz-$release"
+ modules="$install_root/lib/modules/$release"
+ cp "$btf" "$install_root/boot/btf-$release" || return 1
+ cp "$config" "$install_root/boot/config-$release" || return 1
+ [ -s "$image" ] && [ -d "$modules" ] || {
+ echo "kernel packages did not contain image and modules for $release" >&2
+ return 1
+ }
+ validate_kernel_install "$install_root" || return 1
+ stage_kernel_install
+}
+
+run_id() {
+ id=${KERNEL_RUN_ID:-$PINNED_RUN_ID}
+ case "$id" in
+ '' | *[!0-9]*)
+ echo "KERNEL_RUN_ID must be numeric: $id" >&2
+ return 1
+ ;;
+ esac
+ printf '%s\n' "$id"
+}
+
+fetch() {
+ id=$(run_id) || return 1
+ [ "$(uname -m)" = x86_64 ] || {
+ echo "the kernel project publishes a CI kernel for x86-64 only" >&2
+ return 1
+ }
+ command -v gh >/dev/null 2>&1 || {
+ echo "gh is needed to download $ARTIFACT of $REPOSITORY run $id" >&2
+ return 1
+ }
+ download=build/kernel-ci-artifact
+ rm -rf "$download"
+ mkdir -p "$download" || return 1
+ echo "downloading $ARTIFACT of $REPOSITORY run $id" >&2
+ gh run download "$id" --repo "$REPOSITORY" --name "$ARTIFACT" \
+ --dir "$download" || {
+ echo "cannot download $ARTIFACT of $REPOSITORY run $id" >&2
+ return 1
+ }
+ stage_kernel_ci_artifact "$download" || return 1
+ printf '%s\n' "$id" >"$kernel/kernel-run-id"
+}
+
+case "${1:-}" in
+fetch)
+ [ $# -eq 1 ] || { echo "usage: kernel-artifact.sh fetch" >&2; exit 2; }
+ fetch
+ ;;
+stage)
+ [ $# -eq 2 ] || { echo "usage: kernel-artifact.sh stage <dir>" >&2; exit 2; }
+ stage_kernel_ci_artifact "$staged_from"
+ ;;
+run-id)
+ run_id
+ ;;
+*)
+ echo "usage: kernel-artifact.sh fetch|stage <dir>|run-id" >&2
+ exit 2
+ ;;
+esac