blob: 9fe5ed9f442a9ef8f3fb7783fc1524ee3cec8928 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p curl jq
set -euo pipefail
script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
output_file="$script_dir/mullvad-servers-list.nix"
servers_json=$(curl -Ss 'https://api.mullvad.net/www/relays/all')
readarray -t servers_arr < <(jq -c '.[] | select(.type == "wireguard")' <<< $servers_json)
printf '# @generated by generate-mullvad-peer-list.sh\n# Do not Edit.\n\n' > $output_file
printf '[\n' >> $output_file
for item in "${servers_arr[@]}"; do
hostname=$(jq -r '.hostname' <<< $item)
pubkey=$(jq -r '.pubkey' <<< $item)
endpoint=$(jq -r '.ipv4_addr_in' <<< $item)
cat <<EOF >> $output_file
{
id = "$hostname";
uuid = "$(uuidgen -n @url --sha1 --name "$hostname-$endpoint")";
pubKey = "$pubkey";
endpoint = "$endpoint";
}
EOF
done
printf ']' >> $output_file
|