github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/testdata/sh/update-kernel-deps.sh (about) 1 #!/bin/bash 2 3 set -euo pipefail 4 5 readonly docker="${CONTAINER_ENGINE:-docker}" 6 7 extract_oci_image() { 8 local image_name=$1 9 local target_directory=$2 10 11 echo -n "Fetching $image_name... " 12 13 # We abuse the --output flag of docker buildx to obtain a copy of the image. 14 # This is simpler than creating a temporary container and using docker cp. 15 # It also automatically fetches the image for us if necessary. 16 if ! echo "FROM $image_name" | "$docker" buildx build --quiet --pull --output="$target_directory" - &> /dev/null; then 17 echo "failed" 18 return 1 19 fi 20 21 echo "ok" 22 return 0 23 } 24 25 tmp=$(mktemp -d) 26 27 cleanup() { 28 rm -r "$tmp" 29 } 30 31 trap cleanup EXIT 32 33 # Download and process libbpf.c 34 curl -fL "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/tools/lib/bpf/libbpf.c?h=v$KERNEL_VERSION" -o "$tmp/libbpf.c" 35 "./internal/cmd/gensections.awk" "$tmp/libbpf.c" | gofmt > "./elf_sections.go" 36 37 # Download and process vmlinux and btf_testmod 38 extract_oci_image "ghcr.io/cilium/ci-kernels:$KERNEL_VERSION" "$tmp" 39 40 "/lib/modules/$(uname -r)/build/scripts/extract-vmlinux" "$tmp/boot/vmlinuz" > "$tmp/vmlinux" 41 42 objcopy --dump-section .BTF=/dev/stdout "$tmp/vmlinux" /dev/null | gzip > "btf/testdata/vmlinux.btf.gz" 43 find "$tmp/lib/modules" -type f -name bpf_testmod.ko -exec objcopy --dump-section .BTF="btf/testdata/btf_testmod.btf" {} /dev/null \;