safesight-control/scripts/package.sh

46 lines
1.5 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 管理端离线部署包构建脚本
# 交叉编译 safesightd打包配置和部署脚本
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
PACKAGE_NAME="safesight-control-$(date +%Y%m%d-%H%M%S)"
BUILD_DIR="/tmp/$PACKAGE_NAME"
echo "========== 构建管理端离线部署包 =========="
echo ""
# 编译
echo "[1/2] 交叉编译..."
cd "$PROJECT_DIR"
mkdir -p "$BUILD_DIR"
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o "$BUILD_DIR/safesightd-linux-arm64" ./cmd/safesightd/ 2>/dev/null && echo " ✓ ARM64" || echo " ✗ ARM64 failed"
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o "$BUILD_DIR/safesightd-linux-amd64" ./cmd/safesightd/ 2>/dev/null && echo " ✓ AMD64" || echo " ✗ AMD64 failed"
# 打包
echo "[2/2] 打包..."
cp scripts/deploy/safesightd "$BUILD_DIR/"
cp scripts/deploy/safesightd.service "$BUILD_DIR/"
cp safesightd.json "$BUILD_DIR/safesightd.json.example" 2>/dev/null || true
cat > "$BUILD_DIR/README.txt" << 'EOF'
SafeSight Control 离线部署包
=============================
部署:
sudo ./safesightd install /opt/safesightd
sudo vi /opt/safesightd/config/safesightd.json # 修改 token
sudo systemctl start safesightd
打开 http://<IP>:18080
EOF
cd /tmp
tar -czf "$PROJECT_DIR/$PACKAGE_NAME.tar.gz" "$PACKAGE_NAME"
rm -rf "$BUILD_DIR"
echo ""
echo "✓ 打包完成: $PROJECT_DIR/$PACKAGE_NAME.tar.gz"
ls -lh "$PROJECT_DIR/$PACKAGE_NAME.tar.gz"