#!/usr/bin/env bash # script to build latest wireguard module and wg(8) utility # exit if a command fails set -o errexit # display last non-zero exit code in a failed pipeline set -o pipefail # subshells and functions inherit ERR traps set -E # install dependencies if needed sudo apt-get install -y libmnl-dev libelf-dev linux-headers-"$(uname -r)" build-essential pkg-config git resolvconf # create build directory BUILD_DIR="$(mktemp -d)" # remove the build directory on exit function cleanup { rm -rf "${BUILD_DIR}" } trap cleanup EXIT # specify directory for wireguard module MODULE_DIR="${BUILD_DIR}"/wireguard-linux-compat # specify directory for wg(8) TOOL_DIR="${BUILD_DIR}"/wireguard-tools # clone the kernel module source git clone https://git.zx2c4.com/wireguard-linux-compat "${MODULE_DIR}" # clone the wg(8) utility source git clone https://git.zx2c4.com/wireguard-tools "${TOOL_DIR}" # compile and install the module make -C "${MODULE_DIR}"/src -j"$(nproc)" sudo make -C "${MODULE_DIR}"/src install # compile and install wg(8) make -C "${TOOL_DIR}"/src -j"$(nproc)" sudo make -C "${TOOL_DIR}"/src install # restart wireguard sudo systemctl restart wg-quick@wg0