about summary refs log tree commit diff
path: root/modules/nm-mullvad/generate-mullvad-peer-list.sh
diff options
context:
space:
mode:
Diffstat (limited to 'modules/nm-mullvad/generate-mullvad-peer-list.sh')
-rwxr-xr-xmodules/nm-mullvad/generate-mullvad-peer-list.sh30
1 files changed, 30 insertions, 0 deletions
diff --git a/modules/nm-mullvad/generate-mullvad-peer-list.sh b/modules/nm-mullvad/generate-mullvad-peer-list.sh
new file mode 100755
index 0000000..9fe5ed9
--- /dev/null
+++ b/modules/nm-mullvad/generate-mullvad-peer-list.sh
@@ -0,0 +1,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