68 lines
2.5 KiB
Bash
Executable File
68 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# ~/bin/synergy-client-connect - Dynamic Synergy Client Launcher
|
|
# Automatically probes and connects to t520 whether on Ethernet, WiFi, or VPN.
|
|
|
|
set -euo pipefail
|
|
|
|
CLIENT_NAME="${1:-$(hostname -s 2>/dev/null || uname -n)}"
|
|
CANDIDATE_SERVERS=(
|
|
"192.168.1.100:24800" # t520 Ethernet
|
|
"192.168.1.102:24800" # t520 WiFi
|
|
"10.0.0.18:24800" # t520 Legacy LAN
|
|
"10.39.9.100:24800" # t520 WireGuard VPN
|
|
)
|
|
|
|
find_active_server() {
|
|
for target in "${CANDIDATE_SERVERS[@]}"; do
|
|
local host="${target%%:*}"
|
|
local port="${target##*:}"
|
|
if (echo > /dev/tcp/"$host"/"$port") >/dev/null 2>&1; then
|
|
echo "$target"
|
|
return 0
|
|
fi
|
|
done
|
|
return 1
|
|
}
|
|
|
|
# Ensure DISPLAY is set for graphical/XWayland environments (e.g. Crostini or systemd user services)
|
|
export DISPLAY="${DISPLAY:-:0}"
|
|
|
|
# Locate synergyc / barrierc / deskflow-client binary across standard paths
|
|
SYNERGYC="$(command -v synergyc 2>/dev/null || command -v barrierc 2>/dev/null || command -v deskflow-client 2>/dev/null || true)"
|
|
if [ -z "$SYNERGYC" ]; then
|
|
for candidate in \
|
|
"/usr/local/bin/synergyc" "/usr/bin/synergyc" "$HOME/.local/bin/synergyc" \
|
|
"/usr/local/bin/barrierc" "/usr/bin/barrierc" \
|
|
"/usr/local/bin/deskflow-client" "/usr/bin/deskflow-client"; do
|
|
if [ -x "$candidate" ]; then
|
|
SYNERGYC="$candidate"
|
|
break
|
|
fi
|
|
done
|
|
fi
|
|
|
|
if [ -z "$SYNERGYC" ]; then
|
|
echo "[synergy-connect] Error: Neither synergyc, barrierc, nor deskflow-client found in PATH or standard locations." >&2
|
|
echo "[synergy-connect] Please install barrier or deskflow: 'sudo apt install barrier' or 'sudo apt install deskflow'" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Determine crypto flag based on synergyc build (note: synergyc --help exits with code 3)
|
|
CRYPTO_FLAG=""
|
|
if ("$SYNERGYC" --help 2>&1 || true) | grep -q -- '--disable-crypto'; then
|
|
CRYPTO_FLAG="--disable-crypto"
|
|
fi
|
|
|
|
echo "[synergy-connect] Starting dynamic Synergy client for '$CLIENT_NAME' using $SYNERGYC..."
|
|
|
|
while true; do
|
|
if ACTIVE_SERVER=$(find_active_server); then
|
|
echo "[synergy-connect] Found active server at $ACTIVE_SERVER. Connecting..."
|
|
"$SYNERGYC" -f $CRYPTO_FLAG --name "$CLIENT_NAME" "$ACTIVE_SERVER" || true
|
|
echo "[synergy-connect] Synergy client exited or disconnected. Probing again in 2s..."
|
|
else
|
|
echo "[synergy-connect] No reachable t520 server on Ethernet/WiFi/VPN. Retrying in 3s..."
|
|
fi
|
|
sleep 2
|
|
done
|