Skip to content

Instantly share code, notes, and snippets.

@andersonpem
Last active March 13, 2024 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andersonpem/88f21e97ec6878aaea1ca892875f212b to your computer and use it in GitHub Desktop.
Save andersonpem/88f21e97ec6878aaea1ca892875f212b to your computer and use it in GitHub Desktop.
Fix: nordlayer doesn't connect on Linux, KDE, etc

Sometimes NordLayer 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/88f21e97ec6878aaea1ca892875f212b/raw/482c82ec01feb726de2d00075a3cbc4f93c861f5/runme.sh)

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

#!/bin/env bash
mkdir -p $HOME/.local/bin
cat << EOF > $HOME/.local/bin/nordlayer.sh
#!/bin/env bash
# Attempt to execute the nordlayer command with the URL
if ! OUTPUT=\$(nordlayer click "\$1" 2>&1); then
echo "\$(date): Error executing nordlayer click. Error message: \$OUTPUT" >> $HOME/.local/bin/nordlayer_failures.log
fi
EOF
chmod +x $HOME/.local/bin/nordlayer.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/nordlayer.sh '%u'
Type=Application
Terminal=false
MimeType=x-scheme-handler/nordlayer;"
# Create the .desktop file
DESKTOP_FILE="$HOME/.local/share/applications/nordlayer-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\/nordlayer=/d" "$MIMEAPPS_LIST" # Remove existing associations
echo "x-scheme-handler/nordlayer=nordlayer-url-handler.desktop;" >> "$MIMEAPPS_LIST"
# Update the system's MIME database
update-desktop-database ~/.local/share/applications
echo "Setup complete. Custom URL handler for 'nordlayer://' has been configured."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment