Last active
September 28, 2024 21:31
-
-
Save 1player/e9cadfef833d5eb5a23c30223f560147 to your computer and use it in GitHub Desktop.
Script to set up Mullvad VPN from Wireguard config files (+ Tailscale VPN support)
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
#!/bin/bash | |
# | |
# Requires: wg-quick from wireguard-tools package. | |
# | |
# How to configure: go on your Mullvad account page and download the | |
# Wireguard configuration for all countries. | |
# Unpack the archive at $HOME/.config/mullvad/ | |
# | |
# Then run `mullvad.sh up <2-char country code>` | |
# and `mullvad.sh down` to tear it down. | |
set -euo pipefail | |
CONFIGS_DIR=$HOME/.config/mullvad | |
RUNTIME_CONFIG=$XDG_RUNTIME_DIR/mullvad.conf | |
usage() { | |
echo "usage:" | |
echo " $(basename "$0") up <2-char country code>" | |
echo " $(basename "$0") down" | |
exit 1 | |
} | |
if [ $# -lt 1 ]; then | |
usage | |
fi | |
case "$1" in | |
"up") | |
if [ $# -ne 2 ]; then | |
usage | |
fi | |
country=$2 | |
chosen=$(find "$CONFIGS_DIR" -name "mullvad-$country*.conf" | sort -R | head -1) | |
if [ "$chosen" = "" ]; then | |
echo "Country $country not found." | |
exit 1 | |
fi | |
# Make tailscale work with mullvad | |
awk -f - "$chosen" <<EOF > "$RUNTIME_CONFIG" | |
/\[Interface\]/ { | |
print; | |
print "PostUp = ip rule add table 52"; | |
print "PreDown = ip rule del table 52"; | |
next | |
} | |
1 | |
EOF | |
wg-quick up "$RUNTIME_CONFIG" | |
;; | |
"down") | |
wg-quick down "$RUNTIME_CONFIG" | |
rm "$RUNTIME_CONFIG" | |
;; | |
*) | |
usage | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment