Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/mayask/pi-linux-computer. Text-first Linux VM desktop control tools for Pi using SSH, AT-SPI, tmux,
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546#!/usr/bin/env bashset -euo pipefail
config="${PI_LINUX_COMPUTER_CONFIG:-$HOME/.config/pi-linux-computer/targets.json}"project_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
eval "$(python3 - "$config" <<'PY'import json, os, shlex, syswith open(os.path.expanduser(sys.argv[1]), encoding='utf-8') as f: raw=json.load(f)targets=raw.get('targets', raw)name=raw.get('defaultTarget') or next(iter(targets))t=targets[name]for key, value in { 'TARGET_NAME': name, 'HOST': t['host'], 'PORT': str(t.get('port', 22)), 'USER': t['user'], 'KEY': os.path.expanduser(t['identityFile']) if t.get('identityFile') else '', 'KNOWN': os.path.expanduser(t['knownHostsFile']) if t.get('knownHostsFile') else '', 'DISPLAY_VALUE': t['display'], 'XAUTHORITY_VALUE': t['xauthority'], 'DBUS_VALUE': t['dbusAddress'], 'HELPER': t.get('helperPath', ".local/share/pi-linux-computer/linux_computer.py"),}.items(): print(f'{key}={shlex.quote(value)}')PY)"
ssh_args=(-p "$PORT" -o BatchMode=yes -o StrictHostKeyChecking=yes)[[ -n "$KEY" ]] && ssh_args+=(-i "$KEY")[[ -n "$KNOWN" ]] && ssh_args+=(-o "UserKnownHostsFile=$KNOWN")ssh_args+=("$USER@$HOST")remote_dir=${HELPER%/*}ssh "${ssh_args[@]}" "umask 077; mkdir -p '$remote_dir'; cat > '$HELPER'; chmod 700 '$HELPER'" < "$project_dir/remote/linux_computer.py"printf '%s' '{"operation":"ping","params":{}}' | ssh "${ssh_args[@]}" "DISPLAY='$DISPLAY_VALUE' XAUTHORITY='$XAUTHORITY_VALUE' DBUS_SESSION_BUS_ADDRESS='$DBUS_VALUE' python3 '$HELPER'"printf '%s' '{"operation":"snapshot","params":{"maxDepth":8,"maxNodes":300,"includeText":true}}' | ssh "${ssh_args[@]}" "DISPLAY='$DISPLAY_VALUE' XAUTHORITY='$XAUTHORITY_VALUE' DBUS_SESSION_BUS_ADDRESS='$DBUS_VALUE' python3 '$HELPER'" | python3 -c 'import json,sys; d=json.load(sys.stdin); print("snapshot revision={} nodes={} truncated={}".format(d["revision"], len(d["nodes"]), d["truncated"]))'printf '%s' '{"operation":"terminal_capture","params":{"strategy":"clipboard","maxChars":45000}}' | ssh "${ssh_args[@]}" "DISPLAY='$DISPLAY_VALUE' XAUTHORITY='$XAUTHORITY_VALUE' DBUS_SESSION_BUS_ADDRESS='$DBUS_VALUE' python3 '$HELPER'" | python3 -c 'import json,sys; d=json.load(sys.stdin); assert d["ok"] and d["command"]; assert d["clipboardRestored"]; print("terminal capture command={!r} output_chars={} strategy={}".format(d["command"], len(d["output"]), d["strategy"]))'tmux_session="pi-linux-computer-test-$$"cleanup_tmux() { ssh "${ssh_args[@]}" "tmux kill-session -t '$tmux_session'" >/dev/null 2>&1 || true; }trap cleanup_tmux EXITssh "${ssh_args[@]}" "tmux new-session -d -s '$tmux_session'; tmux send-keys -t '$tmux_session:0.0' 'printf \"TMUX_CAPTURE_OK\\n\"' Enter; sleep 1"printf '{"operation":"terminal_capture","params":{"strategy":"tmux","tmuxPane":"%s:0.0"}}' "$tmux_session" | ssh "${ssh_args[@]}" "DISPLAY='$DISPLAY_VALUE' XAUTHORITY='$XAUTHORITY_VALUE' DBUS_SESSION_BUS_ADDRESS='$DBUS_VALUE' python3 '$HELPER'" | python3 -c 'import json,sys; d=json.load(sys.stdin); assert d["strategy"] == "tmux" and d["output"] == "TMUX_CAPTURE_OK"; print("tmux capture command={!r} output={!r}".format(d["command"], d["output"]))'cleanup_tmuxtrap - EXITecho "integration test passed for $TARGET_NAME"