40-vpnclient-set-ipv6 853 B

12345678910111213141516171819202122232425262728
  1. #!/bin/bash
  2. is_ip6addr_set() {
  3. local ip6_addr=${1}
  4. ip address show dev "${gateway_interface}" 2> /dev/null | grep -q "${ip6_addr}/"
  5. }
  6. ip6_addr=$(yunohost app setting "vpnclient" "ip6_addr")
  7. # cf https://openvpn.net/community-resources/reference-manual-for-openvpn-2-4/#environmental-variables for where 'dev' comes from
  8. gateway_interface=${dev}
  9. if [[ -n "${ip6_addr}" ]] && [[ "${ip6_addr}" != none ]]; then
  10. if ! is_ip6addr_set "${ip6_addr}"; then
  11. ip address add "${ip6_addr}/64" dev "${gateway_interface}"
  12. fi
  13. echo "[INFO] IPv6 delegated prefix found"
  14. echo "[INFO] IPv6 address computed from the delegated prefix: ${ip6_addr}"
  15. if is_ip6addr_set "${ip6_addr}"; then
  16. echo "[ OK ] IPv6 address correctly set"
  17. else
  18. echo "[FAIL] No IPv6 address set" >&2
  19. exit 1
  20. fi
  21. else
  22. echo "[INFO] No IPv6 delegated prefix found"
  23. fi