#!/usr/bin/env bash # AmneziaWG as a system-wide VPN: amneziawg-windows's tunnel (amneziawg-go on Wintun, its # firewall that blocks what leaves outside a full tunnel, its DNS and routes), built from its # pinned commit as awg-tunnel.exe rather than its tunnel.dll: the same Run() a tunnel service # makes, with a main that takes the config's path and the tunnel's name, and its log in a # file beside the config (not its ring log). Wintun's signed driver DLL from wintun.net, # pinned as amneziawg-windows's own build pins it. # # tools/build-amneziawg.sh OUT_DIR (needs git, go, curl, unzip) set -euo pipefail . "$(dirname "$0")/lib.sh" OUT=$(realpath -m "${1:?output directory}") COMMIT=e90531d15802cb976773f3b63443bc281f738ca3 VERSION=0-unstable-2026-08-14+e90531d WINTUN_URL=https://www.wintun.net/builds/wintun-0.14.1.zip WINTUN_SHA256=07c256185d6ee3652e09fa55c0b673e2624b565e02c4b9091c79ca7d2f24ef51 WORK=$(mktemp -d) trap 'rm -rf "$WORK"' EXIT clone_commit https://github.com/amnezia-vpn/amneziawg-windows "$COMMIT" "$WORK/src" cd "$WORK/src" # Its exports (tunnel.dll's, through cgo) out; a main of ours in. rm main.go grep -q 'err = ringlogger.InitGlobalLogger("TUN")' service.go || { echo "service.go changed: no ring logger to replace"; exit 1; } sed -i 's|err = ringlogger.InitGlobalLogger("TUN")|err = nil|' service.go sed -i '/"github.com\/amnezia-vpn\/amneziawg-windows\/v3\/ringlogger"/d' service.go cat > proxysuite_main.go <<'GO' /* SPDX-License-Identifier: MIT * * Proxy Suite's AmneziaWG tunnel service: run by the Service Control Manager as * `awg-tunnel `, as amneziawg-windows's tunnel.dll is from its * client's service. Its log goes to .log, written anew at each start. */ package main import ( "fmt" "log" "os" ) func main() { if len(os.Args) != 3 { fmt.Fprintln(os.Stderr, "usage: awg-tunnel (as a Windows service)") os.Exit(2) } confPath, name := os.Args[1], os.Args[2] if f, err := os.OpenFile(confPath+".log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600); err == nil { log.SetOutput(f) } text, err := os.ReadFile(confPath) if err != nil { log.Printf("reading %s: %v", confPath, err) os.Exit(1) } if err := Run(string(text), name); err != nil { log.Printf("the tunnel service: %v", err) os.Exit(1) } } GO export GOTOOLCHAIN=local GOFLAGS=-mod=mod CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o "$WORK/awg-tunnel.exe" . rm -rf "$OUT" && mkdir -p "$OUT" cp "$WORK/awg-tunnel.exe" "$OUT/" # Its license is the MIT text in its README. sed -n '/^```text/,/^```/p' README.md | sed '1d;$d' >"$OUT/LICENSE" grep -q 'Permission is hereby granted' "$OUT/LICENSE" || { echo "README.md: no license text"; exit 1; } fetch_pinned "$WINTUN_URL" "$WINTUN_SHA256" "$WORK/wintun.zip" unzip -q -o "$WORK/wintun.zip" -d "$WORK/wintun" cp "$WORK/wintun/wintun/bin/amd64/wintun.dll" "$OUT/" cp "$WORK/wintun/wintun/LICENSE.txt" "$OUT/wintun-LICENSE.txt" echo "$VERSION" >"$OUT/.version" echo "amneziawg $VERSION (windows) in $OUT"