safesight-control/scripts/deploy/install.sh

73 lines
2.4 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
# 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)
UPGRADE=false
if [ -f "$INSTALL_DIR/bin/safesightd" ]; then
UPGRADE=true
echo "========== SafeSight Control 升级 =========="
echo "检测到已有安装,将保留数据库和配置文件"
systemctl stop safesightd 2>/dev/null || true
else
echo "========== SafeSight Control 安装 =========="
fi
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,configs,tools,scripts,models/standard_models}
# 复制二进制(始终更新)
cp "$SCRIPT_DIR/$BIN" "$INSTALL_DIR/bin/safesightd"
chmod +x "$INSTALL_DIR/bin/safesightd"
# 配置文件:仅在全新安装时创建,升级保留
if [ "$UPGRADE" = false ] && [ -f "$SCRIPT_DIR/safesightd.json.example" ]; then
cp "$SCRIPT_DIR/safesightd.json.example" "$INSTALL_DIR/config/safesightd.json"
echo " ✓ 配置已创建(请修改 agent_token"
else
echo " ✓ 配置文件保留"
fi
# 种子数据、工具、脚本(始终更新)
[ -d "$SCRIPT_DIR/configs" ] && cp -r "$SCRIPT_DIR/configs"/* "$INSTALL_DIR/configs/" 2>/dev/null && echo " ✓ 种子数据已更新"
[ -d "$SCRIPT_DIR/tools" ] && cp -r "$SCRIPT_DIR/tools"/* "$INSTALL_DIR/tools/" 2>/dev/null && echo " ✓ 构建工具已更新"
[ -d "$SCRIPT_DIR/scripts" ] && cp -r "$SCRIPT_DIR/scripts"/* "$INSTALL_DIR/scripts/" 2>/dev/null && echo " ✓ 脚本已更新"
[ -d "$SCRIPT_DIR/models" ] && cp -r "$SCRIPT_DIR/models"/* "$INSTALL_DIR/models/" 2>/dev/null && echo " ✓ 标准模型已更新"
[ -d "$SCRIPT_DIR/deps" ] && cp -r "$SCRIPT_DIR/deps" "$INSTALL_DIR/" 2>/dev/null && echo " ✓ 依赖包已更新"
# 安装/更新服务
cp "$SCRIPT_DIR/safesightd.service" /etc/systemd/system/
systemctl daemon-reload
if [ "$UPGRADE" = true ]; then
systemctl start safesightd
else
systemctl enable --now safesightd
fi
echo ""
echo "========== 完成 =========="
systemctl status safesightd --no-pager -l | head -10
echo ""
echo "打开 http://$(hostname -I | awk '{print $1}'):18080"