Repository navigation
Expand file tree
/
Copy pathbuild-kernel.sh
More file actions
108 lines (99 loc) · 4.87 KB
/
Copy pathbuild-kernel.sh
File metadata and controls
108 lines (99 loc) · 4.87 KB
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
#!/usr/bin/env bash
# build-kernel.sh: build the kernels and signed boot files that packages.list marks <pkgbase>::kernel,
# <pkgbase>::signed and <pkgbase>::signed-kernel, and add them to the signed [mainstream] repo. Used by
# .github/workflows/kernels.yml and kernel-update.yml; build-repo.sh only keeps their published builds.
#
# build-kernel.sh plan JSON list of {"kernel", "boot", "signed"} for each listed entry
# whose recipe version is not live
# build-kernel.sh build <pkgbase> build and sign one kernel into OUTDIR
# build-kernel.sh assemble add every live package OUTDIR does not replace, write the db
#
# Env: PUBLISHED_ASSETS (snapshot from scripts/repo_safety.py, required), GPGKEY, REPO, OUTDIR,
# FORCE_REBUILD (names or "all": plan lists them even when live), BUILDDIR (makepkg's).
set -uo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO="${REPO:-mainstream}"
OUTDIR="${OUTDIR:-$ROOT/out}"
LIST="$ROOT/packages.list"
[ -n "${PUBLISHED_ASSETS:-}" ] && [ -r "$PUBLISHED_ASSETS" ] \
|| { echo "a readable published asset snapshot is required" >&2; exit 1; }
# "<pkgbase> <tag>" for each entry this script builds.
kernels() {
sed -E 's/#.*//; s/^[[:space:]]+//; s/[[:space:]]+$//' "$LIST" \
| sed -nE 's/^([^:]+)::(kernel|signed|signed-kernel)$/\1 \2/p'
}
srcinfo() {
local name="$1" dir="$2"
[ -f "$ROOT/pkgbuilds/$name/PKGBUILD" ] || { echo "missing kernel recipe: pkgbuilds/$name" >&2; return 1; }
rm -rf "$dir"; cp -r "$ROOT/pkgbuilds/$name" "$dir" || return 1
( cd "$dir" && makepkg --printsrcinfo > .SRCINFO )
}
plan() {
local work name tag boot signed rc first=true
work="$(mktemp -d)"; trap 'rm -rf "$work"' RETURN
printf '['
while read -r name tag; do
srcinfo "$name" "$work/$name" >&2 || return 1
python "$ROOT/scripts/repo_safety.py" is-published "$work/$name/.SRCINFO" "$PUBLISHED_ASSETS" >&2
rc=$?
case $rc in
0) echo "$name: recipe version is live, nothing to build" >&2 ;;
3) echo "$name: recipe version is not live, building" >&2
boot=false signed=false
case $tag in kernel|signed-kernel) boot=true ;; esac
case $tag in signed|signed-kernel) signed=true ;; esac
$first || printf ','
printf '{"kernel":"%s","boot":%s,"signed":%s}' "$name" "$boot" "$signed"; first=false ;;
*) return 1 ;;
esac
done < <(kernels)
printf ']\n'
}
build() {
local name="$1" dir deps d official=() sign=()
kernels | cut -d' ' -f1 | grep -qxF "$name" \
|| { echo "$name is not listed as $name::kernel, $name::signed or $name::signed-kernel" >&2; return 1; }
dir="$(mktemp -d)/$name"
srcinfo "$name" "$dir" || return 1
# Each package's own depends are for installing it (the NVIDIA modules name the NVIDIA userspace).
deps="$({ sed -nE 's/^[[:space:]]*(makedepends|checkdepends) = //p' "$dir/.SRCINFO"
sed -nE '/^pkgname = /q; s/^[[:space:]]*depends = //p' "$dir/.SRCINFO"; } \
| sed -E 's/[<>=:].*//' | sort -u)"
while IFS= read -r d; do
[ -n "$d" ] && pacman -Sp "$d" </dev/null >/dev/null 2>&1 && official+=("$d")
done <<<"$deps"
[ ${#official[@]} -eq 0 ] || sudo pacman -S --needed --noconfirm --asdeps "${official[@]}" || return 1
[ -n "${GPGKEY:-}" ] && sign=(--sign --key "$GPGKEY")
mkdir -p "$OUTDIR"
(
cd "$dir" || exit 1
export PKGDEST="$OUTDIR"
# Before prepare(), which writes pkgrel into the kernel release string. No pkgver() to resolve.
python "$ROOT/scripts/repo_safety.py" bump-pkgrel PKGBUILD .SRCINFO "$PUBLISHED_ASSETS" || exit 1
makepkg -f --noconfirm --nodeps "${sign[@]}"
)
}
assemble() {
local pkgs
python "$ROOT/scripts/repo_safety.py" assemble "$PUBLISHED_ASSETS" "$OUTDIR" || return 1
shopt -s nullglob
pkgs=("$OUTDIR"/*.pkg.tar.zst)
rm -f "$OUTDIR/$REPO".db* "$OUTDIR/$REPO".files*
if [ -n "${GPGKEY:-}" ]; then
repo-add --sign --key "$GPGKEY" "$OUTDIR/$REPO.db.tar.gz" "${pkgs[@]}" || return 1
else
repo-add "$OUTDIR/$REPO.db.tar.gz" "${pkgs[@]}" || return 1
fi
# Real files rather than repo-add's symlinks, as build-repo.sh publishes them.
cp -f --remove-destination "$OUTDIR/$REPO.db.tar.gz" "$OUTDIR/$REPO.db"
cp -f --remove-destination "$OUTDIR/$REPO.files.tar.gz" "$OUTDIR/$REPO.files"
[ -f "$OUTDIR/$REPO.db.tar.gz.sig" ] && cp -f --remove-destination "$OUTDIR/$REPO.db.tar.gz.sig" "$OUTDIR/$REPO.db.sig"
[ -f "$OUTDIR/$REPO.files.tar.gz.sig" ] && cp -f --remove-destination "$OUTDIR/$REPO.files.tar.gz.sig" "$OUTDIR/$REPO.files.sig"
return 0
}
case "${1:-}" in
plan) plan ;;
build) [ -n "${2:-}" ] || { echo "usage: $0 build <pkgbase>" >&2; exit 1; }; build "$2" ;;
assemble) assemble ;;
*) echo "usage: $0 plan | build <pkgbase> | assemble" >&2; exit 1 ;;
esac