#!/usr/bin/env bash # script to build latest wireguard module and wg(8) utility # DISCLAIMER: The logic used to retrieve the proper headers is fragile at best. # 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 build-essential pkg-config # create build directory BUILD_DIR="$(mktemp -d)" # remove the build directory on exit function cleanup { rm -rf "${BUILD_DIR}" } trap cleanup EXIT # retrieve debian codename CODENAME="$(grep CODENAME /etc/os-release | cut -d"=" -f2)" # retrieve kernel full version KERNEL="$(uname -r)" # retrieve kernel short version KERNEL_SHORT="${KERNEL//-pve/}" # download appropriate kernel headers wget --directory-prefix="${BUILD_DIR}" http://download.proxmox.com/debian/pve/dists/"$CODENAME"/pve-no-subscription/binary-amd64/pve-headers-"${KERNEL}"_"${KERNEL_SHORT}"_amd64.deb # install the kernel headers sudo dpkg -i "${BUILD_DIR}"/pve-headers-"${KERNEL}"_"${KERNEL_SHORT}"_amd64.deb # 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