|
|
@@ -1,47 +1,84 @@
|
|
|
#!/bin/bash
|
|
|
-
|
|
|
set -e
|
|
|
|
|
|
+BINARY_NAME="opencode-monitor"
|
|
|
+VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
|
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
|
|
|
|
-# 构建前端(可选,需配置 WEB_DIR 环境变量指向前端项目目录)
|
|
|
-WEB_DIR="${WEB_DIR:-}"
|
|
|
-HTML_DIR="$PROJECT_DIR/internal/web/html"
|
|
|
+cd "$PROJECT_DIR"
|
|
|
|
|
|
-if [ -n "$WEB_DIR" ] && [ -d "$WEB_DIR" ]; then
|
|
|
- echo "Building frontend..."
|
|
|
- cd "$WEB_DIR" && npm run build
|
|
|
- rm -rf "$HTML_DIR"
|
|
|
- cp -r dist "$HTML_DIR"
|
|
|
- echo "Frontend built and copied."
|
|
|
-fi
|
|
|
+detect_platform() {
|
|
|
+ local os arch suffix
|
|
|
+ os=$(uname -s | tr '[:upper:]' '[:lower:]')
|
|
|
+ arch=$(uname -m)
|
|
|
+ case "$os" in
|
|
|
+ linux*) os="linux" ;;
|
|
|
+ darwin*) os="darwin" ;;
|
|
|
+ *) os="windows" ;;
|
|
|
+ esac
|
|
|
+ case "$arch" in
|
|
|
+ x86_64|amd64) arch="amd64" ;;
|
|
|
+ aarch64|arm64) arch="arm64" ;;
|
|
|
+ *) arch="amd64" ;;
|
|
|
+ esac
|
|
|
+ if [ "$os" = "windows" ]; then
|
|
|
+ suffix=".exe"
|
|
|
+ else
|
|
|
+ suffix=""
|
|
|
+ fi
|
|
|
+ echo "${os}-${arch}${suffix}"
|
|
|
+}
|
|
|
|
|
|
-cd "$PROJECT_DIR"
|
|
|
+if [ "$1" = "--only-ble" ]; then
|
|
|
+ echo "=== Building BLE relay only ==="
|
|
|
+ python3 -m pip install pyinstaller bleak || python -m pip install pyinstaller bleak
|
|
|
+ mkdir -p bin
|
|
|
+ python3 -m PyInstaller --onefile --name ble_relay --distpath bin --specpath build --workpath build scripts/ble_relay.py || python -m PyInstaller --onefile --name ble_relay --distpath bin --specpath build --workpath build scripts/ble_relay.py
|
|
|
+ cp bin/ble_relay cmd/monitor/ble_relay
|
|
|
+ echo ""
|
|
|
+ echo "Done: bin/ble_relay + cmd/monitor/ble_relay"
|
|
|
|
|
|
-BINARY_NAME="opencode-monitor"
|
|
|
-VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
|
|
+elif [ "$1" = "--ble" ]; then
|
|
|
+ PLATFORM=$(detect_platform)
|
|
|
+ echo "=== Building for ${PLATFORM} with BLE ==="
|
|
|
+ echo "Step 1: Building BLE relay..."
|
|
|
+ python3 -m pip install pyinstaller bleak || python -m pip install pyinstaller bleak
|
|
|
+ mkdir -p bin
|
|
|
+ python3 -m PyInstaller --onefile --name ble_relay --distpath bin --specpath build --workpath build scripts/ble_relay.py || python -m PyInstaller --onefile --name ble_relay --distpath bin --specpath build --workpath build scripts/ble_relay.py
|
|
|
+ cp bin/ble_relay cmd/monitor/ble_relay
|
|
|
+ echo "Step 2: Building Go binary with BLE embedded..."
|
|
|
+ go mod tidy
|
|
|
+ mkdir -p dist
|
|
|
+ go build -tags ble -ldflags "-X main.Version=${VERSION}" -o "dist/${BINARY_NAME}-${PLATFORM}" ./cmd/monitor
|
|
|
+ rm -f cmd/monitor/ble_relay
|
|
|
+ echo ""
|
|
|
+ echo "Done: dist/${BINARY_NAME}-${PLATFORM}"
|
|
|
|
|
|
-mkdir -p dist
|
|
|
+else
|
|
|
+ echo "=== Building all platforms (no BLE) ==="
|
|
|
+ mkdir -p dist
|
|
|
+ go mod tidy
|
|
|
|
|
|
-echo "Building for Linux (amd64)..."
|
|
|
-GOOS=linux GOARCH=amd64 go build -ldflags "-X main.Version=${VERSION}" -o dist/${BINARY_NAME}-linux-amd64 ./cmd/monitor
|
|
|
+ echo "Building for Linux (amd64)..."
|
|
|
+ GOOS=linux GOARCH=amd64 go build -ldflags "-X main.Version=${VERSION}" -o dist/${BINARY_NAME}-linux-amd64 ./cmd/monitor
|
|
|
|
|
|
-echo "Building for Linux (arm64)..."
|
|
|
-GOOS=linux GOARCH=arm64 go build -ldflags "-X main.Version=${VERSION}" -o dist/${BINARY_NAME}-linux-arm64 ./cmd/monitor
|
|
|
+ echo "Building for Linux (arm64)..."
|
|
|
+ GOOS=linux GOARCH=arm64 go build -ldflags "-X main.Version=${VERSION}" -o dist/${BINARY_NAME}-linux-arm64 ./cmd/monitor
|
|
|
|
|
|
-echo "Building for macOS (amd64)..."
|
|
|
-GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.Version=${VERSION}" -o dist/${BINARY_NAME}-darwin-amd64 ./cmd/monitor
|
|
|
+ echo "Building for macOS (amd64)..."
|
|
|
+ GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.Version=${VERSION}" -o dist/${BINARY_NAME}-darwin-amd64 ./cmd/monitor
|
|
|
|
|
|
-echo "Building for macOS (arm64)..."
|
|
|
-GOOS=darwin GOARCH=arm64 go build -ldflags "-X main.Version=${VERSION}" -o dist/${BINARY_NAME}-darwin-arm64 ./cmd/monitor
|
|
|
+ echo "Building for macOS (arm64)..."
|
|
|
+ GOOS=darwin GOARCH=arm64 go build -ldflags "-X main.Version=${VERSION}" -o dist/${BINARY_NAME}-darwin-arm64 ./cmd/monitor
|
|
|
|
|
|
-echo "Building for Windows (amd64)..."
|
|
|
-GOOS=windows GOARCH=amd64 go build -ldflags "-X main.Version=${VERSION}" -o dist/${BINARY_NAME}-windows-amd64.exe ./cmd/monitor
|
|
|
+ echo "Building for Windows (amd64)..."
|
|
|
+ GOOS=windows GOARCH=amd64 go build -ldflags "-X main.Version=${VERSION}" -o dist/${BINARY_NAME}-windows-amd64.exe ./cmd/monitor
|
|
|
|
|
|
-echo "Building for Windows (arm64)..."
|
|
|
-GOOS=windows GOARCH=arm64 go build -ldflags "-X main.Version=${VERSION}" -o dist/${BINARY_NAME}-windows-arm64.exe ./cmd/monitor
|
|
|
+ echo "Building for Windows (arm64)..."
|
|
|
+ GOOS=windows GOARCH=arm64 go build -ldflags "-X main.Version=${VERSION}" -o dist/${BINARY_NAME}-windows-arm64.exe ./cmd/monitor
|
|
|
|
|
|
-echo ""
|
|
|
-echo "Build complete! Binaries in dist/"
|
|
|
-ls -la dist/
|
|
|
+ echo ""
|
|
|
+ echo "Done! Binaries in dist/"
|
|
|
+ ls -la dist/
|
|
|
+fi
|