105 lines
2.6 KiB
Batchfile
105 lines
2.6 KiB
Batchfile
@echo off
|
|
setlocal
|
|
|
|
:: Set this to 1 to force download/install even if git is in PATH
|
|
set "FORCE_DOWNLOAD=1"
|
|
|
|
:: Git download URL
|
|
set "GIT_URL=https://github.com/git-for-windows/git/releases/download/v2.50.0.windows.2/PortableGit-2.50.0.2-64-bit.7z.exe"
|
|
|
|
:: Extract archive name from URL
|
|
for %%A in ("%GIT_URL%") do (
|
|
for %%B in (%%~nxA) do set "GIT_ARCHIVE=%%~B"
|
|
)
|
|
|
|
:: Paths
|
|
set "SCRIPT_DIR=%~dp0"
|
|
set "EXTRACT_DIR=%SCRIPT_DIR%gitportable"
|
|
set "LOG_FILE=%SCRIPT_DIR%git_setup.log"
|
|
|
|
:: Redirect output to log
|
|
call :main >> "%LOG_FILE%" 2>&1
|
|
goto :end
|
|
|
|
:main
|
|
echo ====================================================
|
|
echo Script started at %DATE% %TIME%
|
|
echo ====================================================
|
|
echo.
|
|
|
|
:: Check if git is in PATH unless forced
|
|
where git >nul 2>nul
|
|
if %errorlevel%==0 (
|
|
if "%FORCE_DOWNLOAD%"=="0" (
|
|
echo Git found in PATH, skipping download and extraction.
|
|
goto :done
|
|
) else (
|
|
echo Git found in PATH but FORCE_DOWNLOAD=1, continuing anyway.
|
|
)
|
|
)
|
|
|
|
:: Check if extraction folder exists
|
|
if exist "%EXTRACT_DIR%\" (
|
|
echo 'gitportable' folder already exists.
|
|
if "%FORCE_DOWNLOAD%"=="0" (
|
|
echo Skipping download and extraction.
|
|
goto :done
|
|
) else (
|
|
echo FORCE_DOWNLOAD=1, continuing with download and extraction.
|
|
)
|
|
)
|
|
|
|
:: Download Git
|
|
echo Downloading Git...
|
|
powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%GIT_URL%' -OutFile '%SCRIPT_DIR%%GIT_ARCHIVE%'"
|
|
if %errorlevel% neq 0 (
|
|
echo Error: Download failed.
|
|
goto :done
|
|
)
|
|
echo Download completed.
|
|
|
|
:: Clean extraction directory if forced
|
|
if "%FORCE_DOWNLOAD%"=="1" if exist "%EXTRACT_DIR%\" (
|
|
echo Removing existing '%EXTRACT_DIR%' folder before extraction...
|
|
rmdir /s /q "%EXTRACT_DIR%"
|
|
)
|
|
|
|
:: Create extraction directory
|
|
echo Preparing extraction folder...
|
|
mkdir "%EXTRACT_DIR%"
|
|
if %errorlevel% neq 0 (
|
|
echo Error: Failed to create extraction directory.
|
|
goto :done
|
|
)
|
|
|
|
:: Extract Git silently
|
|
echo Extracting Git...
|
|
"%SCRIPT_DIR%%GIT_ARCHIVE%" -o"%EXTRACT_DIR%" -y >nul 2>&1
|
|
if %errorlevel% neq 0 (
|
|
echo Error: Extraction failed.
|
|
goto :done
|
|
)
|
|
echo Extraction completed.
|
|
|
|
:: Cleanup
|
|
echo Cleaning up archive file...
|
|
del "%SCRIPT_DIR%%GIT_ARCHIVE%"
|
|
if %errorlevel% neq 0 (
|
|
echo Warning: Failed to delete archive file.
|
|
)
|
|
|
|
echo.
|
|
echo Git Portable is ready in: %EXTRACT_DIR%
|
|
echo ====================================================
|
|
echo Script ended at %DATE% %TIME%
|
|
echo ====================================================
|
|
|
|
:done
|
|
exit /b
|
|
|
|
:end
|
|
echo.
|
|
echo Log saved to: %LOG_FILE%
|
|
echo Press Enter to close this window...
|
|
pause >nul
|