From 460337a96914315aebeb4fc93d0767cd1e5be04a Mon Sep 17 00:00:00 2001 From: Anton Bobov Date: Sun, 2 Feb 2025 16:57:39 +0500 Subject: Add Wireguard online sync script --- wg-quick-sync | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 wg-quick-sync diff --git a/wg-quick-sync b/wg-quick-sync new file mode 100755 index 0000000..45fe06d --- /dev/null +++ b/wg-quick-sync @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# Update Wireguard running configuration without restart + +set -euo pipefail + +select_interface() { + select interface in $(wg show interfaces); do + if [ -z "$interface" ]; then + exit 1 + fi + echo "$interface" + return + done +} + +main() { + if [[ $(/usr/bin/id -u) -ne 0 ]]; then + sudo "$(realpath "$0")" "$@" + exit + fi + + local interface + if [ $# = 0 ]; then + interface=$(select_interface) + else + interface="$1" + fi + + if [ -z "$interface" ]; then + echo "No wireguard interface." + exit 1 + fi + + wg syncconf "$interface" <(wg-quick strip "$interface") +} + +main "$@" -- cgit v1.2.3