Created
December 10, 2024 01:38
-
-
Save toriato/3ed8a4d64f8bba914b0a5337509a95f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# https://github.com/bubuntux/nordlynx/blob/main/root/etc/services.d/wireguard/run | |
set -o errexit | |
set -o pipefail | |
if [[ "${TRACE-0}" == "1" ]]; then | |
set -o xtrace | |
fi | |
API_ENTRYPOINT=${API_ENTRYPOINT:-"https://api.nordvpn.com/v1"} | |
API_SELECT=${API_SELECT:-'select(.locations[].country.code == "JP" and (.services[].identifier == "vpn") and (.technologies[].identifier == "wireguard_udp"))'} | |
if [[ -z "${ENDPOINT}" || -z "${PUBLIC_KEY}" ]]; then | |
readarray -t servers < <(curl -sSL "${API_ENTRYPOINT}/servers?limit=0" | jq -c ".[] | ${API_SELECT}") | |
# pick random server | |
server="${servers[ $RANDOM % ${#servers[@]} ]}" | |
ENDPOINT="$(echo "$server" | jq -r '.hostname'):52820" | |
PUBLIC_KEY="$(echo "$server" | jq -r '.technologies[] | select(.identifier == "wireguard_udp") | .metadata[] | select(.name == "public_key") | .value')" | |
fi | |
cat <<-EOF | |
[Interface] | |
PrivateKey = ${PRIVATE_KEY} | |
ListenPort = ${LISTEN_PORT:-"51820"} | |
Address = ${ADDRESS:-"10.5.0.2/32"} | |
DNS = ${DNS:-"103.86.96.100,103.86.99.100"} | |
Table = ${TABLE} | |
PreUp = ${PRE_UP} | |
PostUp = ${POST_UP} | |
PreDown = ${PRE_DOWN} | |
PostDown = ${POST_DOWN} | |
[Peer] | |
Endpoint = ${ENDPOINT} | |
PublicKey = ${PUBLIC_KEY} | |
AllowedIPs = ${ALLOWED_IPS:-"0.0.0.0/0"} | |
PersistentKeepalive = ${PERSISTENT_KEEP_ALIVE:-"25"} | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment