#!/bin/sh # SPDX-License-Identifier: GPL-2.0 # # Copyright (C) 2015-2018 Jason A. Donenfeld . All Rights Reserved. set -e if [ "$(id -u)" -ne 0 ]; then echo "[-] You must be root to run this program." exit 1 fi echo "[+] Preparing build directory in /usr/src/wireguard" cd / rm -rf /usr/src/wireguard trap 'echo "[+] Cleaning up build directory"; cd /; rm -rf /usr/src/wireguard' EXIT mkdir -p /usr/src/wireguard cd /usr/src/wireguard echo "[+] Installing dependencies" pkg_add bash gmake git xz go VERSION_MIN_GOLANG=1.12 VERSION_INSTALLED_GOLANG="$(go version | sed -E -n 's/^go version go([^ ]+) .*/\1/p')" if [ "$(printf '%s\n%s\n' "$VERSION_INSTALLED_GOLANG" "$VERSION_MIN_GOLANG" | sort -V | head -n 1)" != "$VERSION_MIN_GOLANG" ]; then echo "[+] Fetching latest Go version" gorelease="$(ftp -v -o - https://golang.org/src/)" VERSION_GOLANG="$(echo "$gorelease" | sed -E -n 's/.*goVersion = "go([0-9.]+)";.*/\1/p')" echo "[+] System Go $VERSION_INSTALLED_GOLANG too old, downloading and compiling Go $VERSION_GOLANG" { ftp -v -o - "https://dl.google.com/go/go$VERSION_GOLANG.src.tar.gz" || exit 1; } | gzip -d | tar -xf - cd go/src ./make.bash cd .. export PATH="/usr/src/wireguard/go/bin:$PATH" fi echo "[+] Fetching latest versions" distros="$(ftp -v -o - https://build.wireguard.com/distros.txt)" VERSION_KMODTOOLS="$(echo "$distros" | sed -E -n 's/^upstream kmodtools ([^ ]+).*/\1/p')" VERSION_GO="$(echo "$distros" | sed -E -n 's/^upstream go ([^ ]+).*/\1/p')" URI_KMODTOOLS="https://git.zx2c4.com/WireGuard/snapshot/WireGuard-$VERSION_KMODTOOLS.tar.xz" URI_GO="https://git.zx2c4.com/wireguard-go/snapshot/wireguard-go-$VERSION_GO.tar.xz" echo "[+] Fetching and unpacking archives" { ftp -v -o - "$URI_KMODTOOLS" || exit 1; } | xz -d | tar -xf - { ftp -v -o - "$URI_GO" || exit 1; } | xz -d | tar -xf - echo "[+] Building wg(8) and wg-quick(8) tools" sed -i 's/install -v/install/g;s/@install/install/g' "WireGuard-$VERSION_KMODTOOLS/src/tools/Makefile" gmake -j$(sysctl -n hw.ncpu) -C "WireGuard-$VERSION_KMODTOOLS/src/tools" WITH_WGQUICK=yes PREFIX=/usr/local install echo "[+] Building wireguard-go" sed -i 's/install -v/install/g;s/@install/install/g' "wireguard-go-$VERSION_GO/Makefile" gmake -j$(sysctl -n hw.ncpu) -C "wireguard-go-$VERSION_GO" PREFIX=/usr/local install