summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Bobov <anton@bobov.name>2025-02-02 16:57:39 +0500
committerAnton Bobov <anton@bobov.name>2025-02-02 23:07:43 +0500
commit460337a96914315aebeb4fc93d0767cd1e5be04a (patch)
tree6396305de92f9793fbf5785a958752988f9a6311
parent709b8ea3f01d6658f4428f58fead82d350b7bf7e (diff)
Add Wireguard online sync script
-rwxr-xr-xwg-quick-sync37
1 files changed, 37 insertions, 0 deletions
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 "$@"