fix: stabilize device debugging and cloud deploy
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 <<EOF
|
||||
set -euo pipefail
|
||||
|
||||
@@ -22,6 +35,15 @@ REMOTE_DIR=$(printf '%q' "$remote_dir")
|
||||
REMOTE_REPO=$(printf '%q' "$remote_repo")
|
||||
BRANCH=$(printf '%q' "$branch")
|
||||
DEPLOY_MODE=$(printf '%q' "$deploy_mode")
|
||||
SUDO_PASS=$(printf '%q' "$server_pass")
|
||||
|
||||
run_sudo() {
|
||||
if [[ -n "\$SUDO_PASS" ]]; then
|
||||
printf '%s\n' "\$SUDO_PASS" | sudo -S "\$@"
|
||||
else
|
||||
sudo "\$@"
|
||||
fi
|
||||
}
|
||||
|
||||
mkdir -p "\$REMOTE_DIR"
|
||||
|
||||
@@ -37,7 +59,7 @@ git reset --hard "origin/\$BRANCH"
|
||||
|
||||
docker_ok=0
|
||||
if [[ "\$DEPLOY_MODE" != "node" ]]; then
|
||||
if sudo docker compose -f compose.cloud.yaml -p boss up -d --build --remove-orphans; then
|
||||
if run_sudo docker compose -f compose.cloud.yaml -p boss up -d --build --remove-orphans; then
|
||||
docker_ok=1
|
||||
elif [[ "\$DEPLOY_MODE" == "docker" ]]; then
|
||||
exit 1
|
||||
@@ -45,6 +67,35 @@ if [[ "\$DEPLOY_MODE" != "node" ]]; then
|
||||
fi
|
||||
|
||||
if [[ "\$docker_ok" -eq 1 ]]; then
|
||||
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,25 +123,27 @@ 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
|
||||
fi
|
||||
run_sudo nginx -t
|
||||
run_sudo systemctl reload nginx
|
||||
echo "__BOSS_DEPLOY_OK__"
|
||||
echo "mode=docker"
|
||||
sudo docker compose -f compose.cloud.yaml -p boss ps
|
||||
run_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
|
||||
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
|
||||
sudo python3 - <<'PY'
|
||||
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()
|
||||
@@ -117,8 +170,37 @@ 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
|
||||
else
|
||||
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
|
||||
fi
|
||||
run_sudo nginx -t
|
||||
run_sudo systemctl reload nginx
|
||||
echo "__BOSS_DEPLOY_OK__"
|
||||
echo "mode=node"
|
||||
BOSS_BASE_PATH=/boss ./scripts/server_status.sh
|
||||
|
||||
Reference in New Issue
Block a user