#!/bin/bash # 快速启动脚本 - 适用于 macOS/Linux # 一键启动所有服务进行调试 set -e # 颜色定义 RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # 打印带颜色的消息 print_info() { echo -e "${BLUE}[INFO]${NC} $1" } print_success() { echo -e "${GREEN}[✓]${NC} $1" } print_warning() { echo -e "${YELLOW}[!]${NC} $1" } print_error() { echo -e "${RED}[✗]${NC} $1" } # 获取脚本所在目录 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" EXTENSION_DIR="$SCRIPT_DIR/extension" NATIVE_HOST_DIR="$SCRIPT_DIR/native-host" # 清屏并显示标题 clear echo "======================================" echo " Qwen CLI Bridge - Quick Start" echo "======================================" echo "" # 1. 检查 Chrome 是否安装 print_info "Checking Chrome installation..." if [[ "$OSTYPE" == "darwin"* ]]; then CHROME_PATH="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" if [[ ! -f "$CHROME_PATH" ]]; then CHROME_PATH="/Applications/Chromium.app/Contents/MacOS/Chromium" fi elif [[ "$OSTYPE" == "linux-gnu"* ]]; then CHROME_PATH=$(which google-chrome || which chromium-browser || which chromium || echo "") fi if [[ -z "$CHROME_PATH" ]] || [[ ! -f "$CHROME_PATH" ]]; then print_error "Chrome not found! Please install Google Chrome first." exit 1 fi print_success "Chrome found: $CHROME_PATH" # 2. 快速安装 Native Host (如果需要) print_info "Setting up Native Host..." if [[ "$OSTYPE" == "darwin"* ]]; then MANIFEST_DIR="$HOME/Library/Application Support/Google/Chrome/NativeMessagingHosts" elif [[ "$OSTYPE" == "linux-gnu"* ]]; then MANIFEST_DIR="$HOME/.config/google-chrome/NativeMessagingHosts" fi mkdir -p "$MANIFEST_DIR" # 创建 manifest cat > "$MANIFEST_DIR/com.qwen.cli.bridge.json" << EOF { "name": "com.qwen.cli.bridge", "description": "Native messaging host for Qwen CLI Bridge", "path": "$NATIVE_HOST_DIR/host.js", "type": "stdio", "allowed_origins": [ "chrome-extension://*/", "chrome-extension://jniepomhbdkeifkadbfolbcihcmfpfjo/" ] } EOF print_success "Native Host configured" # 3. 检查 Qwen CLI print_info "Checking Qwen CLI..." if command -v qwen &> /dev/null; then print_success "Qwen CLI is installed" QWEN_VERSION=$(qwen --version 2>/dev/null || echo "unknown") print_info "Version: $QWEN_VERSION" # 尝试启动 Qwen server print_info "Starting Qwen server on port 8080..." # 检查端口是否被占用 if lsof -i:8080 &> /dev/null; then print_warning "Port 8080 is already in use, skipping Qwen server start" else # 在后台启动 Qwen server nohup qwen server --port 8080 > /tmp/qwen-server.log 2>&1 & QWEN_PID=$! sleep 2 if kill -0 $QWEN_PID 2>/dev/null; then print_success "Qwen server started (PID: $QWEN_PID)" echo $QWEN_PID > /tmp/qwen-server.pid else print_warning "Failed to start Qwen server, continuing anyway..." fi fi else print_warning "Qwen CLI not installed - some features will be limited" fi # 4. 启动简单的测试服务器 print_info "Starting test server..." # 创建简单的 Python HTTP 服务器 cat > /tmp/test-server.py << 'EOF' #!/usr/bin/env python3 import http.server import socketserver PORT = 3000 html_content = """
Extension debugging environment is ready!
This is sample text content that can be extracted by the extension.