From fa881d4450c5f0a874fd88e74cd27912da4938c4 Mon Sep 17 00:00:00 2001 From: "Quang (Albert)" Date: Sun, 8 Sep 2024 10:54:26 +0700 Subject: [PATCH] feat: add Portable Git to Windows installer (#232) * feat(windows installer): check and install git * feat: update run_windows.bat * feat: Replace standalone Git installer with Portable Git * feat: support milvus vector db (#188) #none Signed-off-by: ChengZi * feat: add github action to build docker for release (#168) #none * feat: update build push docker action * feat: remove tag trigger * feat: remove manual trigger * fix: update workflow * feat: update build-push-docker.yaml * fix: update workflow * fix: update workflow * fix: update workflow * refactor: comfort pre-commit * feat: update permission * feat: update docker support pdfjs * refactor: comfort pre-commit * feat: add support for Gemini, Claude through Langchain (#225) (bump:patch) * fix: disable default install for google-genai package * fix: disable default install for anthropic * fix: update on release event build push docker (#228) #none * fix: update on release event build push docker * refactor: comfort pre-commit * fix: limit fastapi version (#229) * fix: update requirements (#230) * style: fix pre-commit --------- Signed-off-by: ChengZi Co-authored-by: ChengZi Co-authored-by: kan_cin Co-authored-by: Tuan Anh Nguyen Dang (Tadashi_Cin) --- scripts/run_windows.bat | 95 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 6 deletions(-) diff --git a/scripts/run_windows.bat b/scripts/run_windows.bat index 369610d..7aa2d02 100644 --- a/scripts/run_windows.bat +++ b/scripts/run_windows.bat @@ -10,15 +10,34 @@ SET env_dir=%install_dir%\env SET python_version=3.10 SET miniconda_download_url=https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe +SET git_install_dir=%install_dir%\Git +SET seven_zip_dir=%install_dir%\7zip +:: Determine if the machine is 32-bit or 64-bit +IF "%PROCESSOR_ARCHITECTURE%"=="x86" ( + SET seven_zip_url=https://7-zip.org/a/7z2408.exe + SET git_download_url=https://github.com/git-for-windows/git/releases/download/v2.46.0.windows.1/PortableGit-2.46.0-32-bit.7z.exe +) ELSE ( + SET seven_zip_url=https://7-zip.org/a/7z2408-x64.exe + SET git_download_url=https://github.com/git-for-windows/git/releases/download/v2.46.0.windows.1/PortableGit-2.46.0-64-bit.7z.exe +) + ECHO %CD%| FINDSTR /C:" " >nul 2>&1 IF %ERRORLEVEL% EQU 0 ( ECHO The current workdir has whitespace which can lead to unintended behaviour. Please modify your path and continue later. GOTO :end ) +IF NOT EXIST "%install_dir%" ( MKDIR "%install_dir%" ) + +CALL :print_highlight "Setting up Git" +CALL :download_and_install_git +IF ERRORLEVEL 1 GOTO :end + +:: Temporarily add Portable Git to PATH +SET "PATH=%git_install_dir%\bin;%PATH%" + CALL :print_highlight "Setting up Miniconda" CALL :download_and_install_miniconda -:: check if function run fail, then exit the script IF ERRORLEVEL 1 GOTO :end CALL :print_highlight "Creating conda environment" @@ -42,10 +61,70 @@ CALL :launch_ui CALL :deactivate_environment GOTO :end_success +:download_and_install_7zip +:: Check if 7-Zip is installed +IF NOT EXIST "%seven_zip_dir%\7z.exe" ( + ECHO Downloading 7-Zip from %seven_zip_url% + CALL curl -Lk "%seven_zip_url%" -o "%install_dir%\7zip_installer.exe" || ( + ECHO. && ECHO Failed to download 7-Zip. Aborting... + GOTO :exit_func_with_error + ) + ECHO Installing 7-Zip to %seven_zip_dir% + CALL "%install_dir%\7zip_installer.exe" /S /D=%seven_zip_dir% + DEL "%install_dir%\7zip_installer.exe" +) +ECHO 7-Zip is installed at %seven_zip_dir% + +GOTO :eof + +:uninstall_7zip +IF EXIST "%seven_zip_dir%\Uninstall.exe" ( + CALL "%seven_zip_dir%\Uninstall.exe" /S +) ELSE ( + ECHO. && ECHO Uninstaller not found. Manually deleting 7-Zip directory... + RMDIR /S /Q "%seven_zip_dir%" +) + +GOTO :eof + +:download_and_install_git +:: Check if Git is already installed +CALL "%git_install_dir%\bin\git.exe" --version >nul 2>&1 +IF %ERRORLEVEL% NEQ 0 ( + ECHO Install 7-Zip to extract Portable Git. It will be uninstalled automatically after Git installation. && ECHO. + CALL :download_and_install_7zip + IF ERRORLEVEL 1 GOTO :end + + ECHO. && ECHO Downloading Portable Git from %git_download_url% + CALL curl -Lk "%git_download_url%" -o "%install_dir%\portable_git.7z.exe" || ( + ECHO. && ECHO Failed to download Git. Aborting... + GOTO :exit_func_with_error + ) + + ECHO Extracting Git to %git_install_dir%... + CALL "%seven_zip_dir%\7z.exe" x "%install_dir%\portable_git.7z.exe" -o"%git_install_dir%" -y >nul || ( + ECHO. && ECHO Failed to extract Git. Aborting... + GOTO :exit_func_with_error + ) + DEL "%install_dir%\portable_git.7z.exe" + + ECHO. && ECHO Uninstalling 7-Zip... + CALL :uninstall_7zip + IF ERRORLEVEL 1 GOTO :end +) +ECHO Git is installed at %git_install_dir% +:: Recheck Git installation +CALL "%git_install_dir%\bin\git.exe" --version || ( + ECHO. && ECHO Git not found. Aborting... + GOTO :exit_func_with_error +) + +SET "PATH=%git_install_dir%\bin;%PATH%" +ECHO Git is added to PATH for this session + +GOTO :eof :download_and_install_miniconda -IF NOT EXIST "%install_dir%" ( MKDIR "%install_dir%" ) - :: If conda has been installed at the %conda_root%, don't need to reinstall it CALL "%conda_root%\_conda.exe" --version >nul 2>&1 IF %ERRORLEVEL% NEQ 0 ( @@ -62,7 +141,7 @@ IF %ERRORLEVEL% NEQ 0 ( ) ECHO Conda is installed at %conda_root% -:: recheck conda +:: Recheck conda ECHO Conda version: CALL "%conda_root%\_conda.exe" --version || ( ECHO. && ECHO Conda not found. Aborting... && GOTO :exit_func_with_error ) @@ -85,8 +164,12 @@ IF NOT EXIST %env_dir% ( GOTO :eof :activate_environment -:: deactivate existing conda env(s) to avoid conflicts -( CALL conda deactivate && CALL conda deactivate && CALL conda deactivate ) 2> nul +:: Deactivate existing conda env(s) to avoid conflicts +IF EXIST "%conda_root%\condabin\conda.bat" ( + CALL "%conda_root%\condabin\conda.bat" deactivate + CALL "%conda_root%\condabin\conda.bat" deactivate + CALL "%conda_root%\condabin\conda.bat" deactivate +) CALL "%env_dir%\python.exe" --version >nul 2>&1 || ( ECHO The environment appears to be broken. You may need to remove %env_dir% and run the installer again.