-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·123 lines (101 loc) · 3.14 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·123 lines (101 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
# deploy.sh - Claude Code 飞书连接自动化部署脚本
set -e
# 颜色输出函数
red() { echo -e "\033[0;31m$1\033[0m"; }
green() { echo -e "\033[0;32m$1\033[0m"; }
yellow() { echo -e "\033[1;33m$1\033[0m"; }
blue() { echo -e "\033[0;34m$1\033[0m"; }
# 检查函数
check_command() {
if ! command -v "$1" &> /dev/null; then
red "错误:$1 未找到,请先安装 $1"
exit 1
fi
}
check_node_version() {
local required_version=18
local node_version=$(node -v | cut -d'v' -f2 | cut -d'.' -f1)
if [ "$node_version" -lt "$required_version" ]; then
red "错误:Node.js 版本需要 >= $required_version.x,当前版本:$(node -v)"
exit 1
fi
}
# 主程序
main() {
blue "开始部署 Claude Code 飞书连接..."
# 检查依赖
blue "检查系统依赖..."
check_command node
check_command npm
check_command git
check_node_version
# 创建日志目录
blue "创建日志目录..."
mkdir -p logs
# 检查项目结构
if [ ! -d ".claude/skills" ]; then
red "错误:.claude/skills 目录不存在,请检查项目结构"
exit 1
fi
if [ ! -d ".claude/skills/mycc" ]; then
red "错误:.claude/skills/mycc 目录不存在,请检查项目结构"
exit 1
fi
# 安装项目依赖
blue "安装项目依赖..."
cd .claude/skills/mycc/scripts || exit 1
if [ ! -d "node_modules" ]; then
blue "首次安装依赖,可能需要几分钟..."
npm install
fi
cd - || exit 1
# 检查配置文件
blue "检查配置文件..."
if [ ! -f ".env" ]; then
if [ -f ".env.example" ]; then
yellow "警告:配置文件不存在,正在复制示例配置"
cp .env.example .env
yellow "请编辑 .env 文件配置您的应用信息"
else
red "错误:配置文件不存在,没有找到 .env.example"
exit 1
fi
fi
# 启动服务
blue "启动 Claude Code 飞书连接..."
cd .claude/skills/mycc/scripts || exit 1
if command -v pm2 &> /dev/null; then
blue "使用 PM2 管理进程..."
pm2 start /Users/zhangjinlong/mycc/feishu-claude-code/ecosystem.config.js
else
yellow "警告:PM2 未安装,使用直接启动方式"
npm start &
fi
cd - || exit 1
# 检查服务状态
blue "检查服务启动状态..."
sleep 5
if curl -s "http://localhost:18080/health" &> /dev/null; then
green "服务启动成功!"
blue "服务地址:http://localhost:18080"
if command -v pm2 &> /dev/null; then
pm2 status
fi
else
red "服务启动失败,请检查日志"
if [ -f "logs/out.log" ]; then
blue "日志输出:"
head -50 logs/out.log
fi
exit 1
fi
green "部署完成!"
blue "可以通过以下方式访问服务:"
blue "1. 飞书机器人:在飞书中与应用互动"
blue "2. HTTP API:http://localhost:18080"
}
# 检查脚本是否直接运行
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi