✨ feat(MaiLauncher.bat): 优化脚本逻辑,添加MongoDB支持,改进Git安装流程
This commit is contained in:
149
MaiLauncher.bat
149
MaiLauncher.bat
@@ -1,5 +1,5 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
@setlocal enabledelayedexpansion
|
||||
@chcp 936
|
||||
|
||||
@REM 设置版本号
|
||||
@@ -11,9 +11,10 @@ title 麦麦Bot控制台 v%VERSION%
|
||||
set "_root=%~dp0"
|
||||
set "_root=%_root:~0,-1%"
|
||||
cd "%_root%"
|
||||
echo "%_root%
|
||||
|
||||
|
||||
:search_python
|
||||
cls
|
||||
if exist "%_root%\python" (
|
||||
set "PYTHON_HOME=%_root%\python"
|
||||
) else if exist "%_root%\venv" (
|
||||
@@ -42,9 +43,9 @@ if exist "%_root%\python" (
|
||||
)
|
||||
echo 没有找到Python解释器,要安装吗?
|
||||
set /p pyinstall_confirm="继续?(Y/n): "
|
||||
echo !pyinstall_confirm!
|
||||
if /i "!pyinstall_confirm!"=="Y" (
|
||||
@REM echo 正在安装Python...
|
||||
cls
|
||||
echo 正在安装Python...
|
||||
winget install --id Python.Python.3.13 -e --accept-package-agreements --accept-source-agreements
|
||||
if %errorlevel% neq 0 (
|
||||
echo 安装失败,请手动安装Python
|
||||
@@ -84,6 +85,7 @@ echo 成功设置Python路径:%PYTHON_HOME%
|
||||
|
||||
|
||||
:search_git
|
||||
cls
|
||||
if exist "%_root%\tools\git\bin" (
|
||||
set "GIT_HOME=%_root%\tools\git\bin"
|
||||
) else (
|
||||
@@ -98,22 +100,36 @@ if exist "%_root%\tools\git\bin" (
|
||||
)
|
||||
echo 正在扫描常见安装路径...
|
||||
set "search_paths=!ProgramFiles!\Git\cmd"
|
||||
for /d %%d in (!search_paths!) do (
|
||||
if exist "%%d\bin\git.exe" (
|
||||
set "git_path=%%d\bin\git.exe"
|
||||
for /f "tokens=*" %%d in ("!search_paths!") do (
|
||||
if exist "%%d\git.exe" (
|
||||
set "git_path=%%d\git.exe"
|
||||
goto :validate_git
|
||||
)
|
||||
)
|
||||
echo 没有找到Git,要安装吗?
|
||||
set /p confirm="继续?(Y/N): "
|
||||
if /i "!confirm!"=="Y" (
|
||||
cls
|
||||
echo 正在安装Git...
|
||||
winget install --id Git.Git -e --accept-package-agreements --accept-source-agreements
|
||||
if %errorlevel% neq 0 (
|
||||
echo 安装失败,请手动安装Git
|
||||
set "custom_url=https://ghfast.top/https://github.com/git-for-windows/git/releases/download/v2.48.1.windows.1/Git-2.48.1-64-bit.exe"
|
||||
|
||||
set "download_path=%TEMP%\Git-Installer.exe"
|
||||
|
||||
echo 正在下载Git安装包...
|
||||
curl -L -o "!download_path!" "!custom_url!"
|
||||
|
||||
if exist "!download_path!" (
|
||||
echo 下载成功,开始安装Git...
|
||||
start /wait "" "!download_path!" /SILENT /NORESTART
|
||||
) else (
|
||||
echo 下载失败,请手动安装Git
|
||||
start https://git-scm.com/download/win
|
||||
exit /b
|
||||
)
|
||||
|
||||
del "!download_path!"
|
||||
echo 临时文件已清理。
|
||||
|
||||
echo 安装完成,正在验证Git...
|
||||
where git >nul 2>&1
|
||||
if %errorlevel% equ 0 (
|
||||
@@ -121,7 +137,6 @@ if exist "%_root%\tools\git\bin" (
|
||||
set "git_path=%%i"
|
||||
goto :validate_git
|
||||
)
|
||||
echo sba
|
||||
goto :search_git
|
||||
|
||||
) else (
|
||||
@@ -151,35 +166,72 @@ if exist "%_root%\tools\git\bin" (
|
||||
set "GIT_HOME=%GIT_HOME:~0,-1%"
|
||||
)
|
||||
|
||||
:search_mongodb
|
||||
cls
|
||||
sc query | findstr /i "MongoDB" >nul
|
||||
if %errorlevel% neq 0 (
|
||||
echo MongoDB服务未运行,正在尝试启动...
|
||||
net start MongoDB >nul 2>&1
|
||||
if %errorlevel% neq 0 (
|
||||
echo MongoDB服务启动失败,可能是没有安装,要安装吗?
|
||||
set /p confirm="继续?(Y/N): "
|
||||
if /i "!confirm!"=="Y" (
|
||||
echo 正在安装MongoDB...
|
||||
winget install --id MongoDB.Server -e --accept-package-agreements --accept-source-agreements
|
||||
echo 安装完成,正在启动MongoDB服务...
|
||||
net start MongoDB
|
||||
if %errorlevel% neq 0 (
|
||||
echo 启动MongoDB服务失败,请手动启动
|
||||
exit /b
|
||||
)
|
||||
echo MongoDB服务已启动
|
||||
) else (
|
||||
echo 取消安装MongoDB,按任意键退出...
|
||||
pause >nul
|
||||
exit /b
|
||||
)
|
||||
)
|
||||
) else (
|
||||
echo MongoDB服务已运行
|
||||
)
|
||||
|
||||
@REM set "GIT_HOME=%_root%\tools\git\bin"
|
||||
set "PATH=%PYTHON_HOME%;%GIT_HOME%;%PATH%"
|
||||
|
||||
:install_maim
|
||||
if not exist "%_root%\bot.py" (
|
||||
echo 你似乎没有安装麦麦Bot,要自动安装吗?(Y/N)
|
||||
if not exist "!_root!\bot.py" (
|
||||
cls
|
||||
echo 你似乎没有安装麦麦Bot,要安装在当前目录吗?
|
||||
set /p confirm="继续?(Y/N): "
|
||||
if /i "%confirm%"=="Y" (
|
||||
echo 要使用Git代理下载吗?(Y/N)
|
||||
if /i "!confirm!"=="Y" (
|
||||
echo 要使用Git代理下载吗?
|
||||
set /p proxy_confirm="继续?(Y/N): "
|
||||
if /i "%proxy_confirm%"=="Y" (
|
||||
if /i "!proxy_confirm!"=="Y" (
|
||||
echo 正在安装麦麦Bot...
|
||||
git clone https://ghfast.top/https://github.com/SengokuCola/MaiMBot .
|
||||
git clone https://ghfast.top/https://github.com/SengokuCola/MaiMBot
|
||||
) else (
|
||||
echo 正在安装麦麦Bot...
|
||||
git clone https://github.com/SengokuCola/MaiMBot .
|
||||
git clone https://github.com/SengokuCola/MaiMBot
|
||||
)
|
||||
xcopy /E /H /I MaiMBot . >nul 2>&1
|
||||
rmdir /s /q MaiMBot
|
||||
git checkout main-fix
|
||||
|
||||
echo 安装完成,正在安装依赖...
|
||||
python -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
|
||||
python -m pip install virtualenv
|
||||
python -m virtualenv venv
|
||||
call venv\Scripts\activate.bat
|
||||
python -m pip install -r requirements.txt
|
||||
|
||||
echo 安装完成,要编辑配置文件吗?(Y/N)
|
||||
echo 安装完成,要编辑配置文件吗?
|
||||
set /p edit_confirm="继续?(Y/N): "
|
||||
if /i "%edit_confirm%"=="Y" (
|
||||
if /i "!edit_confirm!"=="Y" (
|
||||
goto config_menu
|
||||
) else (
|
||||
echo 取消编辑配置文件,按任意键返回主菜单...
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -190,9 +242,9 @@ for /f "delims=" %%b in ('git symbolic-ref --short HEAD 2^>nul') do (
|
||||
|
||||
@REM 根据不同分支名给分支名字符串使用不同颜色
|
||||
echo 分支名: %BRANCH%
|
||||
if "%BRANCH%"=="main" (
|
||||
if "!BRANCH!"=="main" (
|
||||
set "BRANCH_COLOR=[92m"
|
||||
) else if "%BRANCH%"=="main-fix" (
|
||||
) else if "!BRANCH!"=="main-fix" (
|
||||
set "BRANCH_COLOR=[91m"
|
||||
@REM ) else if "%BRANCH%"=="stable-dev" (
|
||||
@REM set "BRANCH_COLOR=[96m"
|
||||
@@ -217,13 +269,13 @@ echo ======================
|
||||
|
||||
set /p choice="请输入选项数字 (1-5)并按下回车以选择: "
|
||||
|
||||
if "%choice%"=="" set choice=1
|
||||
if "!choice!"=="" set choice=1
|
||||
|
||||
if "%choice%"=="1" goto update_and_start
|
||||
if "%choice%"=="2" goto start_bot
|
||||
if "%choice%"=="3" goto config_menu
|
||||
if "%choice%"=="4" goto tools_menu
|
||||
if "%choice%"=="5" exit /b
|
||||
if "!choice!"=="1" goto update_and_start
|
||||
if "!choice!"=="2" goto start_bot
|
||||
if "!choice!"=="3" goto config_menu
|
||||
if "!choice!"=="4" goto tools_menu
|
||||
if "!choice!"=="5" exit /b
|
||||
|
||||
echo 无效的输入,请输入1-5之间的数字
|
||||
timeout /t 2 >nul
|
||||
@@ -233,13 +285,15 @@ goto menu
|
||||
@chcp 936
|
||||
cls
|
||||
if not exist config/bot_config.toml (
|
||||
copy template/bot_config_template.toml config/bot_config.toml
|
||||
copy /Y "template\bot_config_template.toml" "config\bot_config.toml"
|
||||
re
|
||||
|
||||
)
|
||||
if not exist .env.prod (
|
||||
copy template.env .env.prod
|
||||
copy /Y "template\.env.prod" ".env.prod"
|
||||
)
|
||||
|
||||
python webui.py
|
||||
start python webui.py
|
||||
|
||||
goto menu
|
||||
|
||||
@@ -258,13 +312,12 @@ echo 7. 返回主菜单
|
||||
echo ======================
|
||||
|
||||
set /p choice="请输入选项数字: "
|
||||
if "%choice%"=="1" goto update_dependencies
|
||||
if "%choice%"=="2" goto switch_branch
|
||||
if "%choice%"=="3" goto update_config
|
||||
if "%choice%"=="4" goto learn_new_knowledge
|
||||
if "%choice%"=="5" goto open_knowledge_folder
|
||||
if "%choice%"=="6" goto menu
|
||||
if "%choice%"=="3" goto open_dir
|
||||
if "!choice!"=="1" goto update_dependencies
|
||||
if "!choice!"=="2" goto switch_branch
|
||||
if "!choice!"=="3" goto update_config
|
||||
if "!choice!"=="4" goto learn_new_knowledge
|
||||
if "!choice!"=="5" goto open_knowledge_folder
|
||||
if "!choice!"=="6" goto menu
|
||||
|
||||
echo 无效的输入,请输入1-6之间的数字
|
||||
timeout /t 2 >nul
|
||||
@@ -325,7 +378,7 @@ echo 继续请按Y,取消请按任意键...
|
||||
set /p confirm="继续?(Y/N): "
|
||||
if /i "%confirm%"=="Y" (
|
||||
echo 正在更新配置文件...
|
||||
python\python.exe config\auto_update.py
|
||||
python.exe config\auto_update.py
|
||||
echo 配置文件更新完成,按任意键返回工具箱菜单...
|
||||
) else (
|
||||
echo 取消更新配置文件,按任意键返回工具箱菜单...
|
||||
@@ -341,7 +394,7 @@ echo 继续请按Y,取消请按任意键...
|
||||
set /p confirm="继续?(Y/N): "
|
||||
if /i "%confirm%"=="Y" (
|
||||
echo 正在学习新的知识库...
|
||||
python\python.exe src\plugins\zhishi\knowledge_library.py
|
||||
python.exe src\plugins\zhishi\knowledge_library.py
|
||||
echo 学习完成,按任意键返回工具箱菜单...
|
||||
) else (
|
||||
echo 取消学习新的知识库,按任意键返回工具箱菜单...
|
||||
@@ -366,19 +419,19 @@ goto tools_menu
|
||||
:update_and_start
|
||||
cls
|
||||
:retry_git_pull
|
||||
tools\git\bin\git.exe pull > temp.log 2>&1
|
||||
git pull > temp.log 2>&1
|
||||
findstr /C:"detected dubious ownership" temp.log >nul
|
||||
if %errorlevel% equ 0 (
|
||||
echo 检测到仓库权限问题,正在自动修复...
|
||||
tools\git\bin\git.exe config --global --add safe.directory "%cd%"
|
||||
git config --global --add safe.directory "%cd%"
|
||||
echo 已添加例外,正在重试git pull...
|
||||
del temp.log
|
||||
goto retry_git_pull
|
||||
)
|
||||
del temp.log
|
||||
echo 正在更新依赖...
|
||||
python\python.exe -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
|
||||
python\python.exe -m pip install -r requirements.txt && cls
|
||||
python -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
|
||||
python -m pip install -r requirements.txt && cls
|
||||
|
||||
echo 当前代理设置:
|
||||
echo HTTP_PROXY=%HTTP_PROXY%
|
||||
@@ -390,7 +443,7 @@ set HTTPS_PROXY=
|
||||
set no_proxy=0.0.0.0/32
|
||||
|
||||
REM chcp 65001
|
||||
python\python.exe bot.py
|
||||
python bot.py
|
||||
echo.
|
||||
echo Bot已停止运行,按任意键返回主菜单...
|
||||
pause >nul
|
||||
@@ -399,8 +452,8 @@ goto menu
|
||||
:start_bot
|
||||
cls
|
||||
echo 正在更新依赖...
|
||||
python\python.exe -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
|
||||
python\python.exe -m pip install -r requirements.txt && cls
|
||||
python -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
|
||||
python -m pip install -r requirements.txt && cls
|
||||
|
||||
echo 当前代理设置:
|
||||
echo HTTP_PROXY=%HTTP_PROXY%
|
||||
@@ -412,7 +465,7 @@ set HTTPS_PROXY=
|
||||
set no_proxy=0.0.0.0/32
|
||||
|
||||
REM chcp 65001
|
||||
python\python.exe bot.py
|
||||
python bot.py
|
||||
echo.
|
||||
echo Bot已停止运行,按任意键返回主菜单...
|
||||
pause >nul
|
||||
|
||||
Reference in New Issue
Block a user