From aa33cb5da6f656c62ec07678e14fea87d877c1c5 Mon Sep 17 00:00:00 2001 From: dekun Date: Wed, 27 May 2026 14:25:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20install.sh=20=E4=BD=BF=E7=94=A8=20LF=20?= =?UTF-8?q?=E6=8D=A2=E8=A1=8C=EF=BC=8C=E9=81=BF=E5=85=8D=20Linux=20?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- .gitattributes | 4 ++ deploy/install.sh | 140 +++++++++++++++++++++++----------------------- docs/DEPLOY.md | 15 +++++ 3 files changed, 89 insertions(+), 70 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..d454939 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +* text=auto +*.sh text eol=lf +*.bash text eol=lf +deploy/* text eol=lf diff --git a/deploy/install.sh b/deploy/install.sh index e458372..5611b1b 100644 --- a/deploy/install.sh +++ b/deploy/install.sh @@ -1,70 +1,70 @@ -#!/bin/bash -# K线点位标注工具 - Ubuntu 一键部署脚本 -# 用法: sudo bash deploy/install.sh -# 部署目录: /opt/chart-label-tool - -set -euo pipefail - -APP_DIR="/opt/chart-label-tool" -REPO_URL="https://git.bz121.com/dekun/chart-label-tool.git" -PORT=8010 -SERVICE_USER="root" - -echo "==> K线点位标注工具 部署开始" - -if [[ "$(id -u)" -ne 0 ]]; then - echo "请使用 root 运行: sudo bash deploy/install.sh" - exit 1 -fi - -# 依赖 -apt-get update -qq -apt-get install -y -qq git python3 python3-venv python3-pip curl - -# Node.js + PM2(若未安装) -if ! command -v pm2 &>/dev/null; then - if ! command -v node &>/dev/null; then - curl -fsSL https://deb.nodesource.com/setup_20.x | bash - - apt-get install -y -qq nodejs - fi - npm install -g pm2 -fi - -# 拉取代码 -if [[ -d "$APP_DIR/.git" ]]; then - echo "==> 更新已有仓库 $APP_DIR" - cd "$APP_DIR" - git pull --ff-only origin main || git pull --ff-only -else - echo "==> 克隆仓库到 $APP_DIR" - git clone "$REPO_URL" "$APP_DIR" - cd "$APP_DIR" -fi - -# Python 虚拟环境 -if [[ ! -d "$APP_DIR/venv" ]]; then - echo "==> 创建 Python 虚拟环境" - python3 -m venv "$APP_DIR/venv" -fi - -# PM2 启动/重载 -echo "==> 配置 PM2 守护进程" -pm2 delete chart-label-tool 2>/dev/null || true -pm2 start "$APP_DIR/deploy/ecosystem.config.cjs" -pm2 save -pm2 startup systemd -u "$SERVICE_USER" --hp "/root" 2>/dev/null || pm2 startup - -# 防火墙提示(可选) -if command -v ufw &>/dev/null && ufw status | grep -q "Status: active"; then - ufw allow "$PORT/tcp" 2>/dev/null || true - echo "==> 已尝试放行 UFW 端口 $PORT" -fi - -echo "" -echo "==========================================" -echo " 部署完成" -echo " 访问地址: http://<服务器局域网IP>:$PORT" -echo " 应用目录: $APP_DIR" -echo " 查看状态: pm2 status" -echo " 查看日志: pm2 logs chart-label-tool" -echo "==========================================" +#!/bin/bash +# K线点位标注工具 - Ubuntu 一键部署脚本 +# 用法: sudo bash deploy/install.sh +# 部署目录: /opt/chart-label-tool + +set -euo pipefail + +APP_DIR="/opt/chart-label-tool" +REPO_URL="https://git.bz121.com/dekun/chart-label-tool.git" +PORT=8010 +SERVICE_USER="root" + +echo "==> K线点位标注工具 部署开始" + +if [[ "$(id -u)" -ne 0 ]]; then + echo "请使用 root 运行: sudo bash deploy/install.sh" + exit 1 +fi + +# 依赖 +apt-get update -qq +apt-get install -y -qq git python3 python3-venv python3-pip curl + +# Node.js + PM2(若未安装) +if ! command -v pm2 &>/dev/null; then + if ! command -v node &>/dev/null; then + curl -fsSL https://deb.nodesource.com/setup_20.x | bash - + apt-get install -y -qq nodejs + fi + npm install -g pm2 +fi + +# 拉取代码 +if [[ -d "$APP_DIR/.git" ]]; then + echo "==> 更新已有仓库 $APP_DIR" + cd "$APP_DIR" + git pull --ff-only origin main || git pull --ff-only +else + echo "==> 克隆仓库到 $APP_DIR" + git clone "$REPO_URL" "$APP_DIR" + cd "$APP_DIR" +fi + +# Python 虚拟环境 +if [[ ! -d "$APP_DIR/venv" ]]; then + echo "==> 创建 Python 虚拟环境" + python3 -m venv "$APP_DIR/venv" +fi + +# PM2 启动/重载 +echo "==> 配置 PM2 守护进程" +pm2 delete chart-label-tool 2>/dev/null || true +pm2 start "$APP_DIR/deploy/ecosystem.config.cjs" +pm2 save +pm2 startup systemd -u "$SERVICE_USER" --hp "/root" 2>/dev/null || pm2 startup + +# 防火墙提示(可选) +if command -v ufw &>/dev/null && ufw status | grep -q "Status: active"; then + ufw allow "$PORT/tcp" 2>/dev/null || true + echo "==> 已尝试放行 UFW 端口 $PORT" +fi + +echo "" +echo "==========================================" +echo " 部署完成" +echo " 访问地址: http://<服务器局域网IP>:$PORT" +echo " 应用目录: $APP_DIR" +echo " 查看状态: pm2 status" +echo " 查看日志: pm2 logs chart-label-tool" +echo "==========================================" diff --git a/docs/DEPLOY.md b/docs/DEPLOY.md index e3c0863..f2583d0 100644 --- a/docs/DEPLOY.md +++ b/docs/DEPLOY.md @@ -144,6 +144,21 @@ pm2 restart chart-label-tool ## 故障排查 +### `install.sh: $'\r': command not found` + +脚本在 Windows 下编辑后可能带 **CRLF** 换行,Linux 无法执行。任选一种修复: + +```bash +# 方式一:去掉回车符后重新执行 +sed -i 's/\r$//' /opt/chart-label-tool/deploy/install.sh +sudo bash /opt/chart-label-tool/deploy/install.sh + +# 方式二:拉取已修复的仓库(含 .gitattributes 强制 LF) +cd /opt/chart-label-tool && git pull +sed -i 's/\r$//' deploy/install.sh +sudo bash deploy/install.sh +``` + ### 页面无法打开 1. `pm2 status` 确认进程为 `online`