| mullvad - dotfiles - These are my dotfiles. There are many like it, but these a… | |
| git clone git://jay.scot/dotfiles | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| mullvad (963B) | |
| --- | |
| 1 #!/bin/sh | |
| 2 gw="$(route -n show | awk '$1 == "default" { print $2 }')" | |
| 3 awk -v gw="$gw" ' | |
| 4 $1 == "PrivateKey" { key = $3 } | |
| 5 $1 == "Address" { | |
| 6 addr = $3 | |
| 7 sub(/,.*/, "", addr) | |
| 8 } | |
| 9 $1 == "DNS" { dns = $3 } | |
| 10 $1 == "PublicKey" { peer = $3 } | |
| 11 $1 == "AllowedIPs" { | |
| 12 aip = $3 | |
| 13 sub(/,.*/, "", aip) | |
| 14 } | |
| 15 $1 == "Endpoint" { | |
| 16 endpoint = $3 | |
| 17 sub(/:/, " ", endpoint) | |
| 18 } | |
| 19 END { | |
| 20 epip = substr(endpoint, 1, index(endpoint, " ")-1) | |
| 21 ifip = substr(addr, 1, index(addr, "/")-1) | |
| 22 printf("ifconfig wg0 create wgkey %s wgpeer %s wgendpoint %s wga… | |
| 23 printf("ifconfig wg0 %s\n", addr) | |
| 24 printf("route nameserver wg0 %s\n", dns) | |
| 25 printf("route add %s %s\n", epip, gw) | |
| 26 printf("route change default %s\n", ifip) | |
| 27 printf("curl https://am.i.mullvad.net/connected\n") | |
| 28 printf("trap '\''ifconfig wg0 destroy; route delete %s; route ad… | |
| 29 printf("while read -r ch; do [ \"$ch\" = q ] && break; done </de… | |
| 30 }' "$@" | doas /bin/sh -ex | |
| 31 |