diff options
author | 2019-10-13 20:00:26 +0200 | |
---|---|---|
committer | 2019-10-14 13:03:10 +0200 | |
commit | e3f0f43bb81119eafeb04b66cb7deacd5c1db743 (patch) | |
tree | 3141511288cc86bcf6b16eed3a28ba1590513555 /build-one.bash | |
download | android-wireguard-module-builder-e3f0f43bb81119eafeb04b66cb7deacd5c1db743.tar.xz android-wireguard-module-builder-e3f0f43bb81119eafeb04b66cb7deacd5c1db743.zip |
Initial commit
Diffstat (limited to 'build-one.bash')
-rwxr-xr-x | build-one.bash | 62 |
1 files changed, 62 insertions, 0 deletions
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" |