aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-11-29 02:15:13 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2017-11-29 02:16:43 +0100
commit7ef9ee46554ffba0a5b7de4b68e6be0f8807a15d (patch)
tree46efb10e93cf1ef46c514cc61a549ff2b72f30d7
parentFall back to using readlink -f if no realpath (diff)
downloadandroid_kernel_wireguard-7ef9ee46554ffba0a5b7de4b68e6be0f8807a15d.tar.xz
android_kernel_wireguard-7ef9ee46554ffba0a5b7de4b68e6be0f8807a15d.zip
standalone: some people want to do things a la carte
-rw-r--r--README.md2
-rw-r--r--standalone/.gitignore1
-rw-r--r--standalone/README.md20
-rw-r--r--standalone/addonsd.sh37
-rwxr-xr-xstandalone/build-wg.sh53
-rwxr-xr-xstandalone/install.sh14
l---------standalone/wg-quick.bash1
7 files changed, 127 insertions, 1 deletions
diff --git a/README.md b/README.md
index 2d94f05..1d06d9f 100644
--- a/README.md
+++ b/README.md
@@ -19,4 +19,4 @@ Add the following local manifest to your project, or include the `<remote>` and
Tools
-----
-In addition to the kernel module, this repository also contains a version of [`wg-quick(8)`](https://git.zx2c4.com/WireGuard/about/src/tools/wg-quick.8) that works with Android 7's `ndc` command. Compared to the ordinary wg-quick, this one does not support `SaveConfig` and `{Pre,Post}{Up,Down}`. Put your configuration files into `/data/misc/wireguard/`. After that, the normal `wg-quick up|down` commands will work as usual.
+In addition to the kernel module, this repository also contains a version of [`wg-quick(8)`](https://git.zx2c4.com/WireGuard/about/src/tools/wg-quick.8) that works with Android 7's `ndc` command. Compared to the ordinary wg-quick, this one does not support `SaveConfig` and `{Pre,Post}{Up,Down}`. Put your configuration files into `/data/misc/wireguard/`. After that, the normal `wg-quick up|down` commands will work as usual. Users who only want the tools without having to use this inside a ROM may use the [standalone tool building/installing scripts](standalone/README.md).
diff --git a/standalone/.gitignore b/standalone/.gitignore
new file mode 100644
index 0000000..7f29ff5
--- /dev/null
+++ b/standalone/.gitignore
@@ -0,0 +1 @@
+wg
diff --git a/standalone/README.md b/standalone/README.md
new file mode 100644
index 0000000..87d7734
--- /dev/null
+++ b/standalone/README.md
@@ -0,0 +1,20 @@
+# Standalone WireGuard Tools for Android
+
+This currently contains a version of wg-quick.bash that works with
+Android 7's `ndc` command. It requires the WireGuard module to be
+part of your kernel, but after that, the usual `wg-quick up` and
+`wg-quick down` commands work normally.
+
+## Installation
+
+Build a `wg` binary for Android using the `build-wg.sh` script.
+Then copy this folder some place on your phone, and run `sh ./install.sh`
+as root. It should survive ROM flashes.
+
+## Usage
+
+Compared to the ordinary wg-quick, this one does not support SaveConfig
+and {Pre,Post}{Up,Down}.
+
+Put your configuration files into `/data/misc/wireguard/`. After that,
+the normal `wg-quick up|down` commands will work.
diff --git a/standalone/addonsd.sh b/standalone/addonsd.sh
new file mode 100644
index 0000000..90865d0
--- /dev/null
+++ b/standalone/addonsd.sh
@@ -0,0 +1,37 @@
+#!/sbin/sh
+
+. /tmp/backuptool.functions
+
+list_files() {
+cat <<_EOF
+xbin/wg
+xbin/wg-quick
+_EOF
+}
+
+case "$1" in
+ backup)
+ list_files | while read FILE DUMMY; do
+ backup_file $S/"$FILE"
+ done
+ ;;
+ restore)
+ list_files | while read FILE REPLACEMENT; do
+ R=""
+ [ -n "$REPLACEMENT" ] && R="$S/$REPLACEMENT"
+ [ -f "$C/$S/$FILE" ] && restore_file $S/"$FILE" "$R"
+ done
+ ;;
+ pre-backup)
+ # Stub
+ ;;
+ post-backup)
+ # Stub
+ ;;
+ pre-restore)
+ # Stub
+ ;;
+ post-restore)
+ # Stub
+ ;;
+esac
diff --git a/standalone/build-wg.sh b/standalone/build-wg.sh
new file mode 100755
index 0000000..d2bb5b1
--- /dev/null
+++ b/standalone/build-wg.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+
+set -e
+
+ARCH="arm64"
+ANDROID_PLATFORM="24"
+
+case "$ARCH" in
+ arm) ANDROID_MACHINE="arm-linux-androideabi"; ;;
+ arm64) ANDROID_MACHINE="aarch64-linux-android"; ;;
+ mips) ANDROID_MACHINE="mipsel-linux-android"; ;;
+ mips64) ANDROID_MACHINE="mips64el-linux-android"; ;;
+ x86) ANDROID_MACHINE="x86-linux-android"; ;;
+ x86_64) ANDROID_MACHINE="x86_64-linux-android"; ;;
+ *) echo "Error: unknown architecture" >&2; exit 1; ;;
+esac
+
+GCC_VERSION="4.9"
+ANDROID_PLATFORM="/opt/android-ndk/platforms/android-$ANDROID_PLATFORM/arch-$ARCH/usr"
+ANDROID_TOOLCHAIN="/opt/android-ndk/toolchains/$ANDROID_MACHINE-$GCC_VERSION/prebuilt/linux-$(uname -m)/bin"
+
+export PATH="$ANDROID_TOOLCHAIN:$PATH"
+export CC="$ANDROID_MACHINE-gcc --sysroot $ANDROID_PLATFORM"
+export LD="$ANDROID_MACHINE-ld --sysroot $ANDROID_PLATFORM"
+export CFLAGS="-O3 -fomit-frame-pointer -I$ANDROID_PLATFORM/include -fPIE"
+export LDFLAGS="-pie"
+
+trap 'cd /; rm -rf "$where"' EXIT
+where="$(mktemp -d)"
+here="$PWD"
+cd "$where"
+
+. "$here/../fetch.sh"
+
+cd libmnl
+./configure --enable-static --disable-shared --host="$ANDROID_MACHINE"
+make -j$(nproc)
+
+cd ..
+
+cd wireguard/src/tools
+export CFLAGS="$CFLAGS -I../../../libmnl/include"
+export LDFLAGS="$LDFLAGS -L../../../libmnl/src/.libs"
+make -j$(nproc)
+"$ANDROID_MACHINE-strip" wg
+mv wg "$here/wg"
+
+echo
+echo
+echo ===============================================
+echo Build complete:
+ls -l "$here/wg"
+echo ===============================================
diff --git a/standalone/install.sh b/standalone/install.sh
new file mode 100755
index 0000000..eaef86d
--- /dev/null
+++ b/standalone/install.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+mount -o rw,remount /system
+
+cp -v ./addonsd.sh /system/addon.d/40-wireguard.sh
+if [ -f ./wg ]; then
+ cp -v ./wg /system/xbin/wg
+else
+ echo "Warning: this directory does not contain wg. You may have forgotten to compile it." >&2
+fi
+cp -v ./wg-quick.bash /system/xbin/wg-quick
+chmod 755 /system/xbin/wg /system/xbin/wg-quick /system/addon.d/40-wireguard.sh
+mkdir -pvm 700 /data/misc/wireguard
+
+mount -o ro,remount /system
diff --git a/standalone/wg-quick.bash b/standalone/wg-quick.bash
new file mode 120000
index 0000000..f4eca54
--- /dev/null
+++ b/standalone/wg-quick.bash
@@ -0,0 +1 @@
+../wg-quick.bash \ No newline at end of file