Created
April 19, 2020 11:12
-
-
Save tpretz/5ea1226517d95361f063f621e45de0a6 to your computer and use it in GitHub Desktop.
PIA wireguard enroll
This file contains 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 data.json from the PIA application /opt/piavpn/etc/data.json in the working dir | |
USR="" | |
PASS="" | |
LOC="uk" | |
# generated public key | |
PKEY="" | |
PIAAPI="https://www.privateinternetaccess.com" | |
# get token | |
TOK=$(curl -X POST \ | |
-H "Content-Type: application/json" \ | |
-d "{\"username\":\"$USR\",\"password\":\"$PASS\"}" \ | |
"$PIAAPI/api/client/v2/token" | jq -r '.token') | |
echo "got token: $TOK" | |
if [ -z "$TOK" ]; then | |
echo "no token, exiting" | |
exit 1 | |
fi | |
WG_URL=$(cat data.json | jq -r ".locations.$LOC.wireguardUDP") | |
if [ -z "$WG_URL" ]; then | |
echo "no wg region, exiting" | |
exit 1 | |
fi | |
# should TLS verify here | |
curl -Gkv \ | |
--data-urlencode "pubkey=$PKEY" \ | |
--data-urlencode "pt=$TOK" \ | |
"https://$WG_URL/addKey" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment