summaryrefslogtreecommitdiff
path: root/wg-quick-sync
blob: 45fe06d01fdf079ed313f535667b5150c35ffc77 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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 "$@"