From 3aa73f4ad7de10cef1a17dd587df143769dc3f62 Mon Sep 17 00:00:00 2001 From: lluked <17367626+lluked@users.noreply.github.com> Date: Sun, 17 Dec 2023 13:06:32 +0000 Subject: [PATCH] Updates (#2) * Update NordVPN version * Update error handling --- .gitignore | 3 ++- build/Dockerfile | 12 ++++++++---- build/get_wireguard_config.sh | 16 ++++++++++------ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 4c49bd7..a7dfb30 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.env +.DS_Store +.env \ No newline at end of file diff --git a/build/Dockerfile b/build/Dockerfile index 18e03c3..7756725 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,15 +1,19 @@ FROM ubuntu:22.04 -ARG NORDVPN_VERSION=${NORDVPN_VERSION:-3.16.5} +ARG NORDVPN_VERSION=${NORDVPN_VERSION:-3.16.9} ARG DEBIAN_FRONTEND=noninteractive RUN apt-get update && \ - apt-get install -y curl iputils-ping wireguard-tools jq && \ + apt-get install -y \ + curl \ + jq \ + iputils-ping \ + wireguard-tools && \ curl https://repo.nordvpn.com/deb/nordvpn/debian/pool/main/nordvpn-release_1.0.0_all.deb -o "/tmp/nordrepo.deb" && \ apt-get install -y /tmp/nordrepo.deb && \ apt-get update && \ - apt-get install -y nordvpn${NORDVPN_VERSION:+=$NORDVPN_VERSION} && \ - apt-get remove -y wget nordvpn-release && \ + apt-get install -y nordvpn=${NORDVPN_VERSION} && \ + apt-get remove -y nordvpn-release && \ rm /tmp/nordrepo.deb && \ apt-get clean diff --git a/build/get_wireguard_config.sh b/build/get_wireguard_config.sh index 89a8462..73adfa7 100755 --- a/build/get_wireguard_config.sh +++ b/build/get_wireguard_config.sh @@ -1,5 +1,8 @@ #!/bin/bash +# Clear the output folder +rm -f -r /output/* + # Get the chosen server api_response=$(curl -s ${API_QUERY:-"https://api.nordvpn.com/v1/servers/recommendations?&filters\[servers_technologies\]\[identifier\]=wireguard_udp&limit=1"}) server_identifier=$(jq -r '.[]|.hostname' <<< "$api_response" | cut -d "." -f 1) @@ -20,9 +23,9 @@ echo "############################################################" echo "" # Get client details -nordvpn login --token "${TOKEN}" -nordvpn set technology NordLynx 2>&1 >/dev/null -nordvpn connect "$server_identifier" 2>&1 >/dev/null +nordvpn login --token "${TOKEN}" || { echo 'exiting...' ; exit 1; } +nordvpn set technology NordLynx|| { nordvpn logout --persist-token; echo 'exiting...'; exit 1; } +nordvpn connect "$server_identifier" || { nordvpn logout --persist-token; echo 'exiting...'; exit 1; } client_private_key=$(wg show nordlynx private-key) client_ip_address=$(ip -o addr show dev nordlynx | awk '$3 == "inet" {print $4}') @@ -52,9 +55,10 @@ echo "##################### WireGuard Config #####################" echo "$config" echo "############################################################" -# Write config -rm -f -r /output/* +# Write config to the putput folder echo "$config" > "/output/nordvpn-$server_identifier.conf" -# Disconnect +# Close out nordvpn disconnect +nordvpn logout --persist-token +exit 0