fix: install.sh 使用 LF 换行,避免 Linux 执行报错
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
* text=auto
|
||||||
|
*.sh text eol=lf
|
||||||
|
*.bash text eol=lf
|
||||||
|
deploy/* text eol=lf
|
||||||
+70
-70
@@ -1,70 +1,70 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# K线点位标注工具 - Ubuntu 一键部署脚本
|
# K线点位标注工具 - Ubuntu 一键部署脚本
|
||||||
# 用法: sudo bash deploy/install.sh
|
# 用法: sudo bash deploy/install.sh
|
||||||
# 部署目录: /opt/chart-label-tool
|
# 部署目录: /opt/chart-label-tool
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
APP_DIR="/opt/chart-label-tool"
|
APP_DIR="/opt/chart-label-tool"
|
||||||
REPO_URL="https://git.bz121.com/dekun/chart-label-tool.git"
|
REPO_URL="https://git.bz121.com/dekun/chart-label-tool.git"
|
||||||
PORT=8010
|
PORT=8010
|
||||||
SERVICE_USER="root"
|
SERVICE_USER="root"
|
||||||
|
|
||||||
echo "==> K线点位标注工具 部署开始"
|
echo "==> K线点位标注工具 部署开始"
|
||||||
|
|
||||||
if [[ "$(id -u)" -ne 0 ]]; then
|
if [[ "$(id -u)" -ne 0 ]]; then
|
||||||
echo "请使用 root 运行: sudo bash deploy/install.sh"
|
echo "请使用 root 运行: sudo bash deploy/install.sh"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 依赖
|
# 依赖
|
||||||
apt-get update -qq
|
apt-get update -qq
|
||||||
apt-get install -y -qq git python3 python3-venv python3-pip curl
|
apt-get install -y -qq git python3 python3-venv python3-pip curl
|
||||||
|
|
||||||
# Node.js + PM2(若未安装)
|
# Node.js + PM2(若未安装)
|
||||||
if ! command -v pm2 &>/dev/null; then
|
if ! command -v pm2 &>/dev/null; then
|
||||||
if ! command -v node &>/dev/null; then
|
if ! command -v node &>/dev/null; then
|
||||||
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
|
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
|
||||||
apt-get install -y -qq nodejs
|
apt-get install -y -qq nodejs
|
||||||
fi
|
fi
|
||||||
npm install -g pm2
|
npm install -g pm2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 拉取代码
|
# 拉取代码
|
||||||
if [[ -d "$APP_DIR/.git" ]]; then
|
if [[ -d "$APP_DIR/.git" ]]; then
|
||||||
echo "==> 更新已有仓库 $APP_DIR"
|
echo "==> 更新已有仓库 $APP_DIR"
|
||||||
cd "$APP_DIR"
|
cd "$APP_DIR"
|
||||||
git pull --ff-only origin main || git pull --ff-only
|
git pull --ff-only origin main || git pull --ff-only
|
||||||
else
|
else
|
||||||
echo "==> 克隆仓库到 $APP_DIR"
|
echo "==> 克隆仓库到 $APP_DIR"
|
||||||
git clone "$REPO_URL" "$APP_DIR"
|
git clone "$REPO_URL" "$APP_DIR"
|
||||||
cd "$APP_DIR"
|
cd "$APP_DIR"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Python 虚拟环境
|
# Python 虚拟环境
|
||||||
if [[ ! -d "$APP_DIR/venv" ]]; then
|
if [[ ! -d "$APP_DIR/venv" ]]; then
|
||||||
echo "==> 创建 Python 虚拟环境"
|
echo "==> 创建 Python 虚拟环境"
|
||||||
python3 -m venv "$APP_DIR/venv"
|
python3 -m venv "$APP_DIR/venv"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# PM2 启动/重载
|
# PM2 启动/重载
|
||||||
echo "==> 配置 PM2 守护进程"
|
echo "==> 配置 PM2 守护进程"
|
||||||
pm2 delete chart-label-tool 2>/dev/null || true
|
pm2 delete chart-label-tool 2>/dev/null || true
|
||||||
pm2 start "$APP_DIR/deploy/ecosystem.config.cjs"
|
pm2 start "$APP_DIR/deploy/ecosystem.config.cjs"
|
||||||
pm2 save
|
pm2 save
|
||||||
pm2 startup systemd -u "$SERVICE_USER" --hp "/root" 2>/dev/null || pm2 startup
|
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
|
if command -v ufw &>/dev/null && ufw status | grep -q "Status: active"; then
|
||||||
ufw allow "$PORT/tcp" 2>/dev/null || true
|
ufw allow "$PORT/tcp" 2>/dev/null || true
|
||||||
echo "==> 已尝试放行 UFW 端口 $PORT"
|
echo "==> 已尝试放行 UFW 端口 $PORT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "=========================================="
|
echo "=========================================="
|
||||||
echo " 部署完成"
|
echo " 部署完成"
|
||||||
echo " 访问地址: http://<服务器局域网IP>:$PORT"
|
echo " 访问地址: http://<服务器局域网IP>:$PORT"
|
||||||
echo " 应用目录: $APP_DIR"
|
echo " 应用目录: $APP_DIR"
|
||||||
echo " 查看状态: pm2 status"
|
echo " 查看状态: pm2 status"
|
||||||
echo " 查看日志: pm2 logs chart-label-tool"
|
echo " 查看日志: pm2 logs chart-label-tool"
|
||||||
echo "=========================================="
|
echo "=========================================="
|
||||||
|
|||||||
@@ -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`
|
1. `pm2 status` 确认进程为 `online`
|
||||||
|
|||||||
Reference in New Issue
Block a user