diff --git a/docker-setup.sh b/docker-setup.sh index 8b2f12741..1e3ddd04d 100755 --- a/docker-setup.sh +++ b/docker-setup.sh @@ -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 <&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 \ No newline at end of file