mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-27 04:49:47 +01:00
ci(docker): publish server images to GHCR; add server-base and app Dockerfiles
Workflows build and push thin server and web images; Dockerfiles match the downstream published image layout.
This commit is contained in:
parent
fa91c97685
commit
2f92efd51f
6 changed files with 576 additions and 231 deletions
2
.github/workflows/build-base-image.yml
vendored
2
.github/workflows/build-base-image.yml
vendored
|
|
@ -28,7 +28,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.TOKEN }}
|
password: ${{ github.token }}
|
||||||
|
|
||||||
- name: Build and push server-base
|
- name: Build and push server-base
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
|
|
|
||||||
90
.github/workflows/docker-image.yml
vendored
90
.github/workflows/docker-image.yml
vendored
|
|
@ -3,7 +3,7 @@ name: Docker Image CI
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- 'v*.*.*' # 只在以 v 开头的标签推送时触发,例如 v1.0.0
|
- 'v*.*.*' # Semver tags only, e.g. v1.0.0
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
workflow_run:
|
workflow_run:
|
||||||
workflows: ["Build Base Image"]
|
workflows: ["Build Base Image"]
|
||||||
|
|
@ -11,25 +11,45 @@ on:
|
||||||
- completed
|
- completed
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
version:
|
||||||
name: Release Docker images
|
name: Resolve version
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
version: ${{ steps.meta.outputs.version }}
|
||||||
|
is_version: ${{ steps.meta.outputs.is_version }}
|
||||||
|
steps:
|
||||||
|
- id: meta
|
||||||
|
run: |
|
||||||
|
if [[ "$GITHUB_REF" =~ ^refs/tags/v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
|
||||||
|
echo "version=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "is_version=true" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "version=latest" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "is_version=false" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
release:
|
||||||
|
name: Build and push ${{ matrix.name }}
|
||||||
|
needs: version
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- name: xiaozhi-server
|
||||||
|
file: Dockerfile-server
|
||||||
|
tag_prefix: server
|
||||||
|
cache_scope: docker-server
|
||||||
|
- name: manager-web
|
||||||
|
file: Dockerfile-web
|
||||||
|
tag_prefix: web
|
||||||
|
cache_scope: docker-web
|
||||||
permissions:
|
permissions:
|
||||||
packages: write
|
packages: write
|
||||||
contents: write
|
contents: write
|
||||||
id-token: write
|
id-token: write
|
||||||
issues: write
|
issues: write
|
||||||
steps:
|
steps:
|
||||||
- name: Check Disk Space
|
|
||||||
run: |
|
|
||||||
df -h
|
|
||||||
docker system df
|
|
||||||
|
|
||||||
- name: Clean up Docker resources
|
|
||||||
run: |
|
|
||||||
docker system prune -af
|
|
||||||
docker builder prune -af
|
|
||||||
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
|
@ -44,45 +64,19 @@ jobs:
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.TOKEN }}
|
password: ${{ github.token }}
|
||||||
|
|
||||||
- name: Extract version from tag
|
# linux/arm64 was slow under QEMU; add native ARM runners or restore: platforms: linux/amd64,linux/arm64
|
||||||
id: get_version
|
- name: Build and push ${{ matrix.name }}
|
||||||
run: |
|
|
||||||
if [[ "$GITHUB_REF" =~ ^refs/tags/v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
|
|
||||||
echo "VERSION=${BASH_REMATCH[1]}" >> $GITHUB_ENV
|
|
||||||
echo "IS_VERSION=true" >> $GITHUB_ENV
|
|
||||||
else
|
|
||||||
echo "VERSION=latest" >> $GITHUB_ENV
|
|
||||||
echo "IS_VERSION=false" >> $GITHUB_ENV
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 构建 xiaozhi-server 镜像
|
|
||||||
- name: Build and push xiaozhi-server
|
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: Dockerfile-server
|
file: ${{ matrix.file }}
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: ${{ needs.version.outputs.is_version == 'true' && format('ghcr.io/{0}:{1}_{2},ghcr.io/{0}:{1}_latest', github.repository, matrix.tag_prefix, needs.version.outputs.version) || format('ghcr.io/{0}:{1}_latest', github.repository, matrix.tag_prefix) }}
|
||||||
${{ env.IS_VERSION == 'true' && format('ghcr.io/{0}:server_{1},ghcr.io/{0}:server_latest', github.repository, env.VERSION) || format('ghcr.io/{0}:server_latest', github.repository) }}
|
platforms: linux/amd64
|
||||||
platforms: linux/amd64,linux/arm64
|
cache-from: type=gha,scope=${{ matrix.cache_scope }}
|
||||||
cache-from: type=gha
|
cache-to: type=gha,mode=max,scope=${{ matrix.cache_scope }}
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
build-args: |
|
|
||||||
BUILDKIT_PROGRESS=plain
|
|
||||||
|
|
||||||
# 构建 manager-api 镜像
|
|
||||||
- name: Build and push manager-web
|
|
||||||
uses: docker/build-push-action@v6
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: Dockerfile-web
|
|
||||||
push: true
|
|
||||||
tags: |
|
|
||||||
${{ env.IS_VERSION == 'true' && format('ghcr.io/{0}:web_{1},ghcr.io/{0}:web_latest', github.repository, env.VERSION) || format('ghcr.io/{0}:web_latest', github.repository) }}
|
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
cache-from: type=gha
|
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
build-args: |
|
build-args: |
|
||||||
BUILDKIT_PROGRESS=plain
|
BUILDKIT_PROGRESS=plain
|
||||||
|
SERVER_BASE_IMAGE=ghcr.io/${{ github.repository }}:server-base
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
# 生产镜像,仅包含应用代码
|
# Production image: application code on top of the published server-base image.
|
||||||
FROM ghcr.io/xinnan-tech/xiaozhi-esp32-server:server-base
|
# CI should pass SERVER_BASE_IMAGE=ghcr.io/${{ github.repository }}:server-base.
|
||||||
|
# Local default pulls the lapy org base (build server-base first if missing).
|
||||||
|
ARG SERVER_BASE_IMAGE=ghcr.io/lapy/xiaozhi-esp32-server:server-base
|
||||||
|
FROM ${SERVER_BASE_IMAGE}
|
||||||
|
|
||||||
COPY main/xiaozhi-server .
|
COPY main/xiaozhi-server .
|
||||||
|
|
||||||
# 启动应用
|
CMD ["python", "app.py"]
|
||||||
CMD ["python", "app.py"]
|
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,32 @@
|
||||||
# Dockerfile-server-base
|
# Dockerfile-server-base
|
||||||
# 基础镜像,包含系统依赖和Python包
|
# Base image with system dependencies and Python packages (matches upstream layout;
|
||||||
|
# locale and comments are Western; pip install kept compatible with openai-whisper).
|
||||||
|
|
||||||
FROM python:3.10-slim
|
FROM python:3.10-slim
|
||||||
|
|
||||||
# 安装系统依赖
|
# System packages: audio stack + locales for UTF-8 (en_US, not zh_CN)
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install -y --no-install-recommends libopus0 ffmpeg locales && \
|
apt-get install -y --no-install-recommends libopus0 ffmpeg locales && \
|
||||||
sed -i '/zh_CN.UTF-8/s/^# //g' /etc/locale.gen && \
|
sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && \
|
||||||
locale-gen && \
|
locale-gen && \
|
||||||
apt-get clean && \
|
apt-get clean && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# 配置pip使用国内镜像源(阿里云)并设置超时和重试
|
# Pip mirror and network resilience (same mirror family as upstream product)
|
||||||
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && \
|
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && \
|
||||||
pip config set global.trusted-host mirrors.aliyun.com && \
|
pip config set global.trusted-host mirrors.aliyun.com && \
|
||||||
pip config set global.timeout 120 && \
|
pip config set global.timeout 120 && \
|
||||||
pip config set install.retries 5
|
pip config set install.retries 5
|
||||||
|
|
||||||
# 设置环境变量以确保正确的字符编码
|
ENV LANG=en_US.UTF-8 \
|
||||||
ENV LANG=zh_CN.UTF-8 \
|
LC_ALL=en_US.UTF-8 \
|
||||||
LC_ALL=zh_CN.UTF-8 \
|
LANGUAGE=en_US:en \
|
||||||
LANGUAGE=zh_CN:zh \
|
|
||||||
PYTHONIOENCODING=utf-8
|
PYTHONIOENCODING=utf-8
|
||||||
|
|
||||||
WORKDIR /opt/xiaozhi-esp32-server
|
WORKDIR /opt/xiaozhi-esp32-server
|
||||||
|
|
||||||
# 复制requirements.txt
|
|
||||||
COPY main/xiaozhi-server/requirements.txt .
|
COPY main/xiaozhi-server/requirements.txt .
|
||||||
|
|
||||||
# 安装Python依赖
|
# openai-whisper uses legacy setuptools hooks; pin setuptools and skip build isolation
|
||||||
RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
|
RUN pip install --no-cache-dir --upgrade pip "setuptools<81" wheel && \
|
||||||
pip install --no-cache-dir -r requirements.txt --default-timeout=120 --retries 5
|
pip install --no-cache-dir --no-build-isolation -r requirements.txt --default-timeout=120 --retries 5
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
# 第一阶段:构建Vue前端
|
# Stage 1: Build Vue frontend
|
||||||
FROM node:18 AS web-builder
|
FROM node:18 AS web-builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY main/manager-web/package*.json ./
|
COPY main/manager-web/package*.json ./
|
||||||
|
|
@ -6,17 +6,16 @@ RUN npm install
|
||||||
COPY main/manager-web .
|
COPY main/manager-web .
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# 第二阶段:构建Java后端
|
# Stage 2: Build Java backend
|
||||||
FROM maven:3.9.4-eclipse-temurin-21 AS api-builder
|
FROM maven:3.9.4-eclipse-temurin-21 AS api-builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY main/manager-api/pom.xml .
|
COPY main/manager-api/pom.xml .
|
||||||
COPY main/manager-api/src ./src
|
COPY main/manager-api/src ./src
|
||||||
RUN mvn clean package -Dmaven.test.skip=true
|
RUN mvn clean package -Dmaven.test.skip=true
|
||||||
|
|
||||||
# 第三阶段:构建最终镜像
|
# Stage 3: Final runtime image
|
||||||
FROM bellsoft/liberica-runtime-container:jre-21-glibc
|
FROM bellsoft/liberica-runtime-container:jre-21-glibc
|
||||||
|
|
||||||
# 安装Nginx和字体库
|
|
||||||
RUN apk update && \
|
RUN apk update && \
|
||||||
apk add --no-cache --no-scripts \
|
apk add --no-cache --no-scripts \
|
||||||
nginx \
|
nginx \
|
||||||
|
|
@ -26,25 +25,18 @@ RUN apk update && \
|
||||||
&& rm -rf /var/cache/apk/* \
|
&& rm -rf /var/cache/apk/* \
|
||||||
&& mkdir -p /run/nginx /var/log/nginx /var/tmp/nginx /etc/nginx/conf.d
|
&& mkdir -p /run/nginx /var/log/nginx /var/tmp/nginx /etc/nginx/conf.d
|
||||||
|
|
||||||
# 复制项目自带的中文字体
|
|
||||||
COPY main/manager-web/public/generator/static/fonts/*.ttf /usr/share/fonts/
|
COPY main/manager-web/public/generator/static/fonts/*.ttf /usr/share/fonts/
|
||||||
|
|
||||||
# 更新字体缓存
|
|
||||||
RUN fc-cache -f -v
|
RUN fc-cache -f -v
|
||||||
|
|
||||||
# 配置Nginx
|
|
||||||
COPY docs/docker/nginx.conf /etc/nginx/nginx.conf
|
COPY docs/docker/nginx.conf /etc/nginx/nginx.conf
|
||||||
|
|
||||||
# 复制前端构建产物
|
|
||||||
COPY --from=web-builder /app/dist /usr/share/nginx/html
|
COPY --from=web-builder /app/dist /usr/share/nginx/html
|
||||||
|
|
||||||
# 复制Java后端JAR包
|
|
||||||
COPY --from=api-builder /app/target/xiaozhi-esp32-api.jar /app/xiaozhi-esp32-api.jar
|
COPY --from=api-builder /app/target/xiaozhi-esp32-api.jar /app/xiaozhi-esp32-api.jar
|
||||||
|
|
||||||
# 暴露端口
|
|
||||||
EXPOSE 8002
|
EXPOSE 8002
|
||||||
|
|
||||||
# 启动脚本
|
|
||||||
COPY docs/docker/start.sh /start.sh
|
COPY docs/docker/start.sh /start.sh
|
||||||
RUN chmod +x /start.sh
|
RUN chmod +x /start.sh
|
||||||
CMD ["/start.sh"]
|
CMD ["/start.sh"]
|
||||||
|
|
|
||||||
665
docker-setup.sh
665
docker-setup.sh
|
|
@ -1,43 +1,42 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# 脚本作者@VanillaNahida
|
# Script author @VanillaNahida
|
||||||
# 本文件是用于一键自动下载本项目所需文件,自动创建好目录
|
# This file is used for one-click automatic download of required files for this project and automatic directory creation
|
||||||
# 暂且只支持X86版本的Ubuntu系统,其他系统未测试
|
# Currently only supports X86 version of Ubuntu system, other systems are not tested
|
||||||
|
|
||||||
# 定义中断处理函数
|
# Define interrupt handler function
|
||||||
handle_interrupt() {
|
handle_interrupt() {
|
||||||
echo ""
|
echo ""
|
||||||
echo "安装已被用户中断(Ctrl+C或Esc)"
|
echo "Installation interrupted by user (Ctrl+C or Esc)"
|
||||||
echo "如需重新安装,请再次运行脚本"
|
echo "To reinstall, please run the script again"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# 设置信号捕获,处理Ctrl+C
|
# Set signal capture to handle Ctrl+C
|
||||||
trap handle_interrupt SIGINT
|
trap handle_interrupt SIGINT
|
||||||
|
|
||||||
# 处理Esc键
|
# Handle Esc key
|
||||||
# 保存终端设置
|
# Save terminal settings
|
||||||
old_stty_settings=$(stty -g)
|
old_stty_settings=$(stty -g)
|
||||||
# 设置终端立即响应,不回显
|
# Set terminal to respond immediately, no echo
|
||||||
stty -icanon -echo min 1 time 0
|
stty -icanon -echo min 1 time 0
|
||||||
|
|
||||||
# 后台进程检测Esc键
|
# Background process to detect Esc key
|
||||||
(while true; do
|
(while true; do
|
||||||
read -r key
|
read -r key
|
||||||
if [[ $key == $'\e' ]]; then
|
if [[ $key == $'\e' ]]; then
|
||||||
# 检测到Esc键,触发中断处理
|
# Detected Esc key, trigger interrupt handler
|
||||||
kill -SIGINT $$
|
kill -SIGINT $$
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done) &
|
done) &
|
||||||
|
|
||||||
# 脚本结束时恢复终端设置
|
# Restore terminal settings when script ends
|
||||||
trap 'stty "$old_stty_settings"' EXIT
|
trap 'stty "$old_stty_settings"' EXIT
|
||||||
|
|
||||||
|
# Print colored ASCII art
|
||||||
# 打印彩色字符画
|
echo -e "\e[1;32m" # Set color to bright green
|
||||||
echo -e "\e[1;32m" # 设置颜色为亮绿色
|
|
||||||
cat << "EOF"
|
cat << "EOF"
|
||||||
脚本作者:@Bilibili 香草味的纳西妲喵
|
Script Author: @Bilibili Vanilla Nahida Meow
|
||||||
__ __ _ _ _ _ _ _ _ _
|
__ __ _ _ _ _ _ _ _ _
|
||||||
\ \ / / (_)| || | | \ | | | | (_) | |
|
\ \ / / (_)| || | | \ | | | | (_) | |
|
||||||
\ \ / /__ _ _ __ _ | || | __ _ | \| | __ _ | |__ _ __| | __ _
|
\ \ / /__ _ _ __ _ | || | __ _ | \| | __ _ | |__ _ __| | __ _
|
||||||
|
|
@ -45,16 +44,16 @@ cat << "EOF"
|
||||||
\ /| (_| || | | || || || || (_| | | |\ || (_| || | | || || (_| || (_| |
|
\ /| (_| || | | || || || || (_| | | |\ || (_| || | | || || (_| || (_| |
|
||||||
\/ \__,_||_| |_||_||_||_| \__,_| |_| \_| \__,_||_| |_||_| \__,_| \__,_|
|
\/ \__,_||_| |_||_||_||_| \__,_| |_| \_| \__,_||_| |_||_| \__,_| \__,_|
|
||||||
EOF
|
EOF
|
||||||
echo -e "\e[0m" # 重置颜色
|
echo -e "\e[0m" # Reset color
|
||||||
echo -e "\e[1;36m 小智服务端全量部署一键安装脚本 Ver 0.2 2025年8月20日更新 \e[0m\n"
|
echo -e "\e[1;36m Xiaozhi Server Full Deployment One-Click Installation Script Ver 0.2 Updated August 20, 2025 \e[0m\n"
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 检查并安装whiptail
|
# Check and install whiptail
|
||||||
check_whiptail() {
|
check_whiptail() {
|
||||||
if ! command -v whiptail &> /dev/null; then
|
if ! command -v whiptail &> /dev/null; then
|
||||||
echo "正在安装whiptail..."
|
echo "Installing whiptail..."
|
||||||
apt update
|
apt update
|
||||||
apt install -y whiptail
|
apt install -y whiptail
|
||||||
fi
|
fi
|
||||||
|
|
@ -62,11 +61,11 @@ check_whiptail() {
|
||||||
|
|
||||||
check_whiptail
|
check_whiptail
|
||||||
|
|
||||||
# 创建确认对话框
|
# Create confirmation dialog
|
||||||
whiptail --title "安装确认" --yesno "即将安装小智服务端,是否继续?" \
|
whiptail --title "Installation Confirmation" --yesno "About to install Xiaozhi Server, continue?" \
|
||||||
--yes-button "继续" --no-button "退出" 10 50
|
--yes-button "Continue" --no-button "Exit" 10 50
|
||||||
|
|
||||||
# 根据用户选择执行操作
|
# Execute operation based on user choice
|
||||||
case $? in
|
case $? in
|
||||||
0)
|
0)
|
||||||
;;
|
;;
|
||||||
|
|
@ -75,72 +74,72 @@ case $? in
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# 检查root权限
|
# Check root permissions
|
||||||
if [ $EUID -ne 0 ]; then
|
if [ $EUID -ne 0 ]; then
|
||||||
whiptail --title "权限错误" --msgbox "请使用root权限运行本脚本" 10 50
|
whiptail --title "Permission Error" --msgbox "Please run this script with root privileges" 10 50
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 检查系统版本
|
# Check system version
|
||||||
if [ -f /etc/os-release ]; then
|
if [ -f /etc/os-release ]; then
|
||||||
. /etc/os-release
|
. /etc/os-release
|
||||||
if [ "$ID" != "debian" ] && [ "$ID" != "ubuntu" ]; then
|
if [ "$ID" != "debian" ] && [ "$ID" != "ubuntu" ]; then
|
||||||
whiptail --title "系统错误" --msgbox "该脚本只支持Debian/Ubuntu系统执行" 10 60
|
whiptail --title "System Error" --msgbox "This script only supports Debian/Ubuntu systems" 10 60
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
whiptail --title "系统错误" --msgbox "无法确定系统版本,该脚本只支持Debian/Ubuntu系统执行" 10 60
|
whiptail --title "System Error" --msgbox "Cannot determine system version, this script only supports Debian/Ubuntu systems" 10 60
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 下载配置文件函数
|
# Download configuration file function
|
||||||
check_and_download() {
|
check_and_download() {
|
||||||
local filepath=$1
|
local filepath=$1
|
||||||
local url=$2
|
local url=$2
|
||||||
if [ ! -f "$filepath" ]; then
|
if [ ! -f "$filepath" ]; then
|
||||||
if ! curl -fL --progress-bar "$url" -o "$filepath"; then
|
if ! curl -fL --progress-bar "$url" -o "$filepath"; then
|
||||||
whiptail --title "错误" --msgbox "${filepath}文件下载失败" 10 50
|
whiptail --title "Error" --msgbox "${filepath} file download failed" 10 50
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "${filepath}文件已存在,跳过下载"
|
echo "${filepath} file already exists, skipping download"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# 检查是否已安装
|
# Check if already installed
|
||||||
check_installed() {
|
check_installed() {
|
||||||
# 检查目录是否存在且非空
|
# Check if directory exists and is not empty
|
||||||
if [ -d "/opt/xiaozhi-server/" ] && [ "$(ls -A /opt/xiaozhi-server/)" ]; then
|
if [ -d "/opt/xiaozhi-server/" ] && [ "$(ls -A /opt/xiaozhi-server/)" ]; then
|
||||||
DIR_CHECK=1
|
DIR_CHECK=1
|
||||||
else
|
else
|
||||||
DIR_CHECK=0
|
DIR_CHECK=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 检查容器是否存在
|
# Check if container exists
|
||||||
if docker inspect xiaozhi-esp32-server > /dev/null 2>&1; then
|
if docker inspect xiaozhi-esp32-server > /dev/null 2>&1; then
|
||||||
CONTAINER_CHECK=1
|
CONTAINER_CHECK=1
|
||||||
else
|
else
|
||||||
CONTAINER_CHECK=0
|
CONTAINER_CHECK=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 两次检查都通过
|
# Both checks passed
|
||||||
if [ $DIR_CHECK -eq 1 ] && [ $CONTAINER_CHECK -eq 1 ]; then
|
if [ $DIR_CHECK -eq 1 ] && [ $CONTAINER_CHECK -eq 1 ]; then
|
||||||
return 0 # 已安装
|
return 0 # Already installed
|
||||||
else
|
else
|
||||||
return 1 # 未安装
|
return 1 # Not installed
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# 更新相关
|
# Update related
|
||||||
if check_installed; then
|
if check_installed; then
|
||||||
if whiptail --title "已安装检测" --yesno "检测到小智服务端已安装,是否进行升级?" 10 60; then
|
if whiptail --title "Installation Detected" --yesno "Xiaozhi server installation detected, do you want to upgrade?" 10 60; then
|
||||||
# 用户选择升级,执行清理操作
|
# User chose to upgrade, execute cleanup operations
|
||||||
echo "开始升级操作..."
|
echo "Starting upgrade operation..."
|
||||||
|
|
||||||
# 停止并移除所有docker-compose服务
|
# Stop and remove all docker-compose services
|
||||||
docker compose -f /opt/xiaozhi-server/docker-compose_all.yml down
|
docker compose -f /opt/xiaozhi-server/docker-compose_all.yml down
|
||||||
|
|
||||||
# 停止并删除特定容器(考虑容器可能不存在的情况)
|
# Stop and delete specific containers (considering containers may not exist)
|
||||||
containers=(
|
containers=(
|
||||||
"xiaozhi-esp32-server"
|
"xiaozhi-esp32-server"
|
||||||
"xiaozhi-esp32-server-web"
|
"xiaozhi-esp32-server-web"
|
||||||
|
|
@ -152,135 +151,135 @@ if check_installed; then
|
||||||
if docker ps -a --format '{{.Names}}' | grep -q "^${container}$"; then
|
if docker ps -a --format '{{.Names}}' | grep -q "^${container}$"; then
|
||||||
docker stop "$container" >/dev/null 2>&1 && \
|
docker stop "$container" >/dev/null 2>&1 && \
|
||||||
docker rm "$container" >/dev/null 2>&1 && \
|
docker rm "$container" >/dev/null 2>&1 && \
|
||||||
echo "成功移除容器: $container"
|
echo "Successfully removed container: $container"
|
||||||
else
|
else
|
||||||
echo "容器不存在,跳过: $container"
|
echo "Container does not exist, skipping: $container"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# 删除特定镜像(考虑镜像可能不存在的情况)
|
# Delete specific images (considering images may not exist)
|
||||||
images=(
|
images=(
|
||||||
"ghcr.nju.edu.cn/xinnan-tech/xiaozhi-esp32-server:server_latest"
|
"ghcr.io/lapy/xiaozhi-esp32-server:server_latest"
|
||||||
"ghcr.nju.edu.cn/xinnan-tech/xiaozhi-esp32-server:web_latest"
|
"ghcr.io/lapy/xiaozhi-esp32-server:web_latest"
|
||||||
)
|
)
|
||||||
|
|
||||||
for image in "${images[@]}"; do
|
for image in "${images[@]}"; do
|
||||||
if docker images --format '{{.Repository}}:{{.Tag}}' | grep -q "^${image}$"; then
|
if docker images --format '{{.Repository}}:{{.Tag}}' | grep -q "^${image}$"; then
|
||||||
docker rmi "$image" >/dev/null 2>&1 && \
|
docker rmi "$image" >/dev/null 2>&1 && \
|
||||||
echo "成功删除镜像: $image"
|
echo "Successfully deleted image: $image"
|
||||||
else
|
else
|
||||||
echo "镜像不存在,跳过: $image"
|
echo "Image does not exist, skipping: $image"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "所有清理操作完成"
|
echo "All cleanup operations completed"
|
||||||
|
|
||||||
# 备份原有配置文件
|
# Backup original configuration files
|
||||||
mkdir -p /opt/xiaozhi-server/backup/
|
mkdir -p /opt/xiaozhi-server/backup/
|
||||||
if [ -f /opt/xiaozhi-server/data/.config.yaml ]; then
|
if [ -f /opt/xiaozhi-server/data/.config.yaml ]; then
|
||||||
cp /opt/xiaozhi-server/data/.config.yaml /opt/xiaozhi-server/backup/.config.yaml
|
cp /opt/xiaozhi-server/data/.config.yaml /opt/xiaozhi-server/backup/.config.yaml
|
||||||
echo "已备份原有配置文件到 /opt/xiaozhi-server/backup/.config.yaml"
|
echo "Original configuration file backed up to /opt/xiaozhi-server/backup/.config.yaml"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 下载最新版配置文件
|
# Download latest configuration files
|
||||||
check_and_download "/opt/xiaozhi-server/docker-compose_all.yml" "https://ghfast.top/https://raw.githubusercontent.com/xinnan-tech/xiaozhi-esp32-server/refs/heads/main/main/xiaozhi-server/docker-compose_all.yml"
|
check_and_download "/opt/xiaozhi-server/docker-compose_all.yml" "https://raw.githubusercontent.com/lapy/xiaozhi-esp32-server/main/main/xiaozhi-server/docker-compose_all.yml"
|
||||||
check_and_download "/opt/xiaozhi-server/data/.config.yaml" "https://ghfast.top/https://raw.githubusercontent.com/xinnan-tech/xiaozhi-esp32-server/refs/heads/main/main/xiaozhi-server/config_from_api.yaml"
|
check_and_download "/opt/xiaozhi-server/data/.config.yaml" "https://raw.githubusercontent.com/lapy/xiaozhi-esp32-server/main/main/xiaozhi-server/config_from_api.yaml"
|
||||||
|
|
||||||
# 启动Docker服务
|
# Start Docker services
|
||||||
echo "开始启动最新版本服务..."
|
echo "Starting latest version services..."
|
||||||
# 升级完成后标记,跳过后续下载步骤
|
# Mark upgrade completion, skip subsequent download steps
|
||||||
UPGRADE_COMPLETED=1
|
UPGRADE_COMPLETED=1
|
||||||
docker compose -f /opt/xiaozhi-server/docker-compose_all.yml up -d
|
docker compose -f /opt/xiaozhi-server/docker-compose_all.yml up -d
|
||||||
else
|
else
|
||||||
whiptail --title "跳过升级" --msgbox "已取消升级,将继续使用当前版本。" 10 50
|
whiptail --title "Skip Upgrade" --msgbox "Upgrade cancelled, will continue using current version." 10 50
|
||||||
# 跳过升级,继续执行后续安装流程
|
# Skip upgrade, continue with subsequent installation process
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# 检查curl安装
|
# Check curl installation
|
||||||
if ! command -v curl &> /dev/null; then
|
if ! command -v curl &> /dev/null; then
|
||||||
echo "------------------------------------------------------------"
|
echo "------------------------------------------------------------"
|
||||||
echo "未检测到curl,正在安装..."
|
echo "curl not detected, installing..."
|
||||||
apt update
|
apt update
|
||||||
apt install -y curl
|
apt install -y curl
|
||||||
else
|
else
|
||||||
echo "------------------------------------------------------------"
|
echo "------------------------------------------------------------"
|
||||||
echo "curl已安装,跳过安装步骤"
|
echo "curl already installed, skipping installation step"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 检查Docker安装
|
# Check Docker installation
|
||||||
if ! command -v docker &> /dev/null; then
|
if ! command -v docker &> /dev/null; then
|
||||||
echo "------------------------------------------------------------"
|
echo "------------------------------------------------------------"
|
||||||
echo "未检测到Docker,正在安装..."
|
echo "Docker not detected, installing..."
|
||||||
|
|
||||||
# 使用国内镜像源替代官方源
|
# Use official Docker source
|
||||||
DISTRO=$(lsb_release -cs)
|
DISTRO=$(lsb_release -cs)
|
||||||
MIRROR_URL="https://mirrors.aliyun.com/docker-ce/linux/ubuntu"
|
MIRROR_URL="https://download.docker.com/linux/ubuntu"
|
||||||
GPG_URL="https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg"
|
GPG_URL="https://download.docker.com/linux/ubuntu/gpg"
|
||||||
|
|
||||||
# 安装基础依赖
|
# Install basic dependencies
|
||||||
apt update
|
apt update
|
||||||
apt install -y apt-transport-https ca-certificates curl software-properties-common gnupg
|
apt install -y apt-transport-https ca-certificates curl software-properties-common gnupg
|
||||||
|
|
||||||
# 创建密钥目录并添加国内镜像源密钥
|
# Create key directory and add domestic mirror source key
|
||||||
mkdir -p /etc/apt/keyrings
|
mkdir -p /etc/apt/keyrings
|
||||||
curl -fsSL "$GPG_URL" | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
curl -fsSL "$GPG_URL" | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||||||
|
|
||||||
# 添加国内镜像源
|
# Add domestic mirror source
|
||||||
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] $MIRROR_URL $DISTRO stable" \
|
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] $MIRROR_URL $DISTRO stable" \
|
||||||
> /etc/apt/sources.list.d/docker.list
|
> /etc/apt/sources.list.d/docker.list
|
||||||
|
|
||||||
# 添加备用官方源密钥(避免国内源密钥验证失败)
|
# Add backup official source key (avoid domestic source key verification failure)
|
||||||
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7EA0A9C3F273FCD8 2>/dev/null || \
|
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7EA0A9C3F273FCD8 2>/dev/null || \
|
||||||
echo "警告:部分密钥添加失败,继续尝试安装..."
|
echo "Warning: Some keys failed to add, continuing installation attempt..."
|
||||||
|
|
||||||
# 安装Docker
|
# Install Docker
|
||||||
apt update
|
apt update
|
||||||
apt install -y docker-ce docker-ce-cli containerd.io
|
apt install -y docker-ce docker-ce-cli containerd.io
|
||||||
|
|
||||||
# 启动服务
|
# Start services
|
||||||
systemctl start docker
|
systemctl start docker
|
||||||
systemctl enable docker
|
systemctl enable docker
|
||||||
|
|
||||||
# 检查是否安装成功
|
# Check if installation was successful
|
||||||
if docker --version; then
|
if docker --version; then
|
||||||
echo "------------------------------------------------------------"
|
echo "------------------------------------------------------------"
|
||||||
echo "Docker安装完成!"
|
echo "Docker installation completed!"
|
||||||
else
|
else
|
||||||
whiptail --title "错误" --msgbox "Docker安装失败,请检查日志。" 10 50
|
whiptail --title "Error" --msgbox "Docker installation failed, please check logs." 10 50
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "Docker已安装,跳过安装步骤"
|
echo "Docker already installed, skipping installation step"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Docker镜像源配置
|
# Docker mirror source configuration
|
||||||
MIRROR_OPTIONS=(
|
MIRROR_OPTIONS=(
|
||||||
"1" "轩辕镜像 (推荐)"
|
"1" "Docker Hub Official (Recommended)"
|
||||||
"2" "腾讯云镜像源"
|
"2" "Google Container Registry"
|
||||||
"3" "中科大镜像源"
|
"3" "Amazon ECR Public"
|
||||||
"4" "网易163镜像源"
|
"4" "Microsoft Container Registry"
|
||||||
"5" "华为云镜像源"
|
"5" "Quay.io Registry"
|
||||||
"6" "阿里云镜像源"
|
"6" "GitHub Container Registry"
|
||||||
"7" "自定义镜像源"
|
"7" "Custom Mirror Source"
|
||||||
"8" "跳过配置"
|
"8" "Skip Configuration"
|
||||||
)
|
)
|
||||||
|
|
||||||
MIRROR_CHOICE=$(whiptail --title "选择Docker镜像源" --menu "请选择要使用的Docker镜像源" 20 60 10 \
|
MIRROR_CHOICE=$(whiptail --title "Select Docker Mirror Source" --menu "Please select the Docker mirror source to use" 20 60 10 \
|
||||||
"${MIRROR_OPTIONS[@]}" 3>&1 1>&2 2>&3) || {
|
"${MIRROR_OPTIONS[@]}" 3>&1 1>&2 2>&3) || {
|
||||||
echo "用户取消选择,退出脚本"
|
echo "User cancelled selection, exiting script"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
case $MIRROR_CHOICE in
|
case $MIRROR_CHOICE in
|
||||||
1) MIRROR_URL="https://docker.xuanyuan.me" ;;
|
1) MIRROR_URL="https://registry-1.docker.io" ;;
|
||||||
2) MIRROR_URL="https://mirror.ccs.tencentyun.com" ;;
|
2) MIRROR_URL="https://gcr.io" ;;
|
||||||
3) MIRROR_URL="https://docker.mirrors.ustc.edu.cn" ;;
|
3) MIRROR_URL="https://public.ecr.aws" ;;
|
||||||
4) MIRROR_URL="https://hub-mirror.c.163.com" ;;
|
4) MIRROR_URL="https://mcr.microsoft.com" ;;
|
||||||
5) MIRROR_URL="https://05f073ad3c0010ea0f4bc00b7105ec20.mirror.swr.myhuaweicloud.com" ;;
|
5) MIRROR_URL="https://quay.io" ;;
|
||||||
6) MIRROR_URL="https://registry.aliyuncs.com" ;;
|
6) MIRROR_URL="https://ghcr.io" ;;
|
||||||
7) MIRROR_URL=$(whiptail --title "自定义镜像源" --inputbox "请输入完整的镜像源URL:" 10 60 3>&1 1>&2 2>&3) ;;
|
7) MIRROR_URL=$(whiptail --title "Custom Mirror Source" --inputbox "Please enter the complete mirror source URL:" 10 60 3>&1 1>&2 2>&3) ;;
|
||||||
8) MIRROR_URL="" ;;
|
8) MIRROR_URL="" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
@ -295,76 +294,434 @@ if [ -n "$MIRROR_URL" ]; then
|
||||||
"registry-mirrors": ["$MIRROR_URL"]
|
"registry-mirrors": ["$MIRROR_URL"]
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
whiptail --title "配置成功" --msgbox "已成功添加镜像源: $MIRROR_URL\n请按Enter键重启Docker服务并继续..." 12 60
|
whiptail --title "Configuration Success" --msgbox "Successfully added mirror source: $MIRROR_URL\nPlease press Enter to restart Docker service and continue..." 12 60
|
||||||
echo "------------------------------------------------------------"
|
echo "------------------------------------------------------------"
|
||||||
echo "开始重启Docker服务..."
|
echo "Starting Docker service restart..."
|
||||||
systemctl restart docker.service
|
systemctl restart docker.service
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 创建安装目录
|
# Create installation directory
|
||||||
echo "------------------------------------------------------------"
|
echo "------------------------------------------------------------"
|
||||||
echo "开始创建安装目录..."
|
echo "Starting to create installation directory..."
|
||||||
# 检查并创建数据目录
|
# Check and create data directory
|
||||||
if [ ! -d /opt/xiaozhi-server/data ]; then
|
if [ ! -d /opt/xiaozhi-server/data ]; then
|
||||||
mkdir -p /opt/xiaozhi-server/data
|
mkdir -p /opt/xiaozhi-server/data
|
||||||
echo "已创建数据目录: /opt/xiaozhi-server/data"
|
echo "Created data directory: /opt/xiaozhi-server/data"
|
||||||
else
|
else
|
||||||
echo "目录xiaozhi-server/data已存在,跳过创建"
|
echo "Directory xiaozhi-server/data already exists, skipping creation"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 检查并创建模型目录
|
# Check and create models directory
|
||||||
if [ ! -d /opt/xiaozhi-server/models/SenseVoiceSmall ]; then
|
if [ ! -d /opt/xiaozhi-server/models ]; then
|
||||||
mkdir -p /opt/xiaozhi-server/models/SenseVoiceSmall
|
mkdir -p /opt/xiaozhi-server/models
|
||||||
echo "已创建模型目录: /opt/xiaozhi-server/models/SenseVoiceSmall"
|
echo "Created models directory: /opt/xiaozhi-server/models"
|
||||||
else
|
else
|
||||||
echo "目录xiaozhi-server/models/SenseVoiceSmall已存在,跳过创建"
|
echo "Directory xiaozhi-server/models already exists, skipping creation"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "------------------------------------------------------------"
|
# Download and extract Vosk English model
|
||||||
echo "开始下载语音识别模型"
|
download_vosk_model() {
|
||||||
# 下载模型文件
|
echo "------------------------------------------------------------"
|
||||||
MODEL_PATH="/opt/xiaozhi-server/models/SenseVoiceSmall/model.pt"
|
echo "Checking Vosk English model..."
|
||||||
if [ ! -f "$MODEL_PATH" ]; then
|
|
||||||
(
|
VOSK_MODEL_DIR="/opt/xiaozhi-server/models/vosk"
|
||||||
for i in {1..20}; do
|
VOSK_MODEL_PATH="$VOSK_MODEL_DIR/vosk-model-en-us-0.22"
|
||||||
echo $((i*5))
|
|
||||||
sleep 0.5
|
# Check if model is already downloaded and extracted
|
||||||
|
if [ -d "$VOSK_MODEL_PATH" ] && [ -f "$VOSK_MODEL_PATH/am/final.mdl" ]; then
|
||||||
|
echo "Vosk English model already exists, skipping download"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Vosk English model not found, starting download..."
|
||||||
|
|
||||||
|
# Create vosk directory
|
||||||
|
mkdir -p "$VOSK_MODEL_DIR"
|
||||||
|
|
||||||
|
# Download the model
|
||||||
|
MODEL_URL="https://alphacephei.com/vosk/models/vosk-model-en-us-0.22.zip"
|
||||||
|
MODEL_ZIP="$VOSK_MODEL_DIR/vosk-model-en-us-0.22.zip"
|
||||||
|
|
||||||
|
echo "Downloading Vosk English model from $MODEL_URL"
|
||||||
|
echo "This may take several minutes depending on your internet connection..."
|
||||||
|
|
||||||
|
if ! curl -L --progress-bar "$MODEL_URL" -o "$MODEL_ZIP"; then
|
||||||
|
echo "Warning: Failed to download Vosk model. You can download it manually later."
|
||||||
|
echo "Visit: https://alphacephei.com/vosk/models"
|
||||||
|
echo "Download: vosk-model-en-us-0.22.zip"
|
||||||
|
echo "Extract to: $VOSK_MODEL_DIR/"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if download was successful
|
||||||
|
if [ ! -f "$MODEL_ZIP" ]; then
|
||||||
|
echo "Warning: Vosk model download failed. You can download it manually later."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Download completed, extracting model..."
|
||||||
|
|
||||||
|
# Check if unzip is available
|
||||||
|
if ! command -v unzip &> /dev/null; then
|
||||||
|
echo "Installing unzip..."
|
||||||
|
apt update
|
||||||
|
apt install -y unzip
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Extract the model
|
||||||
|
if unzip -q "$MODEL_ZIP" -d "$VOSK_MODEL_DIR/"; then
|
||||||
|
echo "Vosk model extracted successfully"
|
||||||
|
# Clean up zip file
|
||||||
|
rm "$MODEL_ZIP"
|
||||||
|
echo "Vosk English model setup completed: $VOSK_MODEL_PATH"
|
||||||
|
else
|
||||||
|
echo "Warning: Failed to extract Vosk model. You can extract it manually later."
|
||||||
|
echo "Extract $MODEL_ZIP to $VOSK_MODEL_DIR/"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Download Sherpa ONNX models function
|
||||||
|
download_sherpa_models() {
|
||||||
|
echo "------------------------------------------------------------"
|
||||||
|
echo "Checking Sherpa ONNX ASR models..."
|
||||||
|
|
||||||
|
SHERPA_BASE_DIR="/opt/xiaozhi-server/models"
|
||||||
|
SHERPA_SENSE_VOICE_DIR="$SHERPA_BASE_DIR/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17"
|
||||||
|
SHERPA_PARAFORMER_DIR="$SHERPA_BASE_DIR/sherpa-onnx-paraformer-zh-small-2024-03-09"
|
||||||
|
|
||||||
|
# Check if models are already downloaded
|
||||||
|
SENSE_VOICE_EXISTS=false
|
||||||
|
PARAFORMER_EXISTS=false
|
||||||
|
|
||||||
|
if [ -f "$SHERPA_SENSE_VOICE_DIR/model.int8.onnx" ] && [ -f "$SHERPA_SENSE_VOICE_DIR/tokens.txt" ]; then
|
||||||
|
SENSE_VOICE_EXISTS=true
|
||||||
|
echo "Sherpa ONNX Sense Voice model already exists, skipping download"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "$SHERPA_PARAFORMER_DIR/model.int8.onnx" ] && [ -f "$SHERPA_PARAFORMER_DIR/tokens.txt" ]; then
|
||||||
|
PARAFORMER_EXISTS=true
|
||||||
|
echo "Sherpa ONNX Paraformer model already exists, skipping download"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If both models exist, skip download
|
||||||
|
if [ "$SENSE_VOICE_EXISTS" = true ] && [ "$PARAFORMER_EXISTS" = true ]; then
|
||||||
|
echo "All Sherpa ONNX models already exist, skipping download"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Sherpa ONNX models not found, starting download..."
|
||||||
|
|
||||||
|
# Download Sense Voice model if needed
|
||||||
|
if [ "$SENSE_VOICE_EXISTS" = false ]; then
|
||||||
|
echo "Downloading Sherpa ONNX Sense Voice model..."
|
||||||
|
mkdir -p "$SHERPA_SENSE_VOICE_DIR"
|
||||||
|
|
||||||
|
SENSE_VOICE_URL="https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17.tar.bz2"
|
||||||
|
SENSE_VOICE_ARCHIVE="$SHERPA_SENSE_VOICE_DIR/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17.tar.bz2"
|
||||||
|
|
||||||
|
echo "Downloading from $SENSE_VOICE_URL"
|
||||||
|
echo "This may take several minutes depending on your internet connection..."
|
||||||
|
|
||||||
|
if curl -L --progress-bar "$SENSE_VOICE_URL" -o "$SENSE_VOICE_ARCHIVE"; then
|
||||||
|
echo "Download completed, extracting Sense Voice model..."
|
||||||
|
|
||||||
|
# Check if tar is available
|
||||||
|
if ! command -v tar &> /dev/null; then
|
||||||
|
echo "Installing tar..."
|
||||||
|
apt update
|
||||||
|
apt install -y tar
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Extract the model
|
||||||
|
if tar -xjf "$SENSE_VOICE_ARCHIVE" -C "$SHERPA_SENSE_VOICE_DIR/"; then
|
||||||
|
echo "Sense Voice model extracted successfully"
|
||||||
|
rm "$SENSE_VOICE_ARCHIVE"
|
||||||
|
echo "Sherpa ONNX Sense Voice model setup completed: $SHERPA_SENSE_VOICE_DIR"
|
||||||
|
else
|
||||||
|
echo "Warning: Failed to extract Sense Voice model"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Warning: Failed to download Sense Voice model"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Download Paraformer model if needed
|
||||||
|
if [ "$PARAFORMER_EXISTS" = false ]; then
|
||||||
|
echo "Downloading Sherpa ONNX Paraformer model..."
|
||||||
|
mkdir -p "$SHERPA_PARAFORMER_DIR"
|
||||||
|
|
||||||
|
PARAFORMER_URL="https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-paraformer-zh-small-2024-03-09.tar.bz2"
|
||||||
|
PARAFORMER_ARCHIVE="$SHERPA_PARAFORMER_DIR/sherpa-onnx-paraformer-zh-small-2024-03-09.tar.bz2"
|
||||||
|
|
||||||
|
echo "Downloading from $PARAFORMER_URL"
|
||||||
|
echo "This may take several minutes depending on your internet connection..."
|
||||||
|
|
||||||
|
if curl -L --progress-bar "$PARAFORMER_URL" -o "$PARAFORMER_ARCHIVE"; then
|
||||||
|
echo "Download completed, extracting Paraformer model..."
|
||||||
|
|
||||||
|
# Extract the model
|
||||||
|
if tar -xjf "$PARAFORMER_ARCHIVE" -C "$SHERPA_PARAFORMER_DIR/"; then
|
||||||
|
echo "Paraformer model extracted successfully"
|
||||||
|
rm "$PARAFORMER_ARCHIVE"
|
||||||
|
echo "Sherpa ONNX Paraformer model setup completed: $SHERPA_PARAFORMER_DIR"
|
||||||
|
else
|
||||||
|
echo "Warning: Failed to extract Paraformer model"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Warning: Failed to download Paraformer model"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "All Sherpa ONNX models downloaded successfully!"
|
||||||
|
echo "Models are now available for Docker deployment"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Download Whisper models function
|
||||||
|
download_whisper_models() {
|
||||||
|
echo "------------------------------------------------------------"
|
||||||
|
echo "Checking Whisper models..."
|
||||||
|
|
||||||
|
WHISPER_BASE_DIR="/opt/xiaozhi-server/models/whisper"
|
||||||
|
|
||||||
|
# Check if Whisper models directory exists
|
||||||
|
if [ ! -d "$WHISPER_BASE_DIR" ]; then
|
||||||
|
mkdir -p "$WHISPER_BASE_DIR"
|
||||||
|
echo "Created Whisper models directory: $WHISPER_BASE_DIR"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Define available Whisper models
|
||||||
|
WHISPER_MODELS=(
|
||||||
|
"tiny.en"
|
||||||
|
"tiny"
|
||||||
|
"base.en"
|
||||||
|
"base"
|
||||||
|
"small.en"
|
||||||
|
"small"
|
||||||
|
"medium.en"
|
||||||
|
"medium"
|
||||||
|
"large-v1"
|
||||||
|
"large-v2"
|
||||||
|
"large-v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check which models are already downloaded
|
||||||
|
EXISTING_MODELS=()
|
||||||
|
MISSING_MODELS=()
|
||||||
|
|
||||||
|
for model in "${WHISPER_MODELS[@]}"; do
|
||||||
|
MODEL_PATH="$WHISPER_BASE_DIR/$model"
|
||||||
|
if [ -d "$MODEL_PATH" ] && [ -f "$MODEL_PATH/encoder.onnx" ] || [ -f "$MODEL_PATH/encoder.pt" ]; then
|
||||||
|
EXISTING_MODELS+=("$model")
|
||||||
|
echo "Whisper model '$model' already exists, skipping download"
|
||||||
|
else
|
||||||
|
MISSING_MODELS+=("$model")
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
) | whiptail --title "下载中" --gauge "开始下载语音识别模型..." 10 60 0
|
|
||||||
curl -fL --progress-bar https://modelscope.cn/models/iic/SenseVoiceSmall/resolve/master/model.pt -o "$MODEL_PATH" || {
|
# If all models exist, skip download
|
||||||
whiptail --title "错误" --msgbox "model.pt文件下载失败" 10 50
|
if [ ${#MISSING_MODELS[@]} -eq 0 ]; then
|
||||||
exit 1
|
echo "All Whisper models already exist, skipping download"
|
||||||
}
|
return 0
|
||||||
else
|
fi
|
||||||
echo "model.pt文件已存在,跳过下载"
|
|
||||||
fi
|
echo "Whisper models not found, starting download..."
|
||||||
|
echo "Available models: ${WHISPER_MODELS[*]}"
|
||||||
|
echo "Missing models: ${MISSING_MODELS[*]}"
|
||||||
|
|
||||||
|
# Note: Whisper models are downloaded automatically by the Python whisper library
|
||||||
|
# when first used. We'll create placeholder directories and download scripts.
|
||||||
|
echo "Creating Whisper model download setup..."
|
||||||
|
|
||||||
|
# Create a Python script to download models
|
||||||
|
cat > "$WHISPER_BASE_DIR/download_models.py" << 'EOF'
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Whisper model download script
|
||||||
|
This script downloads Whisper models to the specified directory
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import whisper
|
||||||
|
import argparse
|
||||||
|
|
||||||
# 如果不是升级完成,才执行下载
|
def download_whisper_model(model_name, download_dir):
|
||||||
|
"""Download a Whisper model to the specified directory"""
|
||||||
|
try:
|
||||||
|
print(f"Downloading Whisper model: {model_name}")
|
||||||
|
|
||||||
|
# Set the cache directory for Whisper
|
||||||
|
os.environ['WHISPER_CACHE_DIR'] = download_dir
|
||||||
|
|
||||||
|
# Load the model (this will download it if not present)
|
||||||
|
model = whisper.load_model(model_name)
|
||||||
|
|
||||||
|
print(f"Successfully downloaded Whisper model: {model_name}")
|
||||||
|
return True
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed to download Whisper model {model_name}: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(description='Download Whisper models')
|
||||||
|
parser.add_argument('--model', required=True, help='Model name to download')
|
||||||
|
parser.add_argument('--dir', required=True, help='Download directory')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
success = download_whisper_model(args.model, args.dir)
|
||||||
|
sys.exit(0 if success else 1)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
EOF
|
||||||
|
|
||||||
|
chmod +x "$WHISPER_BASE_DIR/download_models.py"
|
||||||
|
|
||||||
|
# Create a shell script for easy model downloads
|
||||||
|
cat > "$WHISPER_BASE_DIR/download_all_models.sh" << 'EOF'
|
||||||
|
#!/bin/bash
|
||||||
|
# Whisper model download script
|
||||||
|
|
||||||
|
WHISPER_MODELS=(
|
||||||
|
"tiny.en"
|
||||||
|
"tiny"
|
||||||
|
"base.en"
|
||||||
|
"base"
|
||||||
|
"small.en"
|
||||||
|
"small"
|
||||||
|
"medium.en"
|
||||||
|
"medium"
|
||||||
|
"large-v1"
|
||||||
|
"large-v2"
|
||||||
|
"large-v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
DOWNLOAD_DIR="/opt/xiaozhi-server/models/whisper"
|
||||||
|
|
||||||
|
echo "Starting Whisper model downloads..."
|
||||||
|
echo "This may take a long time depending on your internet connection"
|
||||||
|
echo "Models will be downloaded to: $DOWNLOAD_DIR"
|
||||||
|
|
||||||
|
for model in "${WHISPER_MODELS[@]}"; do
|
||||||
|
echo "Downloading model: $model"
|
||||||
|
python3 "$DOWNLOAD_DIR/download_models.py" --model "$model" --dir "$DOWNLOAD_DIR"
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Successfully downloaded: $model"
|
||||||
|
else
|
||||||
|
echo "Failed to download: $model"
|
||||||
|
fi
|
||||||
|
echo "---"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Whisper model download process completed"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
chmod +x "$WHISPER_BASE_DIR/download_all_models.sh"
|
||||||
|
|
||||||
|
# Create model info file
|
||||||
|
cat > "$WHISPER_BASE_DIR/MODELS.md" << 'EOF'
|
||||||
|
# Whisper Models
|
||||||
|
|
||||||
|
This directory contains Whisper ASR models for offline speech recognition.
|
||||||
|
|
||||||
|
## Available Models
|
||||||
|
|
||||||
|
- **tiny.en** - Fastest, English only (~39 MB)
|
||||||
|
- **tiny** - Fastest, multilingual (~39 MB)
|
||||||
|
- **base.en** - Small, English only (~74 MB)
|
||||||
|
- **base** - Small, multilingual (~74 MB)
|
||||||
|
- **small.en** - Medium, English only (~244 MB)
|
||||||
|
- **small** - Medium, multilingual (~244 MB)
|
||||||
|
- **medium.en** - Large, English only (~769 MB)
|
||||||
|
- **medium** - Large, multilingual (~769 MB)
|
||||||
|
- **large-v1** - Very large, multilingual (~1550 MB)
|
||||||
|
- **large-v2** - Very large, multilingual (~1550 MB)
|
||||||
|
- **large-v3** - Very large, multilingual (~1550 MB)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Models are automatically downloaded when first used by the Whisper ASR provider.
|
||||||
|
You can also download them manually using the provided scripts:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Download a specific model
|
||||||
|
python3 /opt/xiaozhi-server/models/whisper/download_models.py --model base --dir /opt/xiaozhi-server/models/whisper
|
||||||
|
|
||||||
|
# Download all models (takes a long time)
|
||||||
|
/opt/xiaozhi-server/models/whisper/download_all_models.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
Configure Whisper models in your config.yaml:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
ASR:
|
||||||
|
WhisperASR:
|
||||||
|
type: whisper
|
||||||
|
model_name: base # Choose from available models above
|
||||||
|
device: auto # auto, cpu, cuda
|
||||||
|
language: null # null for auto-detect, or specific language code
|
||||||
|
output_dir: tmp/
|
||||||
|
```
|
||||||
|
|
||||||
|
## Performance Notes
|
||||||
|
|
||||||
|
- **tiny/tiny.en**: Fastest, lowest accuracy, good for real-time applications
|
||||||
|
- **base/base.en**: Good balance of speed and accuracy
|
||||||
|
- **small/small.en**: Better accuracy, slower than base
|
||||||
|
- **medium/medium.en**: High accuracy, significantly slower
|
||||||
|
- **large-v1/v2/v3**: Highest accuracy, slowest processing
|
||||||
|
|
||||||
|
Choose the model based on your accuracy vs speed requirements.
|
||||||
|
EOF
|
||||||
|
|
||||||
|
echo "Whisper model setup completed!"
|
||||||
|
echo "Models will be downloaded automatically when first used"
|
||||||
|
echo "Manual download scripts available in: $WHISPER_BASE_DIR"
|
||||||
|
echo "Model information available in: $WHISPER_BASE_DIR/MODELS.md"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Only download models if not upgrading
|
||||||
if [ -z "$UPGRADE_COMPLETED" ]; then
|
if [ -z "$UPGRADE_COMPLETED" ]; then
|
||||||
check_and_download "/opt/xiaozhi-server/docker-compose_all.yml" "https://ghfast.top/https://raw.githubusercontent.com/xinnan-tech/xiaozhi-esp32-server/refs/heads/main/main/xiaozhi-server/docker-compose_all.yml"
|
download_vosk_model
|
||||||
check_and_download "/opt/xiaozhi-server/data/.config.yaml" "https://ghfast.top/https://raw.githubusercontent.com/xinnan-tech/xiaozhi-esp32-server/refs/heads/main/main/xiaozhi-server/config_from_api.yaml"
|
download_sherpa_models
|
||||||
|
download_whisper_models
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 启动Docker服务
|
|
||||||
|
# Only execute download if upgrade is not completed
|
||||||
|
if [ -z "$UPGRADE_COMPLETED" ]; then
|
||||||
|
check_and_download "/opt/xiaozhi-server/docker-compose_all.yml" "https://raw.githubusercontent.com/lapy/xiaozhi-esp32-server/main/main/xiaozhi-server/docker-compose_all.yml"
|
||||||
|
check_and_download "/opt/xiaozhi-server/data/.config.yaml" "https://raw.githubusercontent.com/lapy/xiaozhi-esp32-server/main/main/xiaozhi-server/config_from_api.yaml"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Start Docker service
|
||||||
(
|
(
|
||||||
echo "------------------------------------------------------------"
|
echo "------------------------------------------------------------"
|
||||||
echo "正在拉取Docker镜像..."
|
echo "Pulling Docker images..."
|
||||||
echo "这可能需要几分钟时间,请耐心等待"
|
echo "This may take a few minutes, please be patient"
|
||||||
docker compose -f /opt/xiaozhi-server/docker-compose_all.yml up -d
|
docker compose -f /opt/xiaozhi-server/docker-compose_all.yml up -d
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
whiptail --title "错误" --msgbox "Docker服务启动失败,请尝试更换镜像源后重新执行本脚本" 10 60
|
whiptail --title "Error" --msgbox "Docker service startup failed, please try changing the image source and re-execute this script" 10 60
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "------------------------------------------------------------"
|
echo "------------------------------------------------------------"
|
||||||
echo "正在检查服务启动状态..."
|
echo "Checking service startup status..."
|
||||||
TIMEOUT=300
|
TIMEOUT=300
|
||||||
START_TIME=$(date +%s)
|
START_TIME=$(date +%s)
|
||||||
while true; do
|
while true; do
|
||||||
CURRENT_TIME=$(date +%s)
|
CURRENT_TIME=$(date +%s)
|
||||||
if [ $((CURRENT_TIME - START_TIME)) -gt $TIMEOUT ]; then
|
if [ $((CURRENT_TIME - START_TIME)) -gt $TIMEOUT ]; then
|
||||||
whiptail --title "错误" --msgbox "服务启动超时,未在指定时间内找到预期日志内容" 10 60
|
whiptail --title "Error" --msgbox "Service startup timeout, expected log content not found within specified time" 10 60
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -374,18 +731,18 @@ while true; do
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "服务端启动成功!正在完成配置..."
|
echo "Server started successfully! Completing configuration..."
|
||||||
echo "正在启动服务..."
|
echo "Starting services..."
|
||||||
docker compose -f /opt/xiaozhi-server/docker-compose_all.yml up -d
|
docker compose -f /opt/xiaozhi-server/docker-compose_all.yml up -d
|
||||||
echo "服务启动完成!"
|
echo "Service startup completed!"
|
||||||
)
|
)
|
||||||
|
|
||||||
# 密钥配置
|
# Secret key configuration
|
||||||
|
|
||||||
# 获取服务器公网地址
|
# Get server public IP address
|
||||||
PUBLIC_IP=$(hostname -I | awk '{print $1}')
|
PUBLIC_IP=$(hostname -I | awk '{print $1}')
|
||||||
whiptail --title "配置服务器密钥" --msgbox "请使用浏览器,访问下方链接,打开智控台并注册账号: \n\n内网地址:http://127.0.0.1:8002/\n公网地址:http://$PUBLIC_IP:8002/ (若是云服务器请在服务器安全组放行端口 8000 8001 8002)。\n\n注册的第一个用户即是超级管理员,以后注册的用户都是普通用户。普通用户只能绑定设备和配置智能体; 超级管理员可以进行模型管理、用户管理、参数配置等功能。\n\n注册好后请按Enter键继续" 18 70
|
whiptail --title "Configure Server Secret Key" --msgbox "Please use a browser to access the following link, open the Smart Control Panel and register an account: \n\nInternal address: http://127.0.0.1:8002/\nPublic address: http://$PUBLIC_IP:8002/ (If it's a cloud server, please open ports 8000 8001 8002 in the server security group).\n\nThe first registered user is the super administrator, and subsequent users are ordinary users. Ordinary users can only bind devices and configure intelligent agents; super administrators can perform model management, user management, parameter configuration and other functions.\n\nAfter registration, please press Enter to continue" 18 70
|
||||||
SECRET_KEY=$(whiptail --title "配置服务器密钥" --inputbox "请使用超级管理员账号登录智控台\n内网地址:http://127.0.0.1:8002/\n公网地址:http://$PUBLIC_IP:8002/\n在顶部菜单 参数字典 → 参数管理 找到参数编码: server.secret (服务器密钥) \n复制该参数值并输入到下面输入框\n\n请输入密钥(留空则跳过配置):" 15 60 3>&1 1>&2 2>&3)
|
SECRET_KEY=$(whiptail --title "Configure Server Secret Key" --inputbox "Please use the super administrator account to log into the Smart Control Panel\nInternal address: http://127.0.0.1:8002/\nPublic address: http://$PUBLIC_IP:8002/\nIn the top menu Parameter Dictionary → Parameter Management, find parameter code: server.secret (Server Secret Key) \nCopy the parameter value and enter it in the input box below\n\nPlease enter the secret key (leave empty to skip configuration):" 15 60 3>&1 1>&2 2>&3)
|
||||||
|
|
||||||
if [ -n "$SECRET_KEY" ]; then
|
if [ -n "$SECRET_KEY" ]; then
|
||||||
python3 -c "
|
python3 -c "
|
||||||
|
|
@ -400,14 +757,14 @@ with open(config_path, 'w') as f:
|
||||||
docker restart xiaozhi-esp32-server
|
docker restart xiaozhi-esp32-server
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 获取并显示地址信息
|
# Get and display address information
|
||||||
LOCAL_IP=$(hostname -I | awk '{print $1}')
|
LOCAL_IP=$(hostname -I | awk '{print $1}')
|
||||||
|
|
||||||
# 修复日志文件获取不到ws的问题,改为硬编码
|
# Fix log file unable to get ws issue, change to hardcode
|
||||||
whiptail --title "安装完成!" --msgbox "\
|
whiptail --title "Installation Complete!" --msgbox "\
|
||||||
服务端相关地址如下:\n\
|
Server related addresses are as follows:\n\
|
||||||
管理后台访问地址: http://$LOCAL_IP:8002\n\
|
Management backend access address: http://$LOCAL_IP:8002\n\
|
||||||
OTA 地址: http://$LOCAL_IP:8002/xiaozhi/ota/\n\
|
OTA address: http://$LOCAL_IP:8003/xiaozhi/ota/\n\
|
||||||
视觉分析接口地址: http://$LOCAL_IP:8003/mcp/vision/explain\n\
|
Vision analysis interface address: http://$LOCAL_IP:8003/mcp/vision/explain\n\
|
||||||
WebSocket 地址: ws://$LOCAL_IP:8000/xiaozhi/v1/\n\
|
WebSocket address: ws://$LOCAL_IP:8000/xiaozhi/v1/\n\
|
||||||
\n安装完毕!感谢您的使用!\n按Enter键退出..." 16 70
|
\nInstallation complete! Thank you for using!\nPress Enter to exit..." 16 70
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue