2026-10-04 22:54:01 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
# muse-cli-node <node> <muse-cli-args...>
|
|
|
|
|
# Runs muse-cli inside the node's isolated network namespace with its own
|
|
|
|
|
# dedicated Cloudflare WARP egress identity and isolated cookies/config.
|
|
|
|
|
# Auto-refreshes cookies via Chromium CDP if authentication fails.
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
|
|
NETVM_BIN="$(cd "$(dirname "$0")" && pwd)"
|
|
|
|
|
NODE="${1:?usage: muse-cli-node <node> [args...]}"
|
|
|
|
|
shift
|
|
|
|
|
|
|
|
|
|
CONF_DIR="$HOME/.config/muse-cli/$NODE"
|
|
|
|
|
mkdir -p "$CONF_DIR"
|
|
|
|
|
|
2026-10-05 16:06:25 +00:00
|
|
|
ensure_node_up() {
|
|
|
|
|
if ! ip netns list 2>/dev/null | grep -q "^warp-${NODE}\b"; then
|
|
|
|
|
echo "Notice: warp-${NODE} network namespace is down; bringing up via netvm-node-up.sh..." >&2
|
|
|
|
|
sudo -n "$NETVM_BIN/netvm-node-up.sh" "$NODE" >/dev/null 2>&1 || true
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ensure_node_up
|
|
|
|
|
|
2026-10-04 22:54:01 +00:00
|
|
|
run_cli() {
|
|
|
|
|
export MUSE_CONFIG_DIR="$CONF_DIR"
|
2026-10-05 16:02:46 +00:00
|
|
|
"$NETVM_BIN/netvm-exec.sh" "$NODE" -- python3 "$NETVM_BIN/muse-cli-inner.py" "$NODE" "$@"
|
2026-10-04 22:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# First attempt
|
|
|
|
|
set +e
|
|
|
|
|
OUTPUT=$(run_cli "$@" 2>&1)
|
|
|
|
|
RC=$?
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
# Detect authentication failure and trigger single auto-refresh retry
|
|
|
|
|
if [ $RC -ne 0 ] && echo "$OUTPUT" | grep -qiE "AuthError|hatch_sess|401|unauthorized"; then
|
|
|
|
|
echo "Notice: Auth failure detected for $NODE; refreshing cookies from Chromium CDP..." >&2
|
|
|
|
|
if "$NETVM_BIN/netvm-exec.sh" "$NODE" -- python3 "$NETVM_BIN/refresh-node-cookies.py" "$NODE"; then
|
|
|
|
|
echo "Notice: Cookies refreshed for $NODE. Retrying operation..." >&2
|
|
|
|
|
run_cli "$@"
|
|
|
|
|
exit $?
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# If succeeded or failed on something else, emit output and exit with RC
|
|
|
|
|
echo "$OUTPUT"
|
|
|
|
|
exit $RC
|