From e3f0f43bb81119eafeb04b66cb7deacd5c1db743 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 13 Oct 2019 20:00:26 +0200 Subject: Initial commit --- build-one.bash | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 build-one.bash (limited to 'build-one.bash') diff --git a/build-one.bash b/build-one.bash new file mode 100755 index 0000000..3844271 --- /dev/null +++ b/build-one.bash @@ -0,0 +1,62 @@ +#!/bin/bash +set -ex + +[[ $# -eq 1 ]] || { echo "Usage: $0 KERNEL_NAME" >&2; exit 1; } +BASE="$(readlink -f "$(dirname "$(readlink -f "$0")")")" +KERNEL_DIR="$BASE/kernels/$1" +[[ -d $KERNEL_DIR ]] || { echo "Error: '$0' does not exist" >&2; exit 1; } + +# Step 1) Account for already built modules by hard linking new hashes to the old names. +first="" +while IFS='|' read -r hash ver; do + if [[ -f $BASE/out/wireguard-$hash.ko ]]; then + first="$hash" + break + fi +done < "$KERNEL_DIR/version-hashes.txt" +if [[ -n $first ]]; then + while IFS='|' read -r hash ver; do + [[ -f $BASE/out/wireguard-$hash.ko ]] || ln "$BASE/out/wireguard-$first.ko" "$BASE/out/wireguard-$hash.ko" + done < "$KERNEL_DIR/version-hashes.txt" + exit 0 +fi + +# Step 2) Make working directory. +D="$(mktemp -d)" +trap 'rm -rf "$D"' INT TERM EXIT +cd "$D" + +# Step 3) Initialize repo with manifests and fetch repositories. +mkdir -p manifest +cd manifest +git init +git config user.email "$(id -un)@$(hostname)" +git config user.name "$(id -un)" +cp "$KERNEL_DIR/manifest.xml" default.xml +git add default.xml +git commit -m "Initial commit" +cd .. +repo init -u ./manifest +mkdir -p .repo/local_manifests +cp "$BASE/files/wireguard.xml" .repo/local_manifests/ +repo sync + +# Step 4) Inject shim module and launch build. +mkdir -p wireguard +cp "$BASE/files/shim.make" wireguard/Makefile +exec 9>&1 +read -r output < <("$BASH" "$KERNEL_DIR/do.bash" 7>&1 >&9) +exec 9>- +[[ -f $output ]] + +# Step 5) Copy first module out and hard link the rest. +mkdir -p "$BASE/out" +first="" +while IFS='|' read -r hash vers; do + if [[ -z $first ]]; then + cp "$output" "$BASE/out/wireguard-$hash.ko" + first="$hash" + else + ln "$BASE/out/wireguard-$first.ko" "$BASE/out/wireguard-$hash.ko" + fi +done < "$KERNEL_DIR/version-hashes.txt" -- cgit v1.2.3-59-g8ed1b