mirror of
https://github.com/pia-foss/manual-connections.git
synced 2025-02-05 14:08:29 +00:00
refactoring for the last commit
This commit is contained in:
parent
aac22fe847
commit
1ab988a12f
|
@ -19,40 +19,32 @@
|
||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
|
# This function allows you to check if the required tools have been installed.
|
||||||
|
function check_tool() {
|
||||||
|
cmd=$1
|
||||||
|
package=$2
|
||||||
|
if ! command -v $cmd &>/dev/null
|
||||||
|
then
|
||||||
|
echo "$cmd could not be found"
|
||||||
|
echo "Please install $package"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
# Now we call the function to make sure we can use wg-quick, curl and jq.
|
||||||
|
check_tool wg-quick wireguard-tools
|
||||||
|
check_tool curl curl
|
||||||
|
check_tool jq jq
|
||||||
|
|
||||||
# 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.
|
||||||
if [ $(sysctl -n net.ipv6.conf.all.disable_ipv6) -ne 1 ] || [ $(sysctl -n net.ipv6.conf.default.disable_ipv6) -ne 1 ]
|
if [ $(sysctl -n net.ipv6.conf.all.disable_ipv6) -ne 1 ] ||
|
||||||
|
[ $(sysctl -n net.ipv6.conf.default.disable_ipv6) -ne 1 ]
|
||||||
then
|
then
|
||||||
echo 'You should consider disabling IPv6 by running:'
|
echo 'You should consider disabling IPv6 by running:'
|
||||||
echo 'sysctl -w net.ipv6.conf.all.disable_ipv6=1'
|
echo 'sysctl -w net.ipv6.conf.all.disable_ipv6=1'
|
||||||
echo 'sysctl -w net.ipv6.conf.default.disable_ipv6=1'
|
echo 'sysctl -w net.ipv6.conf.default.disable_ipv6=1'
|
||||||
fi
|
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_tool wg-quick wireguard-tools
|
|
||||||
|
|
||||||
# check if curl has been installed
|
|
||||||
check_tool curl curl
|
|
||||||
|
|
||||||
# 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
|
||||||
echo This script requires 3 env vars:
|
echo This script requires 3 env vars:
|
||||||
|
@ -68,13 +60,7 @@ 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.
|
||||||
|
|
|
@ -19,10 +19,24 @@
|
||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
|
# This function allows you to check if the required tools have been installed.
|
||||||
|
function check_tool() {
|
||||||
|
cmd=$1
|
||||||
|
package=$2
|
||||||
|
if ! command -v $cmd &>/dev/null
|
||||||
|
then
|
||||||
|
echo "$cmd could not be found"
|
||||||
|
echo "Please install $package"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
# Now we call the function to make sure we can use wg-quick, curl and jq.
|
||||||
|
check_tool curl curl
|
||||||
|
check_tool jq jq
|
||||||
|
|
||||||
|
# This allows you to set the maximum allowed latency in seconds.
|
||||||
# Set this to the maximum allowed latency in seconds.
|
# All servers that repond slower than this will be ignored.
|
||||||
# All servers that repond slower than this will be ignore.
|
# You can inject this with the environment variable MAX_LATENCY.
|
||||||
# The default value is 50 milliseconds.
|
# The default value is 50 milliseconds.
|
||||||
MAX_LATENCY=${MAX_LATENCY:-0.05}
|
MAX_LATENCY=${MAX_LATENCY:-0.05}
|
||||||
export MAX_LATENCY
|
export MAX_LATENCY
|
||||||
|
|
Loading…
Reference in New Issue
Block a user