From e4113857185367b306410dae1a2b5ce4bab0b4f4 Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Thu, 23 Jul 2026 18:09:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=80=E9=94=AE=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=20install.sh=EF=BC=8C=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E6=9E=B6=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/deployment.md | 23 ++++-------------- scripts/deploy/install.sh | 51 +++++++++++++++++++++++++++++++++++++++ scripts/package.sh | 31 ++++++++---------------- 3 files changed, 66 insertions(+), 39 deletions(-) create mode 100644 scripts/deploy/install.sh diff --git a/docs/deployment.md b/docs/deployment.md index 3deca8f..19108f5 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -25,28 +25,15 @@ bash scripts/package.sh # 传到设备 scp safesight-control-*.tar.gz user@server:/tmp/ -# 解压 +# 解压并一键安装 cd /tmp && tar -xzf safesight-control-*.tar.gz cd safesight-control-* - -# 安装 -sudo mkdir -p /opt/safesightd/{bin,config,data} -sudo cp safesightd-linux-arm64 /opt/safesightd/bin/safesightd -sudo chmod +x /opt/safesightd/bin/safesightd -sudo cp safesightd.json.example /opt/safesightd/config/safesightd.json -sudo cp -r configs /opt/safesightd/ -sudo cp -r tools /opt/safesightd/ -sudo cp -r scripts /opt/safesightd/ - -# 安装服务 -sudo cp safesightd.service /etc/systemd/system/ -sudo systemctl daemon-reload -sudo systemctl enable --now safesightd - -# 首次启动自动导入种子数据,无需手动操作 +sudo bash install.sh ``` -AMD64 部署同上,二进制改为 `safesightd-linux-amd64`。 +AMD64 部署同上,`install.sh` 自动识别架构。 + +首次启动自动导入种子数据,无需手动操作。 --- diff --git a/scripts/deploy/install.sh b/scripts/deploy/install.sh new file mode 100644 index 0000000..dcaba3c --- /dev/null +++ b/scripts/deploy/install.sh @@ -0,0 +1,51 @@ +#!/bin/bash +# SafeSight Control 一键安装脚本 +# 用法: sudo bash install.sh +set -e + +if [ "$EUID" -ne 0 ]; then + echo "请用 sudo 运行" + exit 1 +fi + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +INSTALL_DIR="${1:-/opt/safesightd}" +ARCH=$(uname -m) + +echo "========== SafeSight Control 安装 ==========" +echo "安装目录: $INSTALL_DIR" + +# 选二进制 +if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then + BIN="safesightd-linux-arm64" +elif [ "$ARCH" = "x86_64" ]; then + BIN="safesightd-linux-amd64" +else + echo "不支持的架构: $ARCH" + exit 1 +fi + +# 创建目录 +mkdir -p "$INSTALL_DIR"/{bin,config,data} + +# 复制文件 +cp "$SCRIPT_DIR/$BIN" "$INSTALL_DIR/bin/safesightd" +chmod +x "$INSTALL_DIR/bin/safesightd" + +[ -f "$SCRIPT_DIR/safesightd.json.example" ] && cp "$SCRIPT_DIR/safesightd.json.example" "$INSTALL_DIR/config/safesightd.json" +[ -d "$SCRIPT_DIR/configs" ] && cp -r "$SCRIPT_DIR/configs" "$INSTALL_DIR/" +[ -d "$SCRIPT_DIR/tools" ] && cp -r "$SCRIPT_DIR/tools" "$INSTALL_DIR/" +[ -d "$SCRIPT_DIR/scripts" ] && cp -r "$SCRIPT_DIR/scripts" "$INSTALL_DIR/" +[ -d "$SCRIPT_DIR/deps" ] && cp -r "$SCRIPT_DIR/deps" "$INSTALL_DIR/" + +# 安装服务 +cp "$SCRIPT_DIR/safesightd.service" /etc/systemd/system/ +systemctl daemon-reload +systemctl enable --now safesightd + +echo "" +echo "========== 安装完成 ==========" +echo "服务状态:" +systemctl status safesightd --no-pager -l +echo "" +echo "打开 http://$(hostname -I | awk '{print $1}'):18080" diff --git a/scripts/package.sh b/scripts/package.sh index b03c6b0..6842bdb 100644 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -25,6 +25,7 @@ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o "$BUILD_DIR/s echo "[2/6] 部署文件..." mkdir -p "$BUILD_DIR/scripts" cp scripts/deploy/safesightd.service "$BUILD_DIR/" +cp scripts/deploy/install.sh "$BUILD_DIR/" cp scripts/deploy/safesightd "$BUILD_DIR/" 2>/dev/null || true cp scripts/deploy/import-assets.py "$BUILD_DIR/scripts/" 2>/dev/null || true cp scripts/deploy/register-face-gallery.py "$BUILD_DIR/scripts/" 2>/dev/null || true @@ -79,29 +80,17 @@ cat > "$BUILD_DIR/README.txt" << 'EOF' SafeSight Control 离线部署包 ============================= -快速部署(ARM64): - sudo mkdir -p /opt/safesightd/{bin,config,data,scripts,tools} - sudo cp safesightd-linux-arm64 /opt/safesightd/bin/safesightd - sudo chmod +x /opt/safesightd/bin/safesightd - sudo cp safesightd.json.example /opt/safesightd/config/safesightd.json - sudo cp -r configs /opt/safesightd/ - sudo cp -r tools /opt/safesightd/ - sudo cp -r scripts /opt/safesightd/ - sudo cp safesightd.service /etc/systemd/system/ - sudo systemctl daemon-reload - sudo systemctl enable --now safesightd - -初始化(首次部署必做): - sudo python3 /opt/safesightd/scripts/import-assets.py /opt/safesightd/configs - -安装人脸库构建依赖(离线): - sudo pip3 install deps/*.whl - -人脸库注册(如已有 face_gallery.db): - sudo cp face_gallery.db /opt/safesightd/resources/standard_resources/face_gallery/ - sudo python3 /opt/safesightd/scripts/register-face-gallery.py +一键安装: + sudo bash install.sh 打开 http://:18080 + +--- +首次启动自动导入模板/场景/覆盖层,无需手动操作。 + +人脸库构建(离线环境): + sudo pip3 install deps/*.whl # 安装 Python 依赖 + curl -X POST http://localhost:18080/face-gallery/build # 触发构建 EOF # ── 打包 ──