AllSpice-SVN-Monorepos/clone-allspice-and-svn-monorepo.bat

92 lines
2.6 KiB
Batchfile

@echo off
:: Set color: Light green text on black background
color 09
title AllSpice Loves SVN Monorepos
cls
:: Get current date and time in yyyy-mm-dd_hh:mm:ss format
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /value') do set datetime=%%I
set LOGTIME=%datetime:~0,4%-%datetime:~4,2%-%datetime:~6,2%_%datetime:~8,2%:%datetime:~10,2%:%datetime:~12,2%
echo [%LOGTIME%] Current Timestamp: %LOGTIME%
echo ----------------------------------------------------------------
echo.
echo AllSpice Lovess SVN Monorepos v0.9.1
echo.
echo 1. Cloning a fresh AllSpice Repo...
echo 2. Deep Cloning an existing SVN Monorepo subfolder...
echo - Monorepo is many projects in one SVN repo
echo - SVN is cloned INTO the AllSpice Git repo
echo 3. Adding hooks and fetch-svn.bat
echo.
echo ----------------------------------------------------------------
echo.
setlocal enabledelayedexpansion
REM Define the AllSpice directory
set "ALLSPICE_DIR=%USERPROFILE%\allspice"
REM Check if the directory exists, if not, create it
if not exist "!ALLSPICE_DIR!" mkdir "!ALLSPICE_DIR!"
REM Copy this script to the AllSpice directory
set "SCRIPT_NAME=%~nx0"
set "SCRIPT_PATH=!ALLSPICE_DIR!\!SCRIPT_NAME!"
copy /Y "%~f0" "!SCRIPT_PATH!" >nul 2>&1
REM Change to the AllSpice directory
cd /d "!ALLSPICE_DIR!"
:: clone-allspice-and-svn.bat
:: Downloads a bash script and runs it
:: svn-to-allspice.sh - clones AllSpice, clones SVN into AllSpice repo. Sets up hooks and quality of life scripts.
setlocal
:: Define the URL and output file
set URL=https://hub.allspice.io/AllSpice-Demos/AllSpice-Loves-SVN-Monorepos/raw/branch/main/.allspice/svn-to-allspice.sh
set OUTPUT=svn-to-allspice.sh
echo [%LOGTIME%]- [00] Downloading install script
echo.
:: Download the file using curl
curl -L -o %OUTPUT% %URL%
:: Check if download was successful
if %errorlevel% neq 0 (
echo [%LOGTIME%] Download failed!
exit /b 1
)
echo.
echo [%LOGTIME%]- Download successful: %OUTPUT%
echo.
endlocal
echo [%LOGTIME%]- [00b] running install script
set LOGFILE=allspice.log
echo.
:: Attempt to locate Git Bash in common locations
set "GIT_BASH1=C:\Program Files\Git\bin\bash.exe"
set "GIT_BASH2=%USERPROFILE%\AppData\Local\Programs\Git\bin\bash.exe"
if exist "%GIT_BASH1%" (
set "BASH_EXE=%GIT_BASH1%"
) else if exist "%GIT_BASH2%" (
set "BASH_EXE=%GIT_BASH2%"
) else (
echo Git Bash not found. Please install Git for Windows and try again.
exit /b 1
)
:: Run the repo clone/install script
"%BASH_EXE%" -c "$USERPROFILE/allspice/svn-to-allspice.sh 2>&1 | tee >(sed 's/\x1B\[[0-9;]*[mK]//g' >> %LOGFILE%)"
echo.
set /p RESULT=<latest-repo.txt
cd /d %RESULT%
"%BASH_EXE%" --login -i