#!/usr/bin/env bash # GHOST Direct LAN v0.1 - temporary, local-network-only browser desktop pilot. # Requires a physically logged-in Ubuntu GNOME session; no cloud tunnel, no disk edits. set -Eeuo pipefail umask 077 say(){ printf '[GHOST Direct] %s\n' "$*"; } fail(){ say "STOP: $*" >&2; exit 1; } has(){ command -v "$1" >/dev/null 2>&1; } [[ $(uname -s) == Linux ]] || fail 'Run on the HP under Linux.' [[ -n ${WAYLAND_DISPLAY:-}${DISPLAY:-} && -n ${DBUS_SESSION_BUS_ADDRESS:-} ]] || fail 'Open Terminal from the active Ubuntu graphical desktop, not SSH or a remote terminal.' [[ ${EUID} -ne 0 ]] || fail 'Run as your normal Ubuntu desktop user, not sudo bash.' [[ -z ${SSH_CONNECTION:-}${SSH_TTY:-} ]] || fail 'Open Terminal on the physical HP, not through SSH.' has python3 || fail 'Python 3 is required.' has ip || fail 'The ip networking command is required.' has ss || fail 'The ss networking command is required.' has systemctl || fail 'Systemd is required.' # Resolve a LAN IPv4 interface without sending any traffic. LAN_IP=$(python3 - <<'PY' import ipaddress, subprocess try: s=subprocess.run(['ip','-o','-4','addr','show','scope','global'],capture_output=True,text=True,check=True).stdout except Exception: raise SystemExit(1) ips=[] for line in s.splitlines(): fields=line.split() if 'inet' not in fields: continue addr=ipaddress.ip_interface(fields[fields.index('inet')+1]).ip if addr.is_private and not addr.is_link_local and not addr.is_loopback: ips.append(str(addr)) if not ips: raise SystemExit(1) print(ips[0]) PY ) || fail 'No private IPv4 LAN address found. Connect HP to Wi-Fi/hotspot first.' # Verify the browser gateway port is unoccupied; never replace another service. if ss -H -lnt | awk '$4 ~ /:6080$/ {found=1} END {exit !found}'; then fail 'Port 6080 already has a service. Nothing changed.' fi if ! has grdctl || ! has websockify || [[ ! -f /usr/share/novnc/vnc.html ]]; then say 'Installing official Ubuntu packages for GNOME sharing and the browser viewer.' has sudo || fail 'Ubuntu sudo is required for official package installation.' sudo -v || fail 'Local Ubuntu administrator approval is required.' sudo apt-get update sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends gnome-remote-desktop novnc websockify fi has grdctl || fail 'GNOME desktop sharing is unavailable.' has websockify || fail 'Ubuntu websockify was not installed.' [[ -f /usr/share/novnc/vnc.html ]] || fail 'Ubuntu noVNC files are unavailable.' # Fail closed if this GNOME version lacks the consent/prompt mode. if ! grdctl vnc set-auth-method prompt; then fail 'GNOME does not support required physical approval mode for VNC. No browser gateway started.' fi if ! grdctl vnc disable-view-only; then fail 'GNOME could not enable approved input control.' fi if ! grdctl vnc enable; then fail 'GNOME VNC backend could not be enabled.' fi systemctl --user start gnome-remote-desktop.service || fail 'GNOME screen sharing service could not start.' ready=0 for _ in 1 2 3 4 5; do if ss -H -lnt | awk '$4 ~ /:5900$/ {found=1} END {exit !found}'; then ready=1; break fi sleep 1 done ((ready==1)) || fail 'GNOME VNC is not listening on port 5900. Check GNOME Remote Desktop settings.' say 'Starting the local browser-to-desktop gateway. No external/cloud service is used.' websockify --web /usr/share/novnc "${LAN_IP}:6080" 127.0.0.1:5900 & GATEWAY_PID=$! cleanup(){ if kill -0 "$GATEWAY_PID" 2>/dev/null; then kill "$GATEWAY_PID" 2>/dev/null || true; wait "$GATEWAY_PID" 2>/dev/null || true; fi say 'Browser gateway stopped. GNOME sharing may remain enabled; disable it in Settings → System → Remote Desktop when done.' } trap cleanup EXIT sleep 1 kill -0 "$GATEWAY_PID" 2>/dev/null || fail 'Web gateway failed to start. Check LAN/firewall or port conflicts.' printf '\n' say '============================================================' say 'OPEN THIS ON YOUR SAMSUNG (SAME PRIVATE WI-FI/HOTSPOT):' say "http://${LAN_IP}:6080/vnc.html" say '============================================================' say 'Tap Connect, then approve the screen-sharing request on the HP.' say 'Keep this HP Terminal open for the connection. Ctrl+C stops the gateway.' say 'SECURITY: private trusted LAN ONLY. HTTP/VNC are not suitable for public Internet or untrusted Wi-Fi.' say 'Do NOT open/forward ports 5900 or 6080 on the router.' say 'If GNOME asks to approve each connection, accept only your own Samsung.' printf '\n' wait "$GATEWAY_PID"