mirror of
https://github.com/pia-foss/manual-connections.git
synced 2025-02-05 22:18:30 +00:00
Check more things (#2)
This commits will be reviewed in the next commit, to align coding style with the entire project. The merge request from @triffid included the following commits: * connect_to_wireguard_with_token: Check if "jq" and "curl" are available, allow script to issue multiple errors in a single invocation * connect_to_wireguard_with_token: ensure /etc/wireguard exists * connect_to_wireguard_with_token: only complain about ipv6 if it's not already disabled * get_region_and_token: allow specifying maximum latency via environment variable, retain 50ms default * connect_to_wireguard_with_token: pack tool checks within a function * get_region_and_token: rename maximum_allowed_latency -> MAX_LATENCY
This commit is contained in:
parent
53d2da47e3
commit
aac22fe847
|
@ -23,18 +23,35 @@
|
||||||
|
|
||||||
# PIA currently does not support IPv6. In order to be sure your VPN
|
# PIA currently does not support IPv6. In order to be sure your VPN
|
||||||
# connection does not leak, it is best to disabled IPv6 altogether.
|
# connection does not leak, it is best to disabled IPv6 altogether.
|
||||||
echo 'You should consider disabling IPv6 by running:
|
if [ $(sysctl -n net.ipv6.conf.all.disable_ipv6) -ne 1 ] || [ $(sysctl -n net.ipv6.conf.default.disable_ipv6) -ne 1 ]
|
||||||
sysctl -w net.ipv6.conf.all.disable_ipv6=1
|
then
|
||||||
sysctl -w net.ipv6.conf.default.disable_ipv6=1
|
echo 'You should consider disabling IPv6 by running:'
|
||||||
'
|
echo 'sysctl -w net.ipv6.conf.all.disable_ipv6=1'
|
||||||
|
echo 'sysctl -w net.ipv6.conf.default.disable_ipv6=1'
|
||||||
|
fi
|
||||||
|
|
||||||
|
# so we can print more than one error about missing tools in a single run
|
||||||
|
EXIT=0
|
||||||
|
|
||||||
|
function check_tool() {
|
||||||
|
COMMAND=$1
|
||||||
|
PACKAGE=$2
|
||||||
|
if ! command -v $COMMAND &>/dev/null
|
||||||
|
then
|
||||||
|
echo "$COMMAND could not be found"
|
||||||
|
echo "Please install $PACKAGE"
|
||||||
|
fi
|
||||||
|
EXIT=1
|
||||||
|
}
|
||||||
|
|
||||||
# check if the wireguard tools have been installed
|
# check if the wireguard tools have been installed
|
||||||
if ! command -v wg-quick &> /dev/null
|
check_tool wg-quick wireguard-tools
|
||||||
then
|
|
||||||
echo "wg-quick could not be found."
|
# check if curl has been installed
|
||||||
echo "Please install wireguard-tools"
|
check_tool curl curl
|
||||||
exit 1
|
|
||||||
fi
|
# check if jq has been installed
|
||||||
|
check_tool jq jq
|
||||||
|
|
||||||
# Check if the mandatory environment variables are set.
|
# Check if the mandatory environment variables are set.
|
||||||
if [[ ! $WG_SERVER_IP || ! $WG_HOSTNAME || ! $WG_TOKEN ]]; then
|
if [[ ! $WG_SERVER_IP || ! $WG_HOSTNAME || ! $WG_TOKEN ]]; then
|
||||||
|
@ -51,7 +68,13 @@ if [[ ! $WG_SERVER_IP || ! $WG_HOSTNAME || ! $WG_TOKEN ]]; then
|
||||||
echo as it will guide you through getting the best server and
|
echo as it will guide you through getting the best server and
|
||||||
echo also a token. Detailed information can be found here:
|
echo also a token. Detailed information can be found here:
|
||||||
echo https://github.com/pia-foss/manual-connections
|
echo https://github.com/pia-foss/manual-connections
|
||||||
exit 1
|
EXIT=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# exit if any required tools are missing
|
||||||
|
if [ $EXIT -ne 0 ]
|
||||||
|
then
|
||||||
|
exit $EXIT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create ephemeral wireguard keys, that we don't need to save to disk.
|
# Create ephemeral wireguard keys, that we don't need to save to disk.
|
||||||
|
@ -87,6 +110,7 @@ fi
|
||||||
# have resolvconf, which will result in the script failing.
|
# have resolvconf, which will result in the script failing.
|
||||||
# We will enforce the DNS after the connection gets established.
|
# We will enforce the DNS after the connection gets established.
|
||||||
echo -n "Trying to write /etc/wireguard/pia.conf... "
|
echo -n "Trying to write /etc/wireguard/pia.conf... "
|
||||||
|
mkdir -p /etc/wireguard
|
||||||
echo "
|
echo "
|
||||||
[Interface]
|
[Interface]
|
||||||
Address = $(echo "$wireguard_json" | jq -r '.peer_ip')
|
Address = $(echo "$wireguard_json" | jq -r '.peer_ip')
|
||||||
|
|
|
@ -23,9 +23,9 @@
|
||||||
|
|
||||||
# Set this to the maximum allowed latency in seconds.
|
# Set this to the maximum allowed latency in seconds.
|
||||||
# All servers that repond slower than this will be ignore.
|
# All servers that repond slower than this will be ignore.
|
||||||
# The value is currently set to 50 milliseconds.
|
# The default value is 50 milliseconds.
|
||||||
maximum_allowed_latency=0.05
|
MAX_LATENCY=${MAX_LATENCY:-0.05}
|
||||||
export maximum_allowed_latency
|
export MAX_LATENCY
|
||||||
|
|
||||||
serverlist_url='https://serverlist.piaservers.net/vpninfo/servers/v4'
|
serverlist_url='https://serverlist.piaservers.net/vpninfo/servers/v4'
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ printServerLatency() {
|
||||||
regionName="$(echo ${@:3} |
|
regionName="$(echo ${@:3} |
|
||||||
sed 's/ false//' | sed 's/true/(geo)/')"
|
sed 's/ false//' | sed 's/true/(geo)/')"
|
||||||
time=$(curl -o /dev/null -s \
|
time=$(curl -o /dev/null -s \
|
||||||
--connect-timeout $maximum_allowed_latency \
|
--connect-timeout $MAX_LATENCY \
|
||||||
--write-out "%{time_connect}" \
|
--write-out "%{time_connect}" \
|
||||||
http://$serverIP:443)
|
http://$serverIP:443)
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
|
@ -66,7 +66,7 @@ echo "OK!"
|
||||||
summarized_region_data="$( echo $all_region_data |
|
summarized_region_data="$( echo $all_region_data |
|
||||||
jq -r '.regions[] | .servers.meta[0].ip+" "+.id+" "+.name+" "+(.geo|tostring)' )"
|
jq -r '.regions[] | .servers.meta[0].ip+" "+.id+" "+.name+" "+(.geo|tostring)' )"
|
||||||
echo Testing regions that respond \
|
echo Testing regions that respond \
|
||||||
faster than $maximum_allowed_latency seconds:
|
faster than $MAX_LATENCY seconds:
|
||||||
bestRegion="$(echo "$summarized_region_data" |
|
bestRegion="$(echo "$summarized_region_data" |
|
||||||
xargs -i bash -c 'printServerLatency {}' |
|
xargs -i bash -c 'printServerLatency {}' |
|
||||||
sort | head -1 | awk '{ print $2 }')"
|
sort | head -1 | awk '{ print $2 }')"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user