update setup

This commit is contained in:
Alireza Jahanshahlou 2025-11-15 13:06:57 +03:30
parent 4ebb4bc410
commit ac41a25192

View file

@ -1,43 +1,43 @@
#!/bin/sh
# 脚本作者@VanillaNahida
# 本文件是用于一键自动下载本项目所需文件,自动创建好目录
# 暂且只支持X86版本的Ubuntu系统,其他系统未测试
# Script author @VanillaNahida
This file is for automatically downloading the files required for this project with one click and automatically creating the directory.
# Currently only supports x86 versions of Ubuntu; other systems have not been tested.
# 定义中断处理函数
# Define interrupt handler function
handle_interrupt() {
echo ""
echo "安装已被用户中断(Ctrl+C或Esc)"
echo "如需重新安装,请再次运行脚本"
echo "Installation was interrupted by the user (Ctrl+C or Esc)"
echo "To reinstall, please run the script again."
exit 1
}
# 设置信号捕获,处理Ctrl+C
# Configure signal capture, handle Ctrl+C
trap handle_interrupt SIGINT
# 处理Esc键
# 保存终端设置
# Handling the Esc key
# Save terminal settings
old_stty_settings=$(stty -g)
# 设置终端立即响应,不回显
# Configure the terminal to respond immediately without echoing.
stty -icanon -echo min 1 time 0
# 后台进程检测Esc键
# Background process detection using the Esc key
(while true; do
read -r key
if [[ $key == $'\e' ]]; then
# 检测到Esc键,触发中断处理
# Esc key detected, interrupt handling triggered
kill -SIGINT $$
break
fi
be
done) &
# 脚本结束时恢复终端设置
# Restore terminal settings when the script ends
trap 'stty "$old_stty_settings"' EXIT
# 打印彩色字符画
echo -e "\e[1;32m" # 设置颜色为亮绿色
# Print Color Character Artwork
echo -e "\e[1;32m" # Set the color to bright green
cat << "EOF"
脚本作者:@Bilibili 香草味的纳西妲喵
Script author: @Bilibili Vanilla-flavored Naxi Da Miao
__ __ _ _ _ _ _ _ _ _
\ \ / / (_)| || | | \ | | | | (_) | |
\ \ / /__ _ _ __ _ | || | __ _ | \| | __ _ | |__ _ __| | __ _
@ -45,28 +45,28 @@ cat << "EOF"
\ /| (_| || | | || || || || (_| | | |\ || (_| || | | || || (_| || (_| |
\/ \__,_||_| |_||_||_||_| \__,_| |_| \_| \__,_||_| |_||_| \__,_| \__,_|
EOF
echo -e "\e[0m" # 重置颜色
echo -e "\e[1;36m 小智服务端全量部署一键安装脚本 Ver 0.2 2025年8月20日更新 \e[0m\n"
echo -e "\e[0m" # Reset colors
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
# 检查并安装whiptail
# Check and install whiptail
check_whiptail() {
if ! command -v whiptail &> /dev/null; then
echo "正在安装whiptail..."
echo "Installing whiptail..."
apt update
apt install -y whiptail
fi
be
}
check_whiptail
# 创建确认对话框
whiptail --title "安装确认" --yesno "即将安装小智服务端,是否继续?" \
--yes-button "继续" --no-button "退出" 10 50
# Create a confirmation dialog box
whiptail --title "Installation Confirmed" --yesno "Xiaozhi server is about to be installed, continue?"
--yes-button "Continue" --no-button "Exit" 10 50
# 根据用户选择执行操作
# Perform the operation based on the user's selection.
case $? in
0)
;;
@ -75,76 +75,76 @@ case $? in
;;
esac
# 检查root权限
# Check root privileges
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
fi
be
# 检查系统版本
# Check system version
if [ -f /etc/os-release ]; then
. /etc/os-release
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
fi
be
else
whiptail --title "系统错误" --msgbox "无法确定系统版本,该脚本只支持Debian/Ubuntu系统执行" 10 60
whiptail --title "System Error" --msgbox "Unable to determine system version. This script only supports Debian/Ubuntu systems" 10 60
exit 1
fi
be
# 下载配置文件函数
# Download configuration file function
check_and_download() {
local filepath=$1
local url=$2
if [ ! -f "$filepath" ]; then
if ! curl -fL --progress-bar "$url" -o "$filepath"; then
whiptail --title "错误" --msgbox "${filepath}文件下载失败" 10 50
whiptail --title "Error" --msgbox "Download of file ${filepath} failed" 10 50
exit 1
fi
be
else
echo "${filepath}文件已存在,跳过下载"
fi
echo "The file ${filepath} already exists; skip downloading."
be
}
# 检查是否已安装
# Check if it is installed
check_installed() {
# 检查目录是否存在且非空
# Check if the directory exists and is not empty
if [ -d "/opt/xiaozhi-server/" ] && [ "$(ls -A /opt/xiaozhi-server/)" ]; then
DIR_CHECK=1
else
DIR_CHECK=0
fi
be
# 检查容器是否存在
# Check if the container exists
if docker inspect xiaozhi-esp32-server > /dev/null 2>&1; then
CONTAINER_CHECK=1
else
CONTAINER_CHECK=0
fi
be
# 两次检查都通过
# Both checks passed
if [ $DIR_CHECK -eq 1 ] && [ $CONTAINER_CHECK -eq 1 ]; then
return 0 # 已安装
return 0 # Installed
else
return 1 # 未安装
fi
return 1 # Not installed
be
}
# 更新相关
# Update related
if check_installed; then
if whiptail --title "已安装检测" --yesno "检测到小智服务端已安装,是否进行升级?" 10 60; then
# 用户选择升级,执行清理操作
echo "开始升级操作..."
If whiptail --title "Installation Detection" --yesno "Xiaozhi server detected, upgrade?" 10 60; then
# The user selects to upgrade and performs a cleanup operation.
echo "Initiating upgrade operation..."
# 停止并移除所有docker-compose服务
# Stop and remove all docker-compose services
docker compose -f /opt/xiaozhi-server/docker-compose_all.yml down
# 停止并删除特定容器(考虑容器可能不存在的情况)
# Stop and delete a specific container (considering the possibility that the container may not exist).
containers=(
"xiaozhi-esp32-server"
"xiaozhi-esp32-server-web"
"xiaozhi-esp32-server-db"
"xiaozhi-esp32-server-db
"xiaozhi-esp32-server-redis"
)
@ -152,13 +152,13 @@ if check_installed; then
if docker ps -a --format '{{.Names}}' | grep -q "^${container}$"; then
docker stop "$container" >/dev/null 2>&1 && \
docker rm "$container" >/dev/null 2>&1 && \
echo "成功移除容器: $container"
echo "Container successfully removed: $container"
else
echo "容器不存在,跳过: $container"
fi
echo "Container does not exist, skip: $container"
be
done
# 删除特定镜像(考虑镜像可能不存在的情况)
# Delete a specific image (considering the possibility that the image may not exist).
images=(
"ghcr.nju.edu.cn/xinnan-tech/xiaozhi-esp32-server:server_latest"
"ghcr.nju.edu.cn/xinnan-tech/xiaozhi-esp32-server:web_latest"
@ -167,109 +167,109 @@ if check_installed; then
for image in "${images[@]}"; do
if docker images --format '{{.Repository}}:{{.Tag}}' | grep -q "^${image}$"; then
docker rmi "$image" >/dev/null 2>&1 && \
echo "成功删除镜像: $image"
echo "Mirror image successfully deleted: $image"
else
echo "镜像不存在,跳过: $image"
fi
echo "Image does not exist, skip: $image"
be
done
echo "所有清理操作完成"
echo "All cleanup operations completed"
# 备份原有配置文件
# Backup existing configuration files
mkdir -p /opt/xiaozhi-server/backup/
if [ -f /opt/xiaozhi-server/data/.config.yaml ]; then
cp /opt/xiaozhi-server/data/.config.yaml /opt/xiaozhi-server/backup/.config.yaml
echo "已备份原有配置文件到 /opt/xiaozhi-server/backup/.config.yaml"
fi
echo "The original configuration file has been backed up to /opt/xiaozhi-server/backup/.config.yaml"
be
# 下载最新版配置文件
# Download the latest configuration file
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/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"
# 启动Docker服务
echo "开始启动最新版本服务..."
# 升级完成后标记,跳过后续下载步骤
# Start Docker service
echo "Starting the latest version service..."
# Mark the page after the upgrade is complete to skip subsequent download steps.
UPGRADE_COMPLETED=1
docker compose -f /opt/xiaozhi-server/docker-compose_all.yml up -d
else
whiptail --title "跳过升级" --msgbox "已取消升级,将继续使用当前版本。" 10 50
# 跳过升级,继续执行后续安装流程
fi
fi
whiptail --title "Skip upgrade" --msgbox "Upgrade canceled, will continue using the current version." 10 50
# Skip the upgrade and continue with the subsequent installation process.
be
be
# 检查curl安装
# Check curl installation
if ! command -v curl &> /dev/null; then
echo "------------------------------------------------------------"
echo "未检测到curl,正在安装..."
echo "curl not detected, installing..."
apt update
apt install -y curl
else
echo "------------------------------------------------------------"
echo "curl已安装,跳过安装步骤"
fi
echo "curl is already installed, skip the installation steps"
be
# 检查Docker安装
# Check Docker installation
if ! command -v docker &> /dev/null; then
echo "------------------------------------------------------------"
echo "未检测到Docker,正在安装..."
echo "Docker not detected, installing..."
# 使用国内镜像源替代官方源
# Use a domestic mirror source instead of the official source
DISTRO=$(lsb_release -cs)
MIRROR_URL="https://mirrors.aliyun.com/docker-ce/linux/ubuntu"
GPG_URL="https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg"
# 安装基础依赖
# Install basic dependencies
apt update
apt install -y apt-transport-https ca-certificates curl software-properties-common gnupg
# 创建密钥目录并添加国内镜像源密钥
# Create a key directory and add domestic mirror source keys
mkdir -p /etc/apt/keyrings
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" \
> /etc/apt/sources.list.d/docker.list
# 添加备用官方源密钥(避免国内源密钥验证失败)
# Add a backup official source key (to avoid verification failures using domestic source keys)
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7EA0A9C3F273FCD8 2>/dev/null || \
echo "警告:部分密钥添加失败,继续尝试安装..."
echo "Warning: Partial key addition failed, continue trying to install..."
# 安装Docker
# Install Docker
apt update
apt install -y docker-ce docker-ce-cli containerd.io
# 启动服务
# Start service
systemctl start docker
systemctl enable docker
# 检查是否安装成功
# Check if the installation was successful
if docker --version; then
echo "------------------------------------------------------------"
echo "Docker安装完成!"
echo "Docker installation complete!"
else
whiptail --title "错误" --msgbox "Docker安装失败,请检查日志。" 10 50
whiptail --title "Error" --msgbox "Docker installation failed, please check the logs." 10 50
exit 1
fi
be
else
echo "Docker已安装,跳过安装步骤"
fi
echo "Docker is already installed, skip the installation steps"
be
# Docker镜像源配置
# Docker image source configuration
MIRROR_OPTIONS=(
"1" "轩辕镜像 (推荐)"
"2" "腾讯云镜像源"
"3" "中科大镜像源"
"4" "网易163镜像源"
"5" "华为云镜像源"
"6" "阿里云镜像源"
"7" "自定义镜像源"
"8" "跳过配置"
"1" "Xuanyuan Mirror (Recommended)"
"2" "Tencent Cloud Mirror Source"
"3" "USTC Mirror Source"
"4" "NetEase 163 Mirror Source"
"5" "Huawei Cloud Mirror Source"
"6" "Alibaba Cloud Mirror Source"
"7" "Custom Mirror Source"
"8" "Skip Configuration"
)
MIRROR_CHOICE=$(whiptail --title "选择Docker镜像源" --menu "请选择要使用的Docker镜像源" 20 60 10 \
MIRROR_CHOICE=$(whiptail --title "Select Docker image source" --menu "Please select the Docker image source to use" 20 60 10 \
"${MIRROR_OPTIONS[@]}" 3>&1 1>&2 2>&3) || {
echo "用户取消选择,退出脚本"
echo "User canceled selection, exit script"
exit 1
}
@ -280,7 +280,7 @@ case $MIRROR_CHOICE in
4) MIRROR_URL="https://hub-mirror.c.163.com" ;;
5) MIRROR_URL="https://05f073ad3c0010ea0f4bc00b7105ec20.mirror.swr.myhuaweicloud.com" ;;
6) MIRROR_URL="https://registry.aliyuncs.com" ;;
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="" ;;
esac
@ -288,41 +288,41 @@ if [ -n "$MIRROR_URL" ]; then
mkdir -p /etc/docker
if [ -f /etc/docker/daemon.json ]; then
cp /etc/docker/daemon.json /etc/docker/daemon.json.bak
fi
be
cat > /etc/docker/daemon.json <<EOF
{
"dns": ["8.8.8.8", "114.114.114.114"],
"registry-mirrors": ["$MIRROR_URL"]
}
EOF
whiptail --title "配置成功" --msgbox "已成功添加镜像源: $MIRROR_URL\n请按Enter键重启Docker服务并继续..." 12 60
whiptail --title "Configuration successful" --msgbox "Image source added successfully: $MIRROR_URL\nPlease press Enter to restart the Docker service and continue..." 12 60
echo "------------------------------------------------------------"
echo "开始重启Docker服务..."
echo "Starting to restart Docker service..."
systemctl restart docker.service
fi
be
# 创建安装目录
# Create installation directory
echo "------------------------------------------------------------"
echo "开始创建安装目录..."
# 检查并创建数据目录
echo "Starting to create installation directory..."
# Check and create the data directory
if [ ! -d /opt/xiaozhi-server/data ]; then
mkdir -p /opt/xiaozhi-server/data
echo "已创建数据目录: /opt/xiaozhi-server/data"
echo "Data directory created: /opt/xiaozhi-server/data"
else
echo "目录xiaozhi-server/data已存在,跳过创建"
fi
echo "Directory xiaozhi-server/data already exists, skip creation"
be
# 检查并创建模型目录
# Check and create the model catalog
if [ ! -d /opt/xiaozhi-server/models/SenseVoiceSmall ]; then
mkdir -p /opt/xiaozhi-server/models/SenseVoiceSmall
echo "已创建模型目录: /opt/xiaozhi-server/models/SenseVoiceSmall"
echo "Model directory created: /opt/xiaozhi-server/models/SenseVoiceSmall"
else
echo "目录xiaozhi-server/models/SenseVoiceSmall已存在,跳过创建"
fi
echo "Directory xiaozhi-server/models/SenseVoiceSmall already exists, skipping creation"
be
echo "------------------------------------------------------------"
echo "开始下载语音识别模型"
# 下载模型文件
echo "Start downloading speech recognition model"
# Download model file
MODEL_PATH="/opt/xiaozhi-server/models/SenseVoiceSmall/model.pt"
if [ ! -f "$MODEL_PATH" ]; then
(
@ -330,62 +330,62 @@ if [ ! -f "$MODEL_PATH" ]; then
echo $((i*5))
sleep 0.5
done
) | whiptail --title "下载中" --gauge "开始下载语音识别模型..." 10 60 0
) | whiptail --title "Downloading" --gauge "Starting to download speech recognition model..." 10 60 0
curl -fL --progress-bar https://modelscope.cn/models/iic/SenseVoiceSmall/resolve/master/model.pt -o "$MODEL_PATH" || {
whiptail --title "错误" --msgbox "model.pt文件下载失败" 10 50
whiptail --title "Error" --msgbox "Failed to download model.pt file" 10 50
exit 1
}
else
echo "model.pt文件已存在,跳过下载"
fi
echo "model.pt file already exists, skip downloading"
be
# 如果不是升级完成,才执行下载
# Download will only proceed if the upgrade is not complete.
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"
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"
fi
be
# 启动Docker服务
# Start Docker service
(
echo "------------------------------------------------------------"
echo "正在拉取Docker镜像..."
echo "这可能需要几分钟时间,请耐心等待"
echo "Pulling Docker image..."
This may take a few minutes, please wait patiently.
docker compose -f /opt/xiaozhi-server/docker-compose_all.yml up -d
if [ $? -ne 0 ]; then
whiptail --title "错误" --msgbox "Docker服务启动失败,请尝试更换镜像源后重新执行本脚本" 10 60
whiptail --title "Error" --msgbox "Docker service failed to start. Please try changing the image source and re-execute this script." 10 60
exit 1
fi
be
echo "------------------------------------------------------------"
echo "正在检查服务启动状态..."
echo "Checking service startup status..."
TIMEOUT=300
START_TIME=$(date +%s)
while true; do
CURRENT_TIME=$(date +%s)
if [ $((CURRENT_TIME - START_TIME)) -gt $TIMEOUT ]; then
whiptail --title "错误" --msgbox "服务启动超时,未在指定时间内找到预期日志内容" 10 60
whiptail --title "Error" --msgbox "Service startup timed out, expected log content not found within the specified time" 10 60
exit 1
fi
be
if docker logs xiaozhi-esp32-server-web 2>&1 | grep -q "Started AdminApplication in"; then
break
fi
be
sleep 1
done
echo "服务端启动成功!正在完成配置..."
echo "正在启动服务..."
echo "Server started successfully! Completing configuration..."
echo "Starting service..."
docker compose -f /opt/xiaozhi-server/docker-compose_all.yml up -d
echo "服务启动完成!"
echo "Service startup complete!"
)
# 密钥配置
# Key Configuration
# 获取服务器公网地址
# Get the server's public IP address
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
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)
whiptail --title "Configure Server Key" --msgbox "Please use a browser to access the link below, open the smart console, and register an account:\n\nInternal network address: http://127.0.0.1:8002/\nPublic network address: http://$PUBLIC_IP:8002/ (If it is a cloud server, please allow ports 8000, 8001, and 8002 in the server security group).\n\nThe first user registered is the super administrator; subsequent users are ordinary users. Ordinary users can only bind devices and configure smart agents; super administrators can perform model management, user management, parameter configuration, and other functions.\n\nPlease press Enter to continue after registration." 18 70
SECRET_KEY=$(whiptail --title "Configure Server Key" --inputbox "Please log in to the smart console using the super administrator account\nInternal network address: http://127.0.0.1:8002/\nPublic network address: http://$PUBLIC_IP:8002/\nFind the parameter code: server.secret (server key) in the top menu Parameter Dictionary → Parameter Management\nCopy this parameter value and enter it into the input box below\n\nPlease enter the key (leave blank to skip configuration):" 15 60 3>&1 1>&2 2>&3)
if [ -n "$SECRET_KEY" ]; then
python3 -c "
@ -398,16 +398,16 @@ with open(config_path, 'w') as f:
yaml.dump(config, f);
"
docker restart xiaozhi-esp32-server
fi
be
# 获取并显示地址信息
# Get and display address information
LOCAL_IP=$(hostname -I | awk '{print $1}')
# 修复日志文件获取不到ws的问题,改为硬编码
whiptail --title "安装完成!" --msgbox "\
服务端相关地址如下:\n\
管理后台访问地址: http://$LOCAL_IP:8002\n\
OTA 地址: http://$LOCAL_IP:8002/xiaozhi/ota/\n\
视觉分析接口地址: http://$LOCAL_IP:8003/mcp/vision/explain\n\
WebSocket 地址: ws://$LOCAL_IP:8000/xiaozhi/v1/\n\
\n安装完毕!感谢您的使用!\n按Enter键退出..." 16 70
# Fixed the issue of not being able to retrieve the ws file from the log file; changed it to hard encoding.
whiptail --title "Installation complete!" --msgbox "\
The server-side address is as follows:\n\
Admin panel access address: http://$LOCAL_IP:8002\n\
OTA Location: http://$LOCAL_IP:8002/xiaozhi/ota/\n\
Visual analytics interface address: http://$LOCAL_IP:8003/mcp/vision/explain\n\
WebSocket address: ws://$LOCAL_IP:8000/xiaozhi/v1/\n\
Installation complete! Thank you for using our service! Press Enter to exit... 16 70