#!/bin/bash -e { read -r AN; read -r PRV; } < <(pass mullvad | sed -n '1p; s/^Privkey:\s*//p') ADDRESS="$(curl 'https://api.mullvad.net/wg/' \ -d "account=$AN" --data-urlencode "pubkey=$(wg pubkey <<< "$PRV")")" j="$(curl 'https://api.mullvad.net/app/v1/relays/')" q='.wireguard.relays[] | "\(.hostname) \(.ipv4_addr_in) \(.public_key)"' DNS="$(jq -r '.wireguard.ipv4_gateway' <<< "$j")" while read -r file endpoint pubkey; do cat < "$file.conf" [Interface] PrivateKey = $PRV Address = $ADDRESS DNS = $DNS [Peer] PublicKey = $pubkey AllowedIPs = 0.0.0.0/0,::0/0 Endpoint = $endpoint:51820 EOF done < <(jq -r "$q" <<< "$j")