Skip to content

Instantly share code, notes, and snippets.

@andersonpem
Last active March 5, 2024 11:27
Show Gist options
  • Save andersonpem/f58349b7f9bb4eca446f84298e92d8de to your computer and use it in GitHub Desktop.
Save andersonpem/f58349b7f9bb4eca446f84298e92d8de to your computer and use it in GitHub Desktop.
Fix: nordvpn doesn't connect on Linux, KDE, etc

Sometimes NordVPN doesn't work out of the box to connect to its services on Linux, especially on distros that use KDE. Or when some terminals like Terminator are the default. For some reason.

I debugged the issue and created a custom handler to get the job done. As well as a log writer.

You must have curl installed.

To run this script, go:

bash <(curl -s https://gist.githubusercontent.com/andersonpem/f58349b7f9bb4eca446f84298e92d8de/raw/41fb5f78b47dd4535a214e486e3be4c0b9cffe1d/runme.sh)

Then try to connect to nordvpn again by going nordpn login, going to the browser and clicking on the link.

#!/bin/env bash
mkdir -p $HOME/.local/bin
cat << EOF > $HOME/.local/bin/nordvpn.sh
#!/bin/env bash
# Attempt to execute the nordvpn command with the URL
if ! OUTPUT=\$(nordvpn click "\$1" 2>&1); then
echo "\$(date): Error executing nordvpn click. Error message: \$OUTPUT" >> $HOME/.local/bin/nordvpn_failures.log
fi
EOF
chmod +x $HOME/.local/bin/nordvpn.sh
# Define the desktop entry with conditional logic for keeping the terminal open
DESKTOP_ENTRY="[Desktop Entry]
Name=NordLayer Login Handler
Exec=bash $HOME/.local/bin/nordvpn.sh '%u'
Type=Application
Terminal=false
MimeType=x-scheme-handler/nordvpn;"
# Create the .desktop file
DESKTOP_FILE="$HOME/.local/share/applications/nordvpn-url-handler.desktop"
echo "$DESKTOP_ENTRY" > "$DESKTOP_FILE"
# Update MIME associations
MIMEAPPS_LIST="$HOME/.local/share/applications/mimeapps.list"
if [ ! -f "$MIMEAPPS_LIST" ]; then
echo "[Added Associations]" > "$MIMEAPPS_LIST"
echo "[Default Applications]" >> "$MIMEAPPS_LIST"
fi
sed -i "/x-scheme-handler\/nordvpn=/d" "$MIMEAPPS_LIST" # Remove existing associations
echo "x-scheme-handler/nordvpn=nordvpn-url-handler.desktop;" >> "$MIMEAPPS_LIST"
# Update the system's MIME database
update-desktop-database ~/.local/share/applications
echo "Setup complete. Custom URL handler for 'nordvpn://' has been configured."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment