diff options
| -rwxr-xr-x | wg-quick-sync | 37 |
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 "$@" |
