Skip to content

Commit 883f0d4

Browse files
authored
Merge pull request #2317 from 6vision/master
feat: add install.sh and run.sh
2 parents 6f682c9 + f4c62e7 commit 883f0d4

File tree

2 files changed

+201
-2
lines changed

2 files changed

+201
-2
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ DEMO视频:https://cdn.link-ai.tech/doc/cow_demo.mp4
4646

4747
# 🏷 更新日志
4848

49-
>**2024.08.02:** [1.7.0版本](https://github.com/zhayujie/chatgpt-on-wechat/releases/tag/1.6.9) 新增 讯飞4.0 模型、知识库引用来源展示、相关插件优化
49+
>**2024.09.26:** [1.7.2版本](https://github.com/zhayujie/chatgpt-on-wechat/releases/tag/1.7.2)[1.7.1版本](https://github.com/zhayujie/chatgpt-on-wechat/releases/tag/1.7.1) 文心,讯飞等模型优化、o1 模型、快速安装和管理脚本
50+
51+
>**2024.08.02:** [1.7.0版本](https://github.com/zhayujie/chatgpt-on-wechat/releases/tag/1.7.0) 新增 讯飞4.0 模型、知识库引用来源展示、相关插件优化
5052
5153
>**2024.07.19:** [1.6.9版本](https://github.com/zhayujie/chatgpt-on-wechat/releases/tag/1.6.9) 新增 gpt-4o-mini 模型、阿里语音识别、企微应用渠道路由优化
5254
@@ -80,8 +82,13 @@ DEMO视频:https://cdn.link-ai.tech/doc/cow_demo.mp4
8082

8183
# 🚀 快速开始
8284

83-
快速开始详细文档:[项目搭建文档](https://docs.link-ai.tech/cow/quick-start)
85+
- 快速开始详细文档:[项目搭建文档](https://docs.link-ai.tech/cow/quick-start)
8486

87+
- 快速安装脚本,详细使用指导:[一键安装启动脚本](https://github.com/zhayujie/chatgpt-on-wechat/wiki/%E4%B8%80%E9%94%AE%E5%AE%89%E8%A3%85%E5%90%AF%E5%8A%A8%E8%84%9A%E6%9C%AC)
88+
```bash
89+
bash <(curl -sS https://cdn.link-ai.tech/code/cow/install.sh)
90+
```
91+
- 项目管理脚本,详细使用指导:[项目管理脚本](https://github.com/zhayujie/chatgpt-on-wechat/wiki/%E9%A1%B9%E7%9B%AE%E7%AE%A1%E7%90%86%E8%84%9A%E6%9C%AC)
8592
## 一、准备
8693

8794
### 1. 账号注册

run.sh

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# 颜色定义
5+
RED='\033[0;31m' # 红色
6+
GREEN='\033[0;32m' # 绿色
7+
YELLOW='\033[0;33m' # 黄色
8+
BLUE='\033[0;34m' # 蓝色
9+
NC='\033[0m' # 无颜色
10+
11+
# 获取当前脚本的目录
12+
export BASE_DIR=$(cd "$(dirname "$0")"; pwd)
13+
echo -e "${GREEN}📁 BASE_DIR: ${BASE_DIR}${NC}"
14+
15+
# 检查 config.json 文件是否存在
16+
check_config_file() {
17+
if [ ! -f "${BASE_DIR}/config.json" ]; then
18+
echo -e "${RED}❌ 错误:未找到 config.json 文件。请确保 config.json 存在于当前目录。${NC}"
19+
exit 1
20+
fi
21+
}
22+
23+
# 检查 Python 版本是否大于等于 3.7,并检查 pip 是否可用
24+
check_python_version() {
25+
if ! command -v python3 &> /dev/null; then
26+
echo -e "${RED}❌ 错误:未找到 Python3。请安装 Python 3.7 或以上版本。${NC}"
27+
exit 1
28+
fi
29+
30+
PYTHON_VERSION=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
31+
PYTHON_MAJOR=$(echo "$PYTHON_VERSION" | cut -d'.' -f1)
32+
PYTHON_MINOR=$(echo "$PYTHON_VERSION" | cut -d'.' -f2)
33+
34+
if (( PYTHON_MAJOR < 3 || (PYTHON_MAJOR == 3 && PYTHON_MINOR < 7) )); then
35+
echo -e "${RED}❌ 错误:Python 版本为 ${PYTHON_VERSION}。请安装 Python 3.7 或以上版本。${NC}"
36+
exit 1
37+
fi
38+
39+
if ! python3 -m pip --version &> /dev/null; then
40+
echo -e "${RED}❌ 错误:未找到 pip。请安装 pip。${NC}"
41+
exit 1
42+
fi
43+
}
44+
45+
# 检查并安装缺失的依赖
46+
install_dependencies() {
47+
echo -e "${YELLOW}⏳ 正在安装依赖...${NC}"
48+
49+
if [ ! -f "${BASE_DIR}/requirements.txt" ]; then
50+
echo -e "${RED}❌ 错误:未找到 requirements.txt 文件。${NC}"
51+
exit 1
52+
fi
53+
54+
# 安装 requirements.txt 中的依赖,使用清华大学的 PyPI 镜像
55+
pip3 install -r "${BASE_DIR}/requirements.txt" -i https://pypi.tuna.tsinghua.edu.cn/simple
56+
57+
# 处理 requirements-optional.txt(如果存在)
58+
if [ -f "${BASE_DIR}/requirements-optional.txt" ]; then
59+
echo -e "${YELLOW}⏳ 正在安装可选的依赖...${NC}"
60+
pip3 install -r "${BASE_DIR}/requirements-optional.txt" -i https://pypi.tuna.tsinghua.edu.cn/simple
61+
fi
62+
}
63+
64+
# 启动项目
65+
run_project() {
66+
echo -e "${GREEN}🚀 准备启动项目...${NC}"
67+
cd "${BASE_DIR}"
68+
sleep 2
69+
70+
71+
# 判断操作系统类型
72+
OS_TYPE=$(uname)
73+
74+
if [[ "$OS_TYPE" == "Linux" ]]; then
75+
# 在 Linux 上使用 setsid
76+
setsid python3 "${BASE_DIR}/app.py" > "${BASE_DIR}/nohup.out" 2>&1 &
77+
echo -e "${GREEN}🚀 正在启动 ChatGPT-on-WeChat (Linux)...${NC}"
78+
elif [[ "$OS_TYPE" == "Darwin" ]]; then
79+
# 在 macOS 上直接运行
80+
python3 "${BASE_DIR}/app.py" > "${BASE_DIR}/nohup.out" 2>&1 &
81+
echo -e "${GREEN}🚀 正在启动 ChatGPT-on-WeChat (macOS)...${NC}"
82+
else
83+
echo -e "${RED}❌ 错误:不支持的操作系统 ${OS_TYPE}${NC}"
84+
exit 1
85+
fi
86+
87+
sleep 2
88+
# 显示日志输出,供用户扫码
89+
tail -n 30 -f "${BASE_DIR}/nohup.out"
90+
91+
}
92+
# 更新项目
93+
update_project() {
94+
echo -e "${GREEN}🔄 准备更新项目,现在停止项目...${NC}"
95+
cd "${BASE_DIR}"
96+
97+
# 停止项目
98+
stop_project
99+
echo -e "${GREEN}🔄 开始更新项目...${NC}"
100+
# 更新代码,从 git 仓库拉取最新代码
101+
if [ -d .git ]; then
102+
GIT_PULL_OUTPUT=$(git pull)
103+
if [ $? -eq 0 ]; then
104+
if [[ "$GIT_PULL_OUTPUT" == *"Already up to date."* ]]; then
105+
echo -e "${GREEN}✅ 代码已经是最新的。${NC}"
106+
else
107+
echo -e "${GREEN}✅ 代码更新完成。${NC}"
108+
fi
109+
else
110+
echo -e "${YELLOW}⚠️ 从 GitHub 更新失败,尝试切换到 Gitee 仓库...${NC}"
111+
# 更改远程仓库为 Gitee
112+
git remote set-url origin https://gitee.com/zhayujie/chatgpt-on-wechat.git
113+
GIT_PULL_OUTPUT=$(git pull)
114+
if [ $? -eq 0 ]; then
115+
if [[ "$GIT_PULL_OUTPUT" == *"Already up to date."* ]]; then
116+
echo -e "${GREEN}✅ 代码已经是最新的。${NC}"
117+
else
118+
echo -e "${GREEN}✅ 从 Gitee 更新成功。${NC}"
119+
fi
120+
else
121+
echo -e "${RED}❌ 错误:从 Gitee 更新仍然失败,请检查网络连接。${NC}"
122+
exit 1
123+
fi
124+
fi
125+
else
126+
echo -e "${RED}❌ 错误:当前目录不是 git 仓库,无法更新代码。${NC}"
127+
exit 1
128+
fi
129+
130+
# 安装依赖
131+
install_dependencies
132+
133+
# 启动项目
134+
run_project
135+
}
136+
137+
# 停止项目
138+
stop_project() {
139+
echo -e "${GREEN}🛑 正在停止项目...${NC}"
140+
cd "${BASE_DIR}"
141+
pid=$(ps ax | grep -i app.py | grep "${BASE_DIR}" | grep python3 | grep -v grep | awk '{print $1}')
142+
if [ -z "$pid" ] ; then
143+
echo -e "${YELLOW}⚠️ 未找到正在运行的 ChatGPT-on-WeChat。${NC}"
144+
return
145+
fi
146+
147+
echo -e "${GREEN}🛑 正在运行的 ChatGPT-on-WeChat (PID: ${pid})${NC}"
148+
149+
kill ${pid}
150+
sleep 3
151+
152+
if ps -p $pid > /dev/null; then
153+
echo -e "${YELLOW}⚠️ 进程未停止,尝试强制终止...${NC}"
154+
kill -9 ${pid}
155+
fi
156+
157+
echo -e "${GREEN}✅ 已停止 ChatGPT-on-WeChat (PID: ${pid})${NC}"
158+
}
159+
160+
# 主函数,根据用户参数执行操作
161+
case "$1" in
162+
start)
163+
check_config_file
164+
check_python_version
165+
run_project
166+
;;
167+
stop)
168+
stop_project
169+
;;
170+
restart)
171+
stop_project
172+
check_config_file
173+
check_python_version
174+
run_project
175+
;;
176+
update)
177+
check_config_file
178+
check_python_version
179+
update_project
180+
;;
181+
*)
182+
echo -e "${YELLOW}=========================================${NC}"
183+
echo -e "${YELLOW}用法:${GREEN}$0 ${BLUE}{start|stop|restart|update}${NC}"
184+
echo -e "${YELLOW}示例:${NC}"
185+
echo -e " ${GREEN}$0 ${BLUE}start${NC}"
186+
echo -e " ${GREEN}$0 ${BLUE}stop${NC}"
187+
echo -e " ${GREEN}$0 ${BLUE}restart${NC}"
188+
echo -e " ${GREEN}$0 ${BLUE}update${NC}"
189+
echo -e "${YELLOW}=========================================${NC}"
190+
exit 1
191+
;;
192+
esac

0 commit comments

Comments
 (0)