diff --git a/bash/nord/README.md b/bash/nord/README.md new file mode 100644 index 0000000..3ac50e4 --- /dev/null +++ b/bash/nord/README.md @@ -0,0 +1,23 @@ +# NordVPN commands + +The following commands are supplied: + +- login.sh +- logout.sh +- config.sh +- connect.sh +- list_connected +- exit-node.sh +- status.sh + +The following devices run NordVPN: + +- DELL - DellNord +- HP - HPNord +- Pixel +- Tab8 +- sunndal +- raspberry + +The raspberry will be configured as an exit-node allowing the other devices to +route all traffic through this device. diff --git a/bash/nord/config.sh b/bash/nord/config.sh index 273183c..6bf7e15 100755 --- a/bash/nord/config.sh +++ b/bash/nord/config.sh @@ -1,4 +1,10 @@ #! /usr/bin/bash +# set -euo pipefail + +command -v nordvpn >/dev/null 2>&1 || { + echo "nordvpn CLI not found in PATH" >&2 + exit 1 +} # Check for jq if ! command -v jq &> /dev/null diff --git a/bash/nord/exit_node.sh b/bash/nord/exit_node.sh index cd58c5f..64f3126 100755 --- a/bash/nord/exit_node.sh +++ b/bash/nord/exit_node.sh @@ -11,6 +11,7 @@ fi echo "" echo "Example:" echo " $0 mesh-r + # Function to display usage information display_help() { echo "Usage: $0 " diff --git a/bash/nord/nord_watchdog.sh b/bash/nord/nord_watchdog.sh new file mode 100755 index 0000000..217a6d5 --- /dev/null +++ b/bash/nord/nord_watchdog.sh @@ -0,0 +1,41 @@ +#!/usr/bin/bash + +# Configuration - Replace with your Nord account email +USER_EMAIL="terje.innerdal@protonmail.com" + +echo "Checking NordVPN status..." + +# 1. Ensure the NordVPN daemon is running +if ! systemctl is-active --quiet nordvpnd; then + echo "NordVPN daemon is down. Restarting..." + sudo systemctl start nordvpnd + sleep 2 +fi + +# 2. Check if logged in (Exits if not) +if ! nordvpn status | grep -q "Status:"; then + echo "Error: NordVPN is not logged in. Please login manually once." + exit 1 +fi + +# 3. Ensure Meshnet is ENABLED +if ! nordvpn settings | grep -q "Meshnet: enabled"; then + echo "Enabling Meshnet..." + nordvpn set meshnet on +fi + +# 4. Ensure Exit Node permission is ACTIVE +# We check if the email is in the allowed list +if ! nordvpn meshnet peer list | grep -A 5 "This device" | grep -q "Allowing to use as exit node: yes"; then + echo "Setting Exit Node permissions for $USER_EMAIL..." + nordvpn meshnet peer allow-exit-node set "$USER_EMAIL" +fi + +# 5. Ensure IP Forwarding is active in the kernel +IF_FORWARD=$(cat /proc/sys/net/ipv4/ip_forward) +if [[ "$IF_FORWARD" -eq 0 ]]; then + echo "Enabling IP Forwarding..." + sudo sysctl -w net.ipv4.ip_forward=1 +fi + +echo "NordVPN Exit Node is configured and ready." diff --git a/bash/nord/status.sh b/bash/nord/status.sh deleted file mode 100755 index fa2b5c5..0000000 --- a/bash/nord/status.sh +++ /dev/null @@ -1,3 +0,0 @@ -#! /usr/bin/bash - -nordvpn status