Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 102 additions & 31 deletions src/cloudmesh/common/bin/win-setup.bat
Original file line number Diff line number Diff line change
@@ -1,48 +1,119 @@
@echo off
SETLOCAL
setlocal EnableExtensions EnableDelayedExpansion

REM Check if Chocolatey is installed
choco --version 2>nul
if %errorlevel% neq 0 (
echo Chocolatey is not installed. Installing Chocolatey...
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"
) else (
echo Chocolatey is already installed.
REM -------------------------------------------------------------
REM Resolve Chocolatey path (no reliance on PATH)
REM -------------------------------------------------------------
set "CHOCO="
set "CHOCOROOT="

REM Try Machine scope ChocolateyInstall
for /f "usebackq delims=" %%I in (`powershell -NoProfile -Command ^
"$m=[Environment]::GetEnvironmentVariable('ChocolateyInstall','Machine'); if([string]::IsNullOrWhiteSpace($m)){''} else {$m}"`) do (
set "CHOCOROOT=%%I"
)

REM Fallback: User scope ChocolateyInstall
if not defined CHOCOROOT (
for /f "usebackq delims=" %%I in (`powershell -NoProfile -Command ^
"$u=[Environment]::GetEnvironmentVariable('ChocolateyInstall','User'); if([string]::IsNullOrWhiteSpace($u)){''} else {$u}"`) do (
set "CHOCOROOT=%%I"
)
)

REM Fallback: default install location (use ProgramData, not hard-coded C:)
if not defined CHOCOROOT set "CHOCOROOT=%ProgramData%\Chocolatey"

REM If choco.exe exists there, use it
if exist "%CHOCOROOT%\bin\choco.exe" set "CHOCO=%CHOCOROOT%\bin\choco.exe"

REM As a last resort, try PATH (doesn't break if it's already on PATH)
if not defined CHOCO (
for /f "delims=" %%I in ('where choco 2^>nul') do set "CHOCO=%%~fI"
)

REM -------------------------------------------------------------
REM Install Chocolatey if still not found
REM -------------------------------------------------------------
if not defined CHOCO (
echo Chocolatey is not installed. Installing Chocolatey...
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"
REM Re-resolve after install
set "CHOCOROOT=%ProgramData%\Chocolatey"
if exist "%CHOCOROOT%\bin\choco.exe" (
set "CHOCO=%CHOCOROOT%\bin\choco.exe"
) else (
for /f "usebackq delims=" %%I in (`
powershell -NoProfile -Command "[Environment]::GetEnvironmentVariable('ChocolateyInstall','Machine') ?? ''"
`) do set "CHOCOROOT=%%I"
if exist "%CHOCOROOT%\bin\choco.exe" set "CHOCO=%CHOCOROOT%\bin\choco.exe"
)
)

REM Check if Python is installed
python --version 2>nul
if %errorlevel% neq 0 (
echo Python is not installed. Installing Python...
choco install python -y
if not exist "%CHOCO%" (
echo ERROR: Could not locate choco.exe after installation.
exit /b 1
)

echo Using Chocolatey: "%CHOCO%"
echo.

REM -------------------------------------------------------------
REM Check/install Python
REM -------------------------------------------------------------
where python >nul 2>nul
if errorlevel 1 (
echo Python is not on PATH. Installing Python...
"%CHOCO%" install python -y
) else (
echo Python is already installed.
echo Python is already available.
)

REM Check if Git is installed
git --version 2>nul
if %errorlevel% neq 0 (
echo Git is not installed. Installing Git...
choco install git.install --params "/GitAndUnixToolsOnPath /Editor:Nano /PseudoConsoleSupport /NoAutoCrlf" -y
REM -------------------------------------------------------------
REM Check/install Git
REM -------------------------------------------------------------
where git >nul 2>nul
if errorlevel 1 (
echo Git is not on PATH. Installing Git...
"%CHOCO%" install git.install --params "/GitAndUnixToolsOnPath /Editor:Nano /PseudoConsoleSupport /NoAutoCrlf" -y
) else (
echo Git is already installed.
echo Git is already available.
)

REM Check if cygwin is installed
cygcheck -V 2>nul
if %errorlevel% neq 0 (
echo cygwin is not installed. Installing cygwin...
choco install cygwin -y
REM -------------------------------------------------------------
REM Check/install Cygwin (cygcheck in PATH means it's present)
REM -------------------------------------------------------------
where cygcheck >nul 2>nul
if errorlevel 1 (
echo Cygwin is not on PATH. Installing Cygwin...
"%CHOCO%" install cygwin -y
) else (
echo cygwin is already installed.
echo Cygwin is already available.
)

REM Countdown from 5
REM -------------------------------------------------------------
REM Countdown + refresh environment in THIS window
REM -------------------------------------------------------------
echo.
echo cloudmesh has all required dependencies. Starting in 5 seconds...

for /l %%i in (5,-1,1) do (
echo %%i
timeout /t 1 >nul
echo %%i
timeout /t 1 >nul
)

refreshenv
if exist "%CHOCOROOT%\bin\refreshenv.cmd" (
call "%CHOCOROOT%\bin\refreshenv.cmd"
) else (
set "PATH=%PATH%;%CHOCOROOT%\bin"
)

REM --- snapshot refreshed values while SETLOCAL is active ---
set "PATH_SNAP=!PATH!"
set "CHOCO_SNAP=%CHOCOROOT%"

REM --- propagate to the caller after ENDLOCAL ---
ENDLOCAL & (
set "PATH=%PATH_SNAP%"
if not defined ChocolateyInstall set "ChocolateyInstall=%CHOCO_SNAP%"
)
Loading