From 7915445fcf07b507ae8ef4324a9a4f76ed68b2d0 Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 25 Mar 2026 03:49:50 +0800 Subject: [PATCH] fix: stabilize device debugging and cloud deploy --- scripts/android_honor_debug.sh | 26 +++- scripts/boss_cloud_logs.sh | 15 ++- scripts/boss_cloud_status.sh | 15 ++- scripts/deploy_ai_glasses_server.sh | 176 ++++++++++++++++++++-------- 4 files changed, 182 insertions(+), 50 deletions(-) diff --git a/scripts/android_honor_debug.sh b/scripts/android_honor_debug.sh index 9713046..0b4aeb2 100755 --- a/scripts/android_honor_debug.sh +++ b/scripts/android_honor_debug.sh @@ -3,6 +3,7 @@ set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" DEFAULT_SERIAL="adb-A9TU024628000647-B0UNif._adb-tls-connect._tcp" +TARGET_MODEL="FLC_AN00" DEFAULT_SDK_DIR="/opt/homebrew/share/android-commandlinetools" PACKAGE_NAME="site.hyzq.bossandroid" ACTIVITY_NAME=".MainActivity" @@ -30,7 +31,30 @@ Environment: EOF } +lookup_honor_serial() { + adb devices -l | sed -nE "/model:${TARGET_MODEL}/ s/^(.*)[[:space:]]device .*/\\1/p" | head -n 1 +} + +resolve_target_serial() { + local requested state detected + requested="${BOSS_ANDROID_SERIAL:-$DEFAULT_SERIAL}" + state="$(adb -s "$requested" get-state 2>/dev/null || true)" + if [[ "$state" == "device" ]]; then + printf '%s' "$requested" + return 0 + fi + + detected="$(lookup_honor_serial)" + if [[ -n "$detected" ]]; then + printf '%s' "$detected" + return 0 + fi + + printf '%s' "$requested" +} + ensure_connected() { + TARGET_SERIAL="$(resolve_target_serial)" local state state="$(adb -s "$TARGET_SERIAL" get-state 2>/dev/null || true)" if [[ "$state" != "device" ]]; then @@ -64,7 +88,7 @@ command="${1:-}" case "$command" in serial) - echo "$TARGET_SERIAL" + echo "$(resolve_target_serial)" ;; status) ensure_connected diff --git a/scripts/boss_cloud_logs.sh b/scripts/boss_cloud_logs.sh index 29f1f76..9b26c7c 100755 --- a/scripts/boss_cloud_logs.sh +++ b/scripts/boss_cloud_logs.sh @@ -7,5 +7,18 @@ tail_lines="${1:-150}" export CODEX_HOME="${CODEX_HOME:-$HOME/.codex}" export AG_SERVER_SKILL="${AG_SERVER_SKILL:-$CODEX_HOME/skills/ai-glasses-server-debug}" export AG_SERVER="${AG_SERVER:-$AG_SERVER_SKILL/scripts/server_ssh.sh}" +KEYCHAIN_SERVICE="${AI_GLASSES_KEYCHAIN_SERVICE:-ai-glasses-debug-ssh}" -"$AG_SERVER" exec "set -euo pipefail; cd $(printf '%q' "$remote_dir"); if sudo docker ps --format '{{.Names}}' | grep -qx 'boss-control-plane'; then sudo docker compose -f compose.cloud.yaml -p boss logs --tail $(printf '%q' "$tail_lines"); else tail -n $(printf '%q' "$tail_lines") .boss-data/server.log; fi" +resolve_server_password() { + if [[ -n "${AI_GLASSES_SERVER_PASS:-}" ]]; then + printf '%s' "${AI_GLASSES_SERVER_PASS}" + return 0 + fi + if command -v security >/dev/null 2>&1; then + security find-generic-password -a "${AI_GLASSES_SERVER_USER:-ubuntu}" -s "${KEYCHAIN_SERVICE}" -w 2>/dev/null || true + fi +} + +server_pass="$(resolve_server_password)" + +"$AG_SERVER" exec "set -euo pipefail; SUDO_PASS=$(printf '%q' "$server_pass"); run_sudo(){ if [[ -n \"\$SUDO_PASS\" ]]; then printf '%s\n' \"\$SUDO_PASS\" | sudo -S \"\$@\"; else sudo \"\$@\"; fi; }; cd $(printf '%q' "$remote_dir"); if run_sudo docker ps --format '{{.Names}}' | grep -qx 'boss-control-plane'; then run_sudo docker compose -f compose.cloud.yaml -p boss logs --tail $(printf '%q' "$tail_lines"); else tail -n $(printf '%q' "$tail_lines") .boss-data/server.log; fi" diff --git a/scripts/boss_cloud_status.sh b/scripts/boss_cloud_status.sh index c3fd753..d5555d3 100755 --- a/scripts/boss_cloud_status.sh +++ b/scripts/boss_cloud_status.sh @@ -6,5 +6,18 @@ remote_dir="${BOSS_REMOTE_DIR:-/home/ubuntu/boss}" export CODEX_HOME="${CODEX_HOME:-$HOME/.codex}" export AG_SERVER_SKILL="${AG_SERVER_SKILL:-$CODEX_HOME/skills/ai-glasses-server-debug}" export AG_SERVER="${AG_SERVER:-$AG_SERVER_SKILL/scripts/server_ssh.sh}" +KEYCHAIN_SERVICE="${AI_GLASSES_KEYCHAIN_SERVICE:-ai-glasses-debug-ssh}" -"$AG_SERVER" exec "set -euo pipefail; cd $(printf '%q' "$remote_dir"); if sudo docker ps --format '{{.Names}}' | grep -qx 'boss-control-plane'; then sudo docker compose -f compose.cloud.yaml -p boss ps; echo '---'; curl -fsS http://127.0.0.1:43210/boss/api/health; else BOSS_BASE_PATH=/boss ./scripts/server_status.sh; fi" +resolve_server_password() { + if [[ -n "${AI_GLASSES_SERVER_PASS:-}" ]]; then + printf '%s' "${AI_GLASSES_SERVER_PASS}" + return 0 + fi + if command -v security >/dev/null 2>&1; then + security find-generic-password -a "${AI_GLASSES_SERVER_USER:-ubuntu}" -s "${KEYCHAIN_SERVICE}" -w 2>/dev/null || true + fi +} + +server_pass="$(resolve_server_password)" + +"$AG_SERVER" exec "set -euo pipefail; SUDO_PASS=$(printf '%q' "$server_pass"); run_sudo(){ if [[ -n \"\$SUDO_PASS\" ]]; then printf '%s\n' \"\$SUDO_PASS\" | sudo -S \"\$@\"; else sudo \"\$@\"; fi; }; cd $(printf '%q' "$remote_dir"); if run_sudo docker ps --format '{{.Names}}' | grep -qx 'boss-control-plane'; then run_sudo docker compose -f compose.cloud.yaml -p boss ps; echo '---'; curl -fsS http://127.0.0.1:43210/boss/api/health; else BOSS_BASE_PATH=/boss ./scripts/server_status.sh; fi" diff --git a/scripts/deploy_ai_glasses_server.sh b/scripts/deploy_ai_glasses_server.sh index f651dfd..9851210 100755 --- a/scripts/deploy_ai_glasses_server.sh +++ b/scripts/deploy_ai_glasses_server.sh @@ -9,12 +9,25 @@ deploy_mode="${BOSS_CLOUD_DEPLOY_MODE:-auto}" export CODEX_HOME="${CODEX_HOME:-$HOME/.codex}" export AG_SERVER_SKILL="${AG_SERVER_SKILL:-$CODEX_HOME/skills/ai-glasses-server-debug}" export AG_SERVER="${AG_SERVER:-$AG_SERVER_SKILL/scripts/server_ssh.sh}" +KEYCHAIN_SERVICE="${AI_GLASSES_KEYCHAIN_SERVICE:-ai-glasses-debug-ssh}" + +resolve_server_password() { + if [[ -n "${AI_GLASSES_SERVER_PASS:-}" ]]; then + printf '%s' "${AI_GLASSES_SERVER_PASS}" + return 0 + fi + if command -v security >/dev/null 2>&1; then + security find-generic-password -a "${AI_GLASSES_SERVER_USER:-ubuntu}" -s "${KEYCHAIN_SERVICE}" -w 2>/dev/null || true + fi +} if [[ ! -x "$AG_SERVER" ]]; then echo "AI Glasses server wrapper not found: $AG_SERVER" >&2 exit 1 fi +server_pass="$(resolve_server_password)" + remote_script=$(cat </dev/null 2>&1 || ! command -v npm >/dev/null 2>&1; then + run_sudo apt-get update + run_sudo apt-get install -y nodejs npm +fi + +npm install +npm run build +PORT=43210 BOSS_DATA_FILE=.boss-data/cloud-store.json BOSS_BASE_PATH=/boss ./scripts/server_start.sh +if [[ -n "\$SUDO_PASS" ]]; then + printf '%s\n' "\$SUDO_PASS" | sudo -S python3 - <<'PY' +from pathlib import Path +path = Path("/etc/nginx/sites-enabled/hybrid_updates.conf") +text = path.read_text() +if "location /boss/" not in text: + block = """ + location = /boss { + return 302 /boss/; + } + + location /boss/ { + proxy_pass http://127.0.0.1:43210; + proxy_http_version 1.1; + proxy_set_header Host \$host; + proxy_set_header X-Real-IP \$remote_addr; + proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto \$scheme; + proxy_read_timeout 3600s; + proxy_send_timeout 3600s; + proxy_buffering off; + } + +""" + marker = " location / {\n" + text = text.replace(marker, block + marker, 1) + path.write_text(text) +PY +else sudo python3 - <<'PY' from pathlib import Path path = Path("/etc/nginx/sites-enabled/hybrid_updates.conf") @@ -72,53 +198,9 @@ if "location /boss/" not in text: text = text.replace(marker, block + marker, 1) path.write_text(text) PY - sudo nginx -t - sudo systemctl reload nginx - echo "__BOSS_DEPLOY_OK__" - echo "mode=docker" - sudo docker compose -f compose.cloud.yaml -p boss ps - sleep 3 - curl -fsS http://127.0.0.1:43210/boss/api/health - exit 0 fi - -if ! command -v node >/dev/null 2>&1 || ! command -v npm >/dev/null 2>&1; then - sudo apt-get update - sudo apt-get install -y nodejs npm -fi - -npm install -npm run build -PORT=43210 BOSS_DATA_FILE=.boss-data/cloud-store.json BOSS_BASE_PATH=/boss ./scripts/server_start.sh -sudo python3 - <<'PY' -from pathlib import Path -path = Path("/etc/nginx/sites-enabled/hybrid_updates.conf") -text = path.read_text() -if "location /boss/" not in text: - block = """ - location = /boss { - return 302 /boss/; - } - - location /boss/ { - proxy_pass http://127.0.0.1:43210; - proxy_http_version 1.1; - proxy_set_header Host \$host; - proxy_set_header X-Real-IP \$remote_addr; - proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto \$scheme; - proxy_read_timeout 3600s; - proxy_send_timeout 3600s; - proxy_buffering off; - } - -""" - marker = " location / {\n" - text = text.replace(marker, block + marker, 1) - path.write_text(text) -PY -sudo nginx -t -sudo systemctl reload nginx +run_sudo nginx -t +run_sudo systemctl reload nginx echo "__BOSS_DEPLOY_OK__" echo "mode=node" BOSS_BASE_PATH=/boss ./scripts/server_status.sh