You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
924 B

  1. #!/bin/bash
  2. #re='^[0-9]{1,3}$'
  3. if ! [[ $IP =~ ^[0-9]{1,3}$ ]] ; then
  4. echo "error: Please set IP variable (with IP=1-254. See https://phpipam.altinea.fr" >&2; exit 1
  5. fi
  6. exit 1;
  7. mkdir -p /etc/wireguard/keys
  8. umask 077 && wg genkey > /etc/wireguard/keys/private.key && wg pubkey < /etc/wireguard/keys/private.key > /etc/wireguard/keys/public.key && umask 0022
  9. IP4="10.17.25.$IP"
  10. IP6="fd42:42:42:25"`printf '%.2x\n' $IP`"::"
  11. echo "[Interface]
  12. Address = $IP4/32
  13. Address = $IP6/64
  14. SaveConfig = false
  15. PostUp = wg set %i private-key /etc/wireguard/keys/private.key
  16. [Peer]
  17. PublicKey = iu3I09FtiVDIOuiU83JvpfJkg4yiCxolqcFsXbz5Ixc=
  18. AllowedIPs = 10.17.24.0/22, fd42:42:42::/48
  19. Endpoint = vpn.altinea.fr:58212
  20. PersistentKeepalive = 25" > /etc/wireguard/wg0.conf
  21. systemctl enable wg-quick@wg0.service && systemctl daemon-reload && systemctl start wg-quick@wg0
  22. echo -n "Clé publique : "
  23. cat /etc/wireguard/keys/public.key
  24. exit 0;