aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rwxr-xr-xfetch.sh4
-rw-r--r--standalone-kernel/fetch.sh18
-rwxr-xr-xstandalone-kernel/patch-kernel.sh19
4 files changed, 39 insertions, 4 deletions
diff --git a/README.md b/README.md
index 701efd2..c7a0406 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@ To use, add the following local manifest to your project, or include the `<remot
After that calls to `repo sync` and `mka bacon` will do the right thing, giving you a WireGuard-enabled ROM.
-## Standalone Kernel Module
+## Standalone Kernel Built-in Module
If you do not wish to run a custom ROM, but would still like to build a kernel with WireGuard, you may patch WireGuard into your kernel using the following script:
diff --git a/fetch.sh b/fetch.sh
index 6e0b8b9..9d089e9 100755
--- a/fetch.sh
+++ b/fetch.sh
@@ -12,7 +12,7 @@ fetch_wireguard() {
[[ -d wireguard && -f wireguard/.version && $(< wireguard/.version) == "$WIREGUARD_VERSION" ]] && return 0
rm -rf wireguard
mkdir wireguard
- curl -A "$USER_AGENT" -L "https://git.zx2c4.com/WireGuard/snapshot/WireGuard-$WIREGUARD_VERSION.tar.xz" | tar -C "wireguard" --strip-components=1 -xJf -
+ curl -A "$USER_AGENT" -LSs "https://git.zx2c4.com/WireGuard/snapshot/WireGuard-$WIREGUARD_VERSION.tar.xz" | tar -C "wireguard" --strip-components=1 -xJf -
echo "$WIREGUARD_VERSION" > wireguard/.version
}
@@ -20,7 +20,7 @@ fetch_libmnl() {
[[ -d libmnl && -f libmnl/.version && $(< libmnl/.version) == "$LIBMNL_VERSION" ]] && return 0
rm -rf libmnl
mkdir libmnl
- curl -A "$USER_AGENT" -L "https://www.netfilter.org/projects/libmnl/files/libmnl-$LIBMNL_VERSION.tar.bz2" | tar -C libmnl --strip-components=1 -xjf -
+ curl -A "$USER_AGENT" -LSs "https://www.netfilter.org/projects/libmnl/files/libmnl-$LIBMNL_VERSION.tar.bz2" | tar -C libmnl --strip-components=1 -xjf -
echo "$LIBMNL_VERSION" > libmnl/.version
}
diff --git a/standalone-kernel/fetch.sh b/standalone-kernel/fetch.sh
new file mode 100644
index 0000000..dcc25de
--- /dev/null
+++ b/standalone-kernel/fetch.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+set -e
+USER_AGENT="WireGuard-AndroidROMBuild/0.1 ($(uname -a))"
+
+[[ $(( $(date +%s) - $(stat -c %Y "net/wireguard/.check" 2>/dev/null || echo 0) )) -gt 86400 ]] || exit 0
+
+[[ $(curl -A "$USER_AGENT" -LSs https://git.zx2c4.com/WireGuard/refs/) =~ snapshot/WireGuard-([0-9.]+)\.tar\.xz ]]
+
+if [[ -f net/wireguard/version.h && $(< net/wireguard/version.h) == *${BASH_REMATCH[1]}* ]]; then
+ touch net/wireguard/.check
+ exit 0
+fi
+
+rm -rf net/wireguard
+mkdir -p net/wireguard
+curl -A "$USER_AGENT" -LsS "https://git.zx2c4.com/WireGuard/snapshot/WireGuard-${BASH_REMATCH[1]}.tar.xz" | tar -C "net/wireguard" -xJf - --strip-components=2 "WireGuard-${BASH_REMATCH[1]}/src"
+sed -i 's/tristate/bool/;s/default m/default y/;' net/wireguard/Kconfig
+touch net/wireguard/.check
diff --git a/standalone-kernel/patch-kernel.sh b/standalone-kernel/patch-kernel.sh
index 0d45f7a..dfe45e7 100755
--- a/standalone-kernel/patch-kernel.sh
+++ b/standalone-kernel/patch-kernel.sh
@@ -1 +1,18 @@
-echo work in progress
+#!/bin/bash
+
+cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
+K="$1"
+
+if [[ ! -e $K/net/Kconfig ]]; then
+ echo "You must specify the location of kernel sources as the first argument." >&2
+ exit 1
+fi
+
+[[ $(< "$K/net/Makefile") == *wireguard* ]] || sed -i "/^obj-\\\$(CONFIG_NETFILTER).*+=/a obj-\$(CONFIG_WIREGUARD) += wireguard/" "$K/net/Makefile"
+[[ $(< "$K/net/Kconfig") == *wireguard* ]] || sed -i "/^if INET\$/a source \"net/wireguard/Kconfig\"" "$K/net/Kconfig"
+[[ $(< "$K/.gitignore") == *wireguard* ]] || echo "net/wireguard/" >> "$K/.gitignore"
+
+cp fetch.sh "$K/scripts/fetch-latest-wireguard.sh"
+chmod +x "$K/scripts/fetch-latest-wireguard.sh"
+
+[[ $(< "$K/scripts/Kbuild.include") == *fetch-latest-wireguard.sh* ]] || echo '$(shell scripts/fetch-latest-wireguard.sh)' >> "$K/scripts/Kbuild.include"