NetVM: CDP on by default (deterministic port), --headless mode, netvm-cdp.sh helper

This commit is contained in:
Antigravity Agent
2026-10-03 00:53:04 -04:00
parent 65f0c57ba4
commit fa48228ef4
3 changed files with 45 additions and 11 deletions
+11
View File
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
# netvm-cdp.sh <profile> — show how to reach a profile's CDP endpoint.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
. "$SCRIPT_DIR/netvm-names.sh"
netvm_names "${1:?usage: netvm-cdp.sh <profile>}"
TAIL_IP=$(tailscale ip -4 2>/dev/null | head -1)
echo "profile: $NODE"
echo "cdp: http://$PEER_IP:$CDP_PORT/json/list (from this host)"
echo "remote: ssh -L $CDP_PORT:$PEER_IP:$CDP_PORT super@${TAIL_IP:-<tail-ip-of-this-host>}"
echo "launch: netvm-chrome.sh $NODE [--headless] (CDP on by default)"
+33 -11
View File
@@ -1,18 +1,40 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# netvm-chrome.sh <profile> [url] — launch a chrome-box profile inside its # netvm-chrome.sh [--headless] [--cdp-port N|--no-cdp] <profile> [url]
# dedicated NetVM netns. 1:1: profile = node = warp identity = egress IP. # Launch a chrome-box profile inside its dedicated NetVM netns.
# 1:1: profile = node = warp identity = egress IP.
# CDP is on by default (deterministic port) so agents can automate the
# session via Playwright/Puppeteer; --headless runs without a display.
# Run as your normal user (uses sudo -n only for allowlisted netns ops). # Run as your normal user (uses sudo -n only for allowlisted netns ops).
set -euo pipefail set -euo pipefail
PROFILE="${1:?usage: netvm-chrome.sh <profile> [url]}"
URL="${2:-}"
NODE="$PROFILE"
NETVM_BIN="$(cd "$(dirname "$0")" && pwd)" NETVM_BIN="$(cd "$(dirname "$0")" && pwd)"
. "$NETVM_BIN/netvm-names.sh"
HEADLESS=0; CDP_OVERRIDE=""; NO_CDP=0; PROFILE=""; URL=""
usage() { echo "usage: netvm-chrome.sh [--headless] [--cdp-port N|--no-cdp] <profile> [url]"; }
while [ $# -gt 0 ]; do
case "$1" in
--headless) HEADLESS=1; shift;;
--cdp-port) CDP_OVERRIDE="$2"; shift 2;;
--cdp-port=*) CDP_OVERRIDE="${1#*=}"; shift;;
--no-cdp) NO_CDP=1; shift;;
-h|--help) usage; exit 0;;
*) if [ -z "$PROFILE" ]; then PROFILE="$1"; elif [ -z "$URL" ]; then URL="$1";
else echo "unexpected: $1"; usage; exit 1; fi; shift;;
esac
done
[ -n "$PROFILE" ] || { usage; exit 1; }
NODE="$PROFILE"
netvm_names "$NODE"
CHROME_BOX="${CHROME_BOX_BIN:-$HOME/Projects/chrome-box/chrome-box}" CHROME_BOX="${CHROME_BOX_BIN:-$HOME/Projects/chrome-box/chrome-box}"
[ -x "$CHROME_BOX" ] || { echo "chrome-box not found at $CHROME_BOX (set CHROME_BOX_BIN)"; exit 1; } [ -x "$CHROME_BOX" ] || { echo "chrome-box not found at $CHROME_BOX (set CHROME_BOX_BIN)"; exit 1; }
[ -f "/etc/netvm/${NODE}.conf" ] || { echo "no warp identity for '$NODE' — human: netvm-new-identity.sh $NODE"; exit 1; } [ -f "/etc/netvm/${NODE}.conf" ] || { echo "no warp identity for '$NODE' — human: netvm-new-identity.sh $NODE"; exit 1; }
sudo -n "$NETVM_BIN/netvm-node-up.sh" "$NODE" | tail -2
if [ -n "$URL" ]; then if [ "$NO_CDP" = 1 ]; then CDP=""; elif [ -n "$CDP_OVERRIDE" ]; then CDP="$CDP_OVERRIDE"; else CDP="$CDP_PORT"; fi
exec sudo -n "$NETVM_BIN/netvm-enter.sh" "$NODE" "$(id -u)" "$(id -g)" "$HOME" -- "$CHROME_BOX" launch "$PROFILE" "$URL"
else sudo -n "$NETVM_BIN/netvm-node-up.sh" "$NODE" | tail -1
exec sudo -n "$NETVM_BIN/netvm-enter.sh" "$NODE" "$(id -u)" "$(id -g)" "$HOME" -- "$CHROME_BOX" launch "$PROFILE"
fi LAUNCH_ARGS=(launch "$PROFILE")
[ "$HEADLESS" = 1 ] && LAUNCH_ARGS+=(--no-sandbox --headless)
[ -n "$CDP" ] && LAUNCH_ARGS+=(--cdp-port "$CDP")
[ -n "$URL" ] && LAUNCH_ARGS+=("$URL")
[ -n "$CDP" ] && echo "cdp: http://$PEER_IP:$CDP/json/list (local) | ssh -L $CDP:$PEER_IP:$CDP <user>@<tail-ip> (remote)"
exec sudo -n "$NETVM_BIN/netvm-enter.sh" "$NODE" "$(id -u)" "$(id -g)" "$HOME" -- "$CHROME_BOX" "${LAUNCH_ARGS[@]}"
+1
View File
@@ -9,5 +9,6 @@ netvm_names() {
VETH="ve-${_tag}" VETH="ve-${_tag}"
VPEER="vp-${_tag}" VPEER="vp-${_tag}"
_idx=$(( 0x${_tag:0:3} % 200 + 10 )) _idx=$(( 0x${_tag:0:3} % 200 + 10 ))
CDP_PORT=$(( 9222 + 0x${_tag:4:3} % 2000 ))
GW="10.201.${_idx}.1"; PEER_IP="10.201.${_idx}.2"; SUB="10.201.${_idx}.0/30" GW="10.201.${_idx}.1"; PEER_IP="10.201.${_idx}.2"; SUB="10.201.${_idx}.0/30"
} }