From 2e446c9a48f4995a60ee60a66b3993e0029ffb31 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Tue, 11 Feb 2025 18:38:29 +0000 Subject: [PATCH] Initial mullvad-speedtest implementation --- Dockerfile | 12 ++++++++++++ setup.sh | 10 ++++++++++ speedtest.sh | 24 ++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 Dockerfile create mode 100755 setup.sh create mode 100755 speedtest.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1195917 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM librespeed-cli:latest + +WORKDIR /tmp +COPY setup.sh . +RUN chmod +x setup.sh +RUN ./setup.sh + +COPY speedtest.sh / +RUN chmod +x /speedtest.sh + +ENTRYPOINT ["speedtest.sh"] + diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..1888eeb --- /dev/null +++ b/setup.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# Download the Mullvad signing key +sudo curl -fsSLo /usr/share/keyrings/mullvad-keyring.asc https://repository.mullvad.net/deb/mullvad-keyring.asc + +# Add the Mullvad repository server to apt +echo "deb [signed-by=/usr/share/keyrings/mullvad-keyring.asc arch=$( dpkg --print-architecture )] https://repository.mullvad.net/deb/stable $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mullvad.list + +# Install the package +sudo apt update +sudo apt install mullvad-vpn diff --git a/speedtest.sh b/speedtest.sh new file mode 100755 index 0000000..6a24f4e --- /dev/null +++ b/speedtest.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +node_ids=$(mullvad relay list | grep -oE '[a-z]{2}-[a-z]{3}-\b(wg|ovpn)\b-[0-9]+') +IFS=$'\n' read -r -d '' -a node_ids_arr <<< "$node_ids" + +set -e pipefail + +results='{}' +for node in "${node_ids_arr[@]}"; do + mullvad relay set location "$node" >/dev/null + if ! mullvad connect --wait >/dev/null; then + echo "$node->WARN: failed to connect, skipping" >&2 + continue + fi + + echo "$node->INFO: connected to node" + test_output=$(librespeed-cli --no-icmp --json | jq '.[0]') + + echo "$node->INFO: ping: $(jq '.ping' <<< $test_output)ms, jitter: $(jq '.jitter' <<< $test_output)ms, download: $(jq '.download' <<< $test_output)mbps, upload: $(jq '.upload' <<< $test_output)mbps" + results=$(jq --arg node "$node" --argjson test_output "$test_output" '. + {($node): $test_output}' <<< "$results") + + mullvad disconnect --wait >/dev/null + echo "$results" > /tmp/mullvad-speedtest-results.json +done