infra/remote-chromium.sh
Tommy Rantti 9593b233aa Take remote-chromium.sh's host as an argument instead of an env var
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 13:40:17 +03:00

48 lines
1.5 KiB
Bash
Executable file

#!/usr/bin/env bash
# Run on the travel laptop: closes any Chromium running for you on the remote
# machine (Chromium allows one process per profile, so a running instance
# would swallow the new window), then launches it there with its window
# drawn here.
#
# Usage: remote-chromium.sh [--x11] [host]
# --x11 classic X11 forwarding instead of waypipe
# host ssh host to run Chromium on (default: teemu-thinkpad-ubuntu)
set -euo pipefail
MODE="waypipe"
HOST="teemu-thinkpad-ubuntu"
for arg in "$@"; do
case "$arg" in
--x11) MODE="x11" ;;
-*) echo "Unknown option: $arg"; exit 1 ;;
*) HOST="$arg" ;;
esac
done
if [ "$MODE" = "waypipe" ] && ! command -v waypipe >/dev/null 2>&1; then
echo "waypipe not installed here - run: sudo apt install waypipe (needed on both machines)"
exit 1
fi
ssh "$HOST" bash -s <<'EOF'
# snap build (Ubuntu) and the Debian package - matches the browser binary only,
# not shells/editors that merely mention "chromium"
PAT='chromium-browser/chrome|/usr/lib/chromium/chromium'
if pgrep -u "$USER" -f "$PAT" >/dev/null; then
echo "Chromium is running on $(hostname) - closing it gracefully..."
pkill -TERM -u "$USER" -f "$PAT"
for _ in $(seq 1 10); do
pgrep -u "$USER" -f "$PAT" >/dev/null || break
sleep 1
done
if pgrep -u "$USER" -f "$PAT" >/dev/null; then
echo "Still running after 10s - force killing."
pkill -KILL -u "$USER" -f "$PAT"
fi
fi
EOF
case "$MODE" in
waypipe) exec waypipe ssh "$HOST" chromium --ozone-platform=wayland ;;
x11) exec ssh -X "$HOST" chromium ;;
esac