From f62e79523a97bbd11986339ca379fbaac2aee88e Mon Sep 17 00:00:00 2001 From: Cookie987 Date: Wed, 12 Mar 2025 22:38:40 +0800 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20Linux=20=E4=B8=80=E9=94=AE=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1key_install_linux.sh | 183 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 1key_install_linux.sh diff --git a/1key_install_linux.sh b/1key_install_linux.sh new file mode 100644 index 000000000..dd9903716 --- /dev/null +++ b/1key_install_linux.sh @@ -0,0 +1,183 @@ +#!/bin/bash + +# Maimbot 一键安装脚本 by Cookie987 +# 适用于Debian系 +# 请小心使用任何一键脚本! + +# 如无法访问GitHub请修改此处镜像地址 +GITHUB_REPO="https://ghfast.top/https://github.com/SengokuCola/MaiMBot.git" + +# 颜色输出 +GREEN="\e[32m" +RED="\e[31m" +RESET="\e[0m" + +# 需要的基本软件包 +REQUIRED_PACKAGES=("git" "sudo" "python3" "python3-venv" "python3-pip") + +# 默认项目目录 +DEFAULT_INSTALL_DIR="/opt/maimbot" + +# 服务名称 +SERVICE_NAME="maimbot" + +# 1/6: 检测是否安装 whiptail +if ! command -v whiptail &>/dev/null; then + echo -e "${RED}[1/6] whiptail 未安装,正在安装...${RESET}" + apt update && apt install -y whiptail +fi + +get_os_info() { + if command -v lsb_release &>/dev/null; then + OS_INFO=$(lsb_release -d | cut -f2) + elif [[ -f /etc/os-release ]]; then + OS_INFO=$(grep "^PRETTY_NAME=" /etc/os-release | cut -d '"' -f2) + else + OS_INFO="Unknown OS" + fi + echo "$OS_INFO" +} + +check_system() { + OS_NAME=$(get_os_info) + whiptail --title "⚙️ [2/6] 检查系统" --yesno "本脚本仅支持Debian 12。\n当前系统为 $OS_NAME\n是否继续?" 10 60 || exit 1 +} +# 3/6: 询问用户是否安装缺失的软件包 +install_packages() { + missing_packages=() + for package in "${REQUIRED_PACKAGES[@]}"; do + if ! dpkg -s "$package" &>/dev/null; then + missing_packages+=("$package") + fi + done + + if [[ ${#missing_packages[@]} -gt 0 ]]; then + whiptail --title "📦 [3/6] 软件包检查" --yesno "检测到以下软件包缺失(MongoDB除外):\n${missing_packages[*]}\n\n是否要自动安装?" 12 60 + if [[ $? -eq 0 ]]; then + break + else + whiptail --title "⚠️ 注意" --yesno "某些必要的软件包未安装,可能会影响运行!\n是否继续?" 10 60 || exit 1 + fi + fi +} + +# 4/6: Python 版本检查 +check_python() { + PYTHON_VERSION=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")') + + python3 -c "import sys; exit(0) if sys.version_info >= (3,9) else exit(1)" + if [[ $? -ne 0 ]]; then + whiptail --title "⚠️ [4/6] Python 版本过低" --msgbox "检测到 Python 版本为 $PYTHON_VERSION,需要 3.9 或以上!\n请升级 Python 后重新运行本脚本。" 10 60 + exit 1 + fi +} + +# 5/6: 选择分支 +choose_branch() { + BRANCH=$(whiptail --title "🔀 [5/6] 选择 Maimbot 分支" --menu "请选择要安装的 Maimbot 分支:" 15 60 2 \ + "main" "稳定版本(推荐)" \ + "debug" "开发版本(可能不稳定)" 3>&1 1>&2 2>&3) + + if [[ -z "$BRANCH" ]]; then + BRANCH="main" + whiptail --title "🔀 默认选择" --msgbox "未选择分支,默认安装稳定版本(main)" 10 60 + fi +} + +# 6/6: 选择安装路径 +choose_install_dir() { + INSTALL_DIR=$(whiptail --title "📂 [6/6] 选择安装路径" --inputbox "请输入 Maimbot 的安装目录:" 10 60 "$DEFAULT_INSTALL_DIR" 3>&1 1>&2 2>&3) + + if [[ -z "$INSTALL_DIR" ]]; then + whiptail --title "⚠️ 取消输入" --yesno "未输入安装路径,是否退出安装?" 10 60 + if [[ $? -ne 0 ]]; then + INSTALL_DIR="$DEFAULT_INSTALL_DIR" + else + exit 1 + fi + fi +} + +# 显示确认界面 +confirm_install() { + local confirm_message="请确认以下更改:\n\n" + + if [[ ${#missing_packages[@]} -gt 0 ]]; then + confirm_message+="📦 安装缺失的依赖项: ${missing_packages[*]}\n" + else + confirm_message+="✅ 所有依赖项已安装,无需额外安装\n" + fi + + confirm_message+="📂 安装目录: $INSTALL_DIR\n" + confirm_message+="🔀 分支: $BRANCH\n" + + if dpkg -s mongodb-org &>/dev/null; then + confirm_message+="✅ MongoDB 已安装\n" + else + confirm_message+="⚠️ MongoDB 可能未安装(请参阅官方文档安装)\n" + fi + + confirm_message+="🛠️ 添加 Maimbot 作为系统服务 ($SERVICE_NAME.service)\n" + + confitm_message+="\n\n注意:本脚本使用GitHub,如无法访问请手动修改仓库地址。" + whiptail --title "🔧 安装确认" --yesno "$confirm_message\n\n是否继续安装?" 15 60 + if [[ $? -ne 0 ]]; then + whiptail --title "🚫 取消安装" --msgbox "安装已取消。" 10 60 + exit 1 + fi +} + +# 运行安装步骤 +check_system +install_packages +check_python +choose_branch +choose_install_dir +confirm_install + +# 开始安装 +whiptail --title "🚀 开始安装" --msgbox "所有环境检查完毕,即将开始安装 Maimbot!" 10 60 + +echo -e "${GREEN}安装依赖项...${RESET}" + +apt update && apt install -y "${missing_packages[@]}" + +echo -e "${GREEN}创建 Python 虚拟环境...${RESET}" +mkdir -p "$INSTALL_DIR" +cd "$INSTALL_DIR" || exit +python3 -m venv venv +source venv/bin/activate + +echo -e "${GREEN}克隆仓库...${RESET}" +# 安装 Maimbot +mkdir -p "$INSTALL_DIR/repo" +cd "$INSTALL_DIR/repo" || exit 1 +git clone -b "$BRANCH" $GITHUB_REPO . + +echo -e "${GREEN}安装 Python 依赖...${RESET}" +pip install -r requirements.txt + +echo -e "${GREEN}设置服务...${RESET}" +# 设置 Maimbot 服务 +cat < Date: Wed, 12 Mar 2025 22:40:22 +0800 Subject: [PATCH 2/8] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c14ac646e..964c69e22 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ - 📦 **Windows 一键傻瓜式部署**:请运行项目根目录中的 `run.bat`,部署完成后请参照后续配置指南进行配置 +- [📦 Linux 自动部署(实验) ](请在项目根目录中运行 `bash 1key_install_linux.sh`并安装提示安装,部署完成后请参照后续配置指南进行配置) - [📦 Windows 手动部署指南 ](docs/manual_deploy_windows.md) From 466ce4c45d331cd297f007e877969fbc4cfb27cc Mon Sep 17 00:00:00 2001 From: Cookie987 Date: Wed, 12 Mar 2025 22:41:15 +0800 Subject: [PATCH 3/8] =?UTF-8?q?feat:=20Linux=E4=B8=80=E9=94=AE=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 964c69e22..92fcdc318 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ - 📦 **Windows 一键傻瓜式部署**:请运行项目根目录中的 `run.bat`,部署完成后请参照后续配置指南进行配置 -- [📦 Linux 自动部署(实验) ](请在项目根目录中运行 `bash 1key_install_linux.sh`并安装提示安装,部署完成后请参照后续配置指南进行配置) +- 📦 Linux 自动部署(实验) :请在项目根目录中运行 `bash 1key_install_linux.sh`并按照提示安装,部署完成后请参照后续配置指南进行配置 - [📦 Windows 手动部署指南 ](docs/manual_deploy_windows.md) From 1db47d24680c7f8b4e38faa854d7d4beb744d3fb Mon Sep 17 00:00:00 2001 From: Cookie987 Date: Wed, 12 Mar 2025 22:42:22 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E6=8E=92=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/manual_deploy_linux.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/manual_deploy_linux.md b/docs/manual_deploy_linux.md index b19f3d6a7..a5c91d6e2 100644 --- a/docs/manual_deploy_linux.md +++ b/docs/manual_deploy_linux.md @@ -121,6 +121,7 @@ sudo nano /etc/systemd/system/maimbot.service 输入以下内容: ``:你的maimbot目录 + ``:你的venv环境(就是上文创建环境后,执行的代码`source maimbot/bin/activate`中source后面的路径的绝对路径) ```ini From 5399aca0d3f503d4e542846506830d369ad8a0e6 Mon Sep 17 00:00:00 2001 From: Cookie987 Date: Wed, 12 Mar 2025 22:46:00 +0800 Subject: [PATCH 5/8] Update and rename 1key_install_linux.sh to run.sh --- 1key_install_linux.sh => run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename 1key_install_linux.sh => run.sh (97%) diff --git a/1key_install_linux.sh b/run.sh similarity index 97% rename from 1key_install_linux.sh rename to run.sh index dd9903716..c616edcfb 100644 --- a/1key_install_linux.sh +++ b/run.sh @@ -5,7 +5,7 @@ # 请小心使用任何一键脚本! # 如无法访问GitHub请修改此处镜像地址 -GITHUB_REPO="https://ghfast.top/https://github.com/SengokuCola/MaiMBot.git" +GITHUB_REPO="https://github.com/SengokuCola/MaiMBot.git" # 颜色输出 GREEN="\e[32m" @@ -119,7 +119,7 @@ confirm_install() { confirm_message+="🛠️ 添加 Maimbot 作为系统服务 ($SERVICE_NAME.service)\n" - confitm_message+="\n\n注意:本脚本使用GitHub,如无法访问请手动修改仓库地址。" + confirm_message+="\n\n注意:本脚本使用GitHub,如无法访问请手动修改仓库地址。" whiptail --title "🔧 安装确认" --yesno "$confirm_message\n\n是否继续安装?" 15 60 if [[ $? -ne 0 ]]; then whiptail --title "🚫 取消安装" --msgbox "安装已取消。" 10 60 From 5bb8b69fa0b302aabcd38f007e989ade487b57e7 Mon Sep 17 00:00:00 2001 From: Cookie987 Date: Wed, 12 Mar 2025 22:55:11 +0800 Subject: [PATCH 6/8] =?UTF-8?q?break=E6=94=B9=E4=B8=BAreturn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index c616edcfb..43f35c578 100644 --- a/run.sh +++ b/run.sh @@ -54,7 +54,7 @@ install_packages() { if [[ ${#missing_packages[@]} -gt 0 ]]; then whiptail --title "📦 [3/6] 软件包检查" --yesno "检测到以下软件包缺失(MongoDB除外):\n${missing_packages[*]}\n\n是否要自动安装?" 12 60 if [[ $? -eq 0 ]]; then - break + return else whiptail --title "⚠️ 注意" --yesno "某些必要的软件包未安装,可能会影响运行!\n是否继续?" 10 60 || exit 1 fi From 2caeb59f2875e6be64abd6e420fad1527c1b1a8c Mon Sep 17 00:00:00 2001 From: Cookie987 Date: Thu, 13 Mar 2025 13:20:32 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=B8=80=E9=94=AE?= =?UTF-8?q?=E5=AE=89=E8=A3=85=20NapCat=E3=80=81MongoDB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run.sh | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 110 insertions(+), 15 deletions(-) diff --git a/run.sh b/run.sh index 43f35c578..c3f6969b6 100644 --- a/run.sh +++ b/run.sh @@ -5,7 +5,10 @@ # 请小心使用任何一键脚本! # 如无法访问GitHub请修改此处镜像地址 -GITHUB_REPO="https://github.com/SengokuCola/MaiMBot.git" + +LANG=C.UTF-8 + +GITHUB_REPO="https://ghfast.top/https://github.com/SengokuCola/MaiMBot.git" # 颜色输出 GREEN="\e[32m" @@ -13,7 +16,7 @@ RED="\e[31m" RESET="\e[0m" # 需要的基本软件包 -REQUIRED_PACKAGES=("git" "sudo" "python3" "python3-venv" "python3-pip") +REQUIRED_PACKAGES=("git" "sudo" "python3" "python3-venv" "curl" "gnupg" "python3-pip") # 默认项目目录 DEFAULT_INSTALL_DIR="/opt/maimbot" @@ -21,6 +24,9 @@ DEFAULT_INSTALL_DIR="/opt/maimbot" # 服务名称 SERVICE_NAME="maimbot" +IS_INSTALL_MONGODB=false +IS_INSTALL_NAPCAT=false + # 1/6: 检测是否安装 whiptail if ! command -v whiptail &>/dev/null; then echo -e "${RED}[1/6] whiptail 未安装,正在安装...${RESET}" @@ -38,10 +44,26 @@ get_os_info() { echo "$OS_INFO" } +# 检查系统 check_system() { - OS_NAME=$(get_os_info) - whiptail --title "⚙️ [2/6] 检查系统" --yesno "本脚本仅支持Debian 12。\n当前系统为 $OS_NAME\n是否继续?" 10 60 || exit 1 + # 检查是否为 root 用户 + if [[ "$(id -u)" -ne 0 ]]; then + whiptail --title "🚫 权限不足" --msgbox "请使用 root 用户运行此脚本!\n执行方式: sudo bash $0" 10 60 + exit 1 + fi + + if [[ -f /etc/os-release ]]; then + source /etc/os-release + if [[ "$ID" != "debian" || "$VERSION_ID" != "12" ]]; then + whiptail --title "🚫 不支持的系统" --msgbox "此脚本仅支持 Debian 12 (Bookworm)!\n当前系统: $PRETTY_NAME\n安装已终止。" 10 60 + exit 1 + fi + else + whiptail --title "⚠️ 无法检测系统" --msgbox "无法识别系统版本,安装已终止。" 10 60 + exit 1 + fi } + # 3/6: 询问用户是否安装缺失的软件包 install_packages() { missing_packages=() @@ -52,11 +74,11 @@ install_packages() { done if [[ ${#missing_packages[@]} -gt 0 ]]; then - whiptail --title "📦 [3/6] 软件包检查" --yesno "检测到以下软件包缺失(MongoDB除外):\n${missing_packages[*]}\n\n是否要自动安装?" 12 60 + whiptail --title "📦 [3/6] 软件包检查" --yesno "检测到以下必须的依赖项目缺失:\n${missing_packages[*]}\n\n是否要自动安装?" 12 60 if [[ $? -eq 0 ]]; then - return + return 0 else - whiptail --title "⚠️ 注意" --yesno "某些必要的软件包未安装,可能会影响运行!\n是否继续?" 10 60 || exit 1 + whiptail --title "⚠️ 注意" --yesno "某些必要的依赖项未安装,可能会影响运行!\n是否继续?" 10 60 || exit 1 fi fi } @@ -105,21 +127,31 @@ confirm_install() { if [[ ${#missing_packages[@]} -gt 0 ]]; then confirm_message+="📦 安装缺失的依赖项: ${missing_packages[*]}\n" else - confirm_message+="✅ 所有依赖项已安装,无需额外安装\n" + confirm_message+="✅ 所有依赖项已安装\n" fi - confirm_message+="📂 安装目录: $INSTALL_DIR\n" + confirm_message+="📂 安装麦麦Bot到: $INSTALL_DIR\n" confirm_message+="🔀 分支: $BRANCH\n" - if dpkg -s mongodb-org &>/dev/null; then + if [[ "$MONGODB_INSTALLED" == "true" ]]; then confirm_message+="✅ MongoDB 已安装\n" else - confirm_message+="⚠️ MongoDB 可能未安装(请参阅官方文档安装)\n" + if [[ "$IS_INSTALL_MONGODB" == "true" ]]; then + confirm_message+="📦 安装 MongoDB\n" + fi fi - confirm_message+="🛠️ 添加 Maimbot 作为系统服务 ($SERVICE_NAME.service)\n" + if [[ "$NAPCAT_INSTALLED" == "true" ]]; then + confirm_message+="✅ NapCat 已安装\n" + else + if [[ "$IS_INSTALL_NAPCAT" == "true" ]]; then + confirm_message+="📦 安装 NapCat\n" + fi + fi - confirm_message+="\n\n注意:本脚本使用GitHub,如无法访问请手动修改仓库地址。" + confirm_message+="🛠️ 添加麦麦Bot作为系统服务 ($SERVICE_NAME.service)\n" + + confitm_message+="\n\n注意:本脚本默认使用ghfast.top为GitHub进行加速,如不想使用请手动修改脚本开头的GITHUB_REPO变量。" whiptail --title "🔧 安装确认" --yesno "$confirm_message\n\n是否继续安装?" 15 60 if [[ $? -ne 0 ]]; then whiptail --title "🚫 取消安装" --msgbox "安装已取消。" 10 60 @@ -127,21 +159,83 @@ confirm_install() { fi } +check_mongodb() { + if command -v mongod &>/dev/null; then + MONGO_INSTALLED=true + else + MONGO_INSTALLED=false + fi +} + +# 安装 MongoDB +install_mongodb() { + if [[ "$MONGO_INSTALLED" == "true" ]]; then + return 0 + fi + + whiptail --title "📦 [3/6] 软件包检查" --yesno "检测到未安装MongoDB,是否安装?\n如果您想使用远程数据库,请跳过此步。" 10 60 + if [[ $? -ne 0 ]]; then + return 1 + fi + IS_INSTALL_MONGODB=true +} + +check_napcat() { + if command -v napcat &>/dev/null; then + NAPCAT_INSTALLED=true + else + NAPCAT_INSTALLED=false + fi +} + +install_napcat() { + if [[ "$NAPCAT_INSTALLED" == "true" ]]; then + return 0 + fi + + whiptail --title "📦 [3/6] 软件包检查" --yesno "检测到未安装NapCat,是否安装?\n如果您想使用远程NapCat,请跳过此步。" 10 60 + if [[ $? -ne 0 ]]; then + return 1 + fi + IS_INSTALL_NAPCAT=true +} + # 运行安装步骤 check_system +check_mongodb +check_napcat install_packages +install_mongodb +install_napcat check_python choose_branch choose_install_dir confirm_install # 开始安装 -whiptail --title "🚀 开始安装" --msgbox "所有环境检查完毕,即将开始安装 Maimbot!" 10 60 +whiptail --title "🚀 开始安装" --msgbox "所有环境检查完毕,即将开始安装麦麦Bot!" 10 60 echo -e "${GREEN}安装依赖项...${RESET}" apt update && apt install -y "${missing_packages[@]}" + +if [[ "$IS_INSTALL_MONGODB" == "true" ]]; then + echo -e "${GREEN}安装 MongoDB...${RESET}" + curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor + echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/8.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list + apt-get update + apt-get install -y mongodb-org + + systemctl enable mongod + systemctl start mongod +fi + +if [[ "$IS_INSTALL_NAPCAT" == "true" ]]; then + echo -e "${GREEN}安装 NapCat...${RESET}" + curl -o napcat.sh https://nclatest.znin.net/NapNeko/NapCat-Installer/main/script/install.sh && bash napcat.sh +fi + echo -e "${GREEN}创建 Python 虚拟环境...${RESET}" mkdir -p "$INSTALL_DIR" cd "$INSTALL_DIR" || exit @@ -158,6 +252,7 @@ echo -e "${GREEN}安装 Python 依赖...${RESET}" pip install -r requirements.txt echo -e "${GREEN}设置服务...${RESET}" + # 设置 Maimbot 服务 cat < Date: Thu, 13 Mar 2025 13:25:26 +0800 Subject: [PATCH 8/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 92fcdc318..a7394c7cf 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ - 📦 **Windows 一键傻瓜式部署**:请运行项目根目录中的 `run.bat`,部署完成后请参照后续配置指南进行配置 -- 📦 Linux 自动部署(实验) :请在项目根目录中运行 `bash 1key_install_linux.sh`并按照提示安装,部署完成后请参照后续配置指南进行配置 +- 📦 Linux 自动部署(实验) :请下载并运行项目根目录中的`run.sh`并按照提示安装,部署完成后请参照后续配置指南进行配置 - [📦 Windows 手动部署指南 ](docs/manual_deploy_windows.md)