mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-29 05:09:46 +01:00
refactor: 更新 docker-setup.sh 脚本以支持多操作系统下载命令
- 修改脚本以检测操作系统类型,并根据不同系统选择合适的下载命令(curl 或 wget)。 - 优化错误处理,确保在下载失败时提供清晰的提示信息。 - 更新 Deployment.md 文档,调整懒人脚本的使用说明,增加手动部署的步骤。
This commit is contained in:
parent
0ce59dccd0
commit
b9c86a4049
2 changed files with 99 additions and 47 deletions
|
|
@ -1,22 +1,61 @@
|
|||
#!/bin/bash
|
||||
#!/bin/sh
|
||||
|
||||
# 设置颜色输出
|
||||
# 检测操作系统类型
|
||||
case "$(uname -s)" in
|
||||
Linux*) OS=Linux;;
|
||||
Darwin*) OS=Mac;;
|
||||
CYGWIN*) OS=Windows;;
|
||||
MINGW*) OS=Windows;;
|
||||
MSYS*) OS=Windows;;
|
||||
*) OS=UNKNOWN;;
|
||||
esac
|
||||
|
||||
# 设置颜色(Windows CMD 不支持,但不影响使用)
|
||||
if [ "$OS" = "Windows" ]; then
|
||||
GREEN=""
|
||||
RED=""
|
||||
NC=""
|
||||
else
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
NC='\033[0m'
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}开始安装小智服务端...${NC}"
|
||||
echo "${GREEN}开始安装小智服务端...${NC}"
|
||||
|
||||
# 创建必要的目录
|
||||
echo "创建目录结构..."
|
||||
mkdir -p xiaozhi-server/data xiaozhi-server/models/SenseVoiceSmall
|
||||
cd xiaozhi-server
|
||||
cd xiaozhi-server || exit
|
||||
|
||||
# 根据操作系统选择下载命令
|
||||
if [ "$OS" = "Windows" ]; then
|
||||
DOWNLOAD_CMD="curl -L -o"
|
||||
if ! command -v curl >/dev/null 2>&1; then
|
||||
DOWNLOAD_CMD="powershell -Command Invoke-WebRequest -Uri"
|
||||
DOWNLOAD_CMD_SUFFIX="-OutFile"
|
||||
fi
|
||||
else
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
DOWNLOAD_CMD="curl -L -o"
|
||||
elif command -v wget >/dev/null 2>&1; then
|
||||
DOWNLOAD_CMD="wget -O"
|
||||
else
|
||||
echo "${RED}错误: 需要安装 curl 或 wget${NC}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# 下载语音识别模型
|
||||
echo "下载语音识别模型..."
|
||||
curl -L --progress-bar -o models/SenseVoiceSmall/model.pt https://modelscope.cn/models/iic/SenseVoiceSmall/resolve/master/model.pt
|
||||
if [ "$DOWNLOAD_CMD" = "powershell -Command Invoke-WebRequest -Uri" ]; then
|
||||
$DOWNLOAD_CMD "https://modelscope.cn/models/iic/SenseVoiceSmall/resolve/master/model.pt" $DOWNLOAD_CMD_SUFFIX "models/SenseVoiceSmall/model.pt"
|
||||
else
|
||||
$DOWNLOAD_CMD "models/SenseVoiceSmall/model.pt" "https://modelscope.cn/models/iic/SenseVoiceSmall/resolve/master/model.pt"
|
||||
fi
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "${RED}模型下载失败。请手动从以下地址下载:${NC}"
|
||||
echo "${RED}模型下载失败。请手动从以下地址下载:${NC}"
|
||||
echo "1. https://modelscope.cn/models/iic/SenseVoiceSmall/resolve/master/model.pt"
|
||||
echo "2. 百度网盘: https://pan.baidu.com/share/init?surl=QlgM58FHhYv1tFnUT_A8Sg (提取码: qvna)"
|
||||
echo "下载后请将文件放置在 models/SenseVoiceSmall/model.pt"
|
||||
|
|
@ -24,35 +63,40 @@ fi
|
|||
|
||||
# 下载配置文件
|
||||
echo "下载配置文件..."
|
||||
curl -L --progress-bar -o docker-compose.yml https://raw.githubusercontent.com/xinnan-tech/xiaozhi-esp32-server/main/main/xiaozhi-server/docker-compose.yml
|
||||
curl -L --progress-bar -o data/.config.yaml https://raw.githubusercontent.com/xinnan-tech/xiaozhi-esp32-server/main/main/xiaozhi-server/config.yaml
|
||||
if [ "$DOWNLOAD_CMD" = "powershell -Command Invoke-WebRequest -Uri" ]; then
|
||||
$DOWNLOAD_CMD "https://raw.githubusercontent.com/xinnan-tech/xiaozhi-esp32-server/main/main/xiaozhi-server/docker-compose.yml" $DOWNLOAD_CMD_SUFFIX "docker-compose.yml"
|
||||
$DOWNLOAD_CMD "https://raw.githubusercontent.com/xinnan-tech/xiaozhi-esp32-server/main/main/xiaozhi-server/config.yaml" $DOWNLOAD_CMD_SUFFIX "data/.config.yaml"
|
||||
else
|
||||
$DOWNLOAD_CMD "docker-compose.yml" "https://raw.githubusercontent.com/xinnan-tech/xiaozhi-esp32-server/main/main/xiaozhi-server/docker-compose.yml"
|
||||
$DOWNLOAD_CMD "data/.config.yaml" "https://raw.githubusercontent.com/xinnan-tech/xiaozhi-esp32-server/main/main/xiaozhi-server/config.yaml"
|
||||
fi
|
||||
|
||||
# 检查文件是否存在
|
||||
echo "检查文件完整性..."
|
||||
files_to_check=("docker-compose.yml" "data/.config.yaml" "models/SenseVoiceSmall/model.pt")
|
||||
all_files_exist=true
|
||||
FILES_TO_CHECK="docker-compose.yml data/.config.yaml models/SenseVoiceSmall/model.pt"
|
||||
ALL_FILES_EXIST=true
|
||||
|
||||
for file in "${files_to_check[@]}"; do
|
||||
if [ ! -f "$file" ]; then
|
||||
echo -e "${RED}错误: $file 不存在${NC}"
|
||||
all_files_exist=false
|
||||
for FILE in $FILES_TO_CHECK; do
|
||||
if [ ! -f "$FILE" ]; then
|
||||
echo "${RED}错误: $FILE 不存在${NC}"
|
||||
ALL_FILES_EXIST=false
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$all_files_exist" = false ]; then
|
||||
echo -e "${RED}某些文件下载失败,请检查上述错误信息并手动下载缺失的文件。${NC}"
|
||||
if [ "$ALL_FILES_EXIST" = false ]; then
|
||||
echo "${RED}某些文件下载失败,请检查上述错误信息并手动下载缺失的文件。${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}文件下载完成!${NC}"
|
||||
echo "${GREEN}文件下载完成!${NC}"
|
||||
echo "请编辑 data/.config.yaml 文件配置你的API密钥。"
|
||||
echo "配置完成后,运行以下命令启动服务:"
|
||||
echo -e "${GREEN}docker-compose up -d${NC}"
|
||||
echo "${GREEN}docker-compose up -d${NC}"
|
||||
echo "查看日志请运行:"
|
||||
echo -e "${GREEN}docker logs -f xiaozhi-esp32-server${NC}"
|
||||
echo "${GREEN}docker logs -f xiaozhi-esp32-server${NC}"
|
||||
|
||||
# 提示用户编辑配置文件
|
||||
echo -e "\n${RED}重要提示:${NC}"
|
||||
echo "\n${RED}重要提示:${NC}"
|
||||
echo "1. 请确保编辑 data/.config.yaml 文件,配置必要的API密钥"
|
||||
echo "2. 特别是 ChatGLM 和 mem0ai 的密钥必须配置"
|
||||
echo "3. 配置完成后再启动 docker 服务"
|
||||
|
|
@ -6,25 +6,29 @@ docker镜像已支持x86架构、arm64架构的CPU,支持在国产操作系统
|
|||
|
||||
如果您的电脑还没安装docker,可以按照这里的教程安装:[docker安装](https://www.runoob.com/docker/ubuntu-docker-install.html)
|
||||
|
||||
> [!NOTE]
|
||||
> 懒人脚本
|
||||
>
|
||||
> 你可以使用以下命令一键下载并执行部署脚本:
|
||||
> 请确保你的环境可以正常访问 GitHub 否则无法下载脚本。
|
||||
> ```bash
|
||||
> curl -L -o docker-setup.sh https://raw.githubusercontent.com/xinnan-tech/xiaozhi-esp32-server/main/docker-setup.sh && chmod +x docker-setup.sh
|
||||
> ```
|
||||
>
|
||||
> 如果您的电脑是windows系统,请使用powershell运行以下命令:
|
||||
> ```bash
|
||||
> bash docker-setup.sh
|
||||
> ```
|
||||
> 如果您的电脑是linux系统,请使用bash运行以下命令:
|
||||
> ```bash
|
||||
> ./docker-setup.sh
|
||||
> ```
|
||||
>
|
||||
> 脚本会自动完成以下操作:
|
||||
### 1.1 懒人脚本
|
||||
|
||||
你可以使用以下命令一键下载并执行部署脚本:
|
||||
请确保你的环境可以正常访问 GitHub 否则无法下载脚本。
|
||||
```bash
|
||||
curl -L -o docker-setup.sh https://raw.githubusercontent.com/xinnan-tech/xiaozhi-esp32-server/main/docker-setup.sh
|
||||
```
|
||||
|
||||
如果您的电脑是windows系统,请使用使用 Git Bash、WSL、PowerShell 或 CMD 运行以下命令:
|
||||
```bash
|
||||
# Git Bash 或 WSL
|
||||
sh docker-setup.sh
|
||||
# PowerShell 或 CMD
|
||||
.\docker-setup.sh
|
||||
```
|
||||
|
||||
如果您的电脑是linux 或者 macos 系统,请使用终端运行以下命令:
|
||||
```bash
|
||||
chmod +x docker-setup.sh
|
||||
./docker-setup.sh
|
||||
```
|
||||
|
||||
脚本会自动完成以下操作:
|
||||
> 1. 创建必要的目录结构
|
||||
> 2. 下载语音识别模型
|
||||
> 3. 下载配置文件
|
||||
|
|
@ -32,7 +36,11 @@ docker镜像已支持x86架构、arm64架构的CPU,支持在国产操作系统
|
|||
>
|
||||
> 执行完成后,请按照提示配置 API 密钥。
|
||||
|
||||
## 2. 创建目录
|
||||
### 1.2 手动部署
|
||||
|
||||
如果懒人脚本无法正常运行,请手动部署。
|
||||
|
||||
#### 1.2.1 创建目录
|
||||
|
||||
安装完后,你需要为这个项目找一个安放配置文件的目录,例如我们可以新建一个文件夹叫`xiaozhi-server`。
|
||||
|
||||
|
|
@ -47,7 +55,7 @@ mkdir -p xiaozhi-server/data xiaozhi-server/models/SenseVoiceSmall
|
|||
cd xiaozhi-server
|
||||
```
|
||||
|
||||
## 3. 下载语音识别模型文件
|
||||
#### 1.2.2 下载语音识别模型文件
|
||||
|
||||
你需要下载语音识别的模型文件,因为本项目的默认语音识别用的是本地离线语音识别方案。
|
||||
|
||||
|
|
@ -60,11 +68,11 @@ cd xiaozhi-server
|
|||
curl -L --progress-bar -o models/SenseVoiceSmall/model.pt https://modelscope.cn/models/iic/SenseVoiceSmall/resolve/master/model.pt
|
||||
```
|
||||
|
||||
## 4. 下载配置文件
|
||||
#### 1.2.3 下载配置文件
|
||||
|
||||
你需要下载两个配置文件:`docker-compose.yaml` 和 `config.yaml`。你可以通过以下命令下载,或者手动从项目仓库下载这两个文件。
|
||||
|
||||
### 4.1 下载 docker-compose.yaml
|
||||
##### 1.2.3.1 下载 docker-compose.yaml
|
||||
|
||||
如果你的电脑安装了 curl 工具,可以直接使用以下命令下载:
|
||||
|
||||
|
|
@ -75,7 +83,7 @@ curl -L --progress-bar -o docker-compose.yml https://raw.githubusercontent.com/x
|
|||
如果没有安装 curl,你也可以直接用浏览器打开这个地址下载文件:
|
||||
https://raw.githubusercontent.com/xinnan-tech/xiaozhi-esp32-server/main/main/xiaozhi-server/docker-compose.yml
|
||||
|
||||
### 4.2 下载 config.yaml
|
||||
##### 1.2.3.2 下载 config.yaml
|
||||
|
||||
> [!NOTE]
|
||||
> 注意,`config.yaml` 文件需要放在 data 目录下,并且重命名成 `.config.yaml`
|
||||
|
|
|
|||
Loading…
Reference in a new issue