S04wireguard 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/sh
  2. source /opt/wz_mini/etc/rc.common
  3. source /opt/wz_mini/wz_mini.conf
  4. if [[ "$ENABLE_WIREGUARD" == "true" ]]; then
  5. if [[ "$WIREGUARD_IPV4" != "" ]]; then
  6. if [ -d /opt/wz_mini/etc/wireguard ]; then
  7. echo "wireguard dir exists"
  8. else
  9. mkdir -p /opt/wz_mini/etc/wireguard
  10. fi
  11. if [ ! -f /opt/wz_mini/etc/wireguard/privatekey ]; then
  12. (umask 277 && /opt/wz_mini/bin/wg genkey | /opt/wz_mini/bin/busybox tee /opt/wz_mini/etc/wireguard/privatekey | /opt/wz_mini/bin/wg pubkey > /opt/wz_mini/etc/wireguard/publickey)
  13. fi
  14. /opt/wz_mini/bin/busybox ip link add dev wg0 type wireguard
  15. /opt/wz_mini/bin/busybox ip address add dev wg0 "$WIREGUARD_IPV4"
  16. /opt/wz_mini/bin/wg set wg0 private-key /opt/wz_mini/etc/wireguard/privatekey
  17. /opt/wz_mini/bin/busybox ip link set wg0 up
  18. fi
  19. if [[ "$WIREGUARD_PEER_PUBLIC_KEY" != "" ]] && [[ "$WIREGUARD_PEER_ALLOWED_IPS" != "" ]] && [[ "$WIREGUARD_PEER_ENDPOINT" != "" ]] && [[ "$WIREGUARD_PEER_KEEP_ALIVE" != "" ]]; then
  20. /opt/wz_mini/bin/wg set wg0 peer "$WIREGUARD_PEER_PUBLIC_KEY" allowed-ips "$WIREGUARD_PEER_ALLOWED_IPS" endpoint "$WIREGUARD_PEER_ENDPOINT" persistent-keepalive "$WIREGUARD_PEER_KEEP_ALIVE"
  21. /opt/wz_mini/bin/busybox ip route add "$WIREGUARD_PEER_ALLOWED_IPS" dev wg0
  22. fi
  23. else
  24. echo "wireguard disabled"
  25. fi