Skip to content

Commit a214a3b

Browse files
authored
Update win-setup.bat
1 parent 2d5ca91 commit a214a3b

File tree

1 file changed

+102
-31
lines changed

1 file changed

+102
-31
lines changed
Lines changed: 102 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,119 @@
11
@echo off
2-
SETLOCAL
2+
setlocal EnableExtensions EnableDelayedExpansion
33

4-
REM Check if Chocolatey is installed
5-
choco --version 2>nul
6-
if %errorlevel% neq 0 (
7-
echo Chocolatey is not installed. Installing Chocolatey...
8-
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"
9-
) else (
10-
echo Chocolatey is already installed.
4+
REM -------------------------------------------------------------
5+
REM Resolve Chocolatey path (no reliance on PATH)
6+
REM -------------------------------------------------------------
7+
set "CHOCO="
8+
set "CHOCOROOT="
9+
10+
REM Try Machine scope ChocolateyInstall
11+
for /f "usebackq delims=" %%I in (`powershell -NoProfile -Command ^
12+
"$m=[Environment]::GetEnvironmentVariable('ChocolateyInstall','Machine'); if([string]::IsNullOrWhiteSpace($m)){''} else {$m}"`) do (
13+
set "CHOCOROOT=%%I"
14+
)
15+
16+
REM Fallback: User scope ChocolateyInstall
17+
if not defined CHOCOROOT (
18+
for /f "usebackq delims=" %%I in (`powershell -NoProfile -Command ^
19+
"$u=[Environment]::GetEnvironmentVariable('ChocolateyInstall','User'); if([string]::IsNullOrWhiteSpace($u)){''} else {$u}"`) do (
20+
set "CHOCOROOT=%%I"
21+
)
22+
)
23+
24+
REM Fallback: default install location (use ProgramData, not hard-coded C:)
25+
if not defined CHOCOROOT set "CHOCOROOT=%ProgramData%\Chocolatey"
26+
27+
REM If choco.exe exists there, use it
28+
if exist "%CHOCOROOT%\bin\choco.exe" set "CHOCO=%CHOCOROOT%\bin\choco.exe"
29+
30+
REM As a last resort, try PATH (doesn't break if it's already on PATH)
31+
if not defined CHOCO (
32+
for /f "delims=" %%I in ('where choco 2^>nul') do set "CHOCO=%%~fI"
33+
)
34+
35+
REM -------------------------------------------------------------
36+
REM Install Chocolatey if still not found
37+
REM -------------------------------------------------------------
38+
if not defined CHOCO (
39+
echo Chocolatey is not installed. Installing Chocolatey...
40+
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
41+
"iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"
42+
REM Re-resolve after install
43+
set "CHOCOROOT=%ProgramData%\Chocolatey"
44+
if exist "%CHOCOROOT%\bin\choco.exe" (
45+
set "CHOCO=%CHOCOROOT%\bin\choco.exe"
46+
) else (
47+
for /f "usebackq delims=" %%I in (`
48+
powershell -NoProfile -Command "[Environment]::GetEnvironmentVariable('ChocolateyInstall','Machine') ?? ''"
49+
`) do set "CHOCOROOT=%%I"
50+
if exist "%CHOCOROOT%\bin\choco.exe" set "CHOCO=%CHOCOROOT%\bin\choco.exe"
51+
)
1152
)
1253

13-
REM Check if Python is installed
14-
python --version 2>nul
15-
if %errorlevel% neq 0 (
16-
echo Python is not installed. Installing Python...
17-
choco install python -y
54+
if not exist "%CHOCO%" (
55+
echo ERROR: Could not locate choco.exe after installation.
56+
exit /b 1
57+
)
58+
59+
echo Using Chocolatey: "%CHOCO%"
60+
echo.
61+
62+
REM -------------------------------------------------------------
63+
REM Check/install Python
64+
REM -------------------------------------------------------------
65+
where python >nul 2>nul
66+
if errorlevel 1 (
67+
echo Python is not on PATH. Installing Python...
68+
"%CHOCO%" install python -y
1869
) else (
19-
echo Python is already installed.
70+
echo Python is already available.
2071
)
2172

22-
REM Check if Git is installed
23-
git --version 2>nul
24-
if %errorlevel% neq 0 (
25-
echo Git is not installed. Installing Git...
26-
choco install git.install --params "/GitAndUnixToolsOnPath /Editor:Nano /PseudoConsoleSupport /NoAutoCrlf" -y
73+
REM -------------------------------------------------------------
74+
REM Check/install Git
75+
REM -------------------------------------------------------------
76+
where git >nul 2>nul
77+
if errorlevel 1 (
78+
echo Git is not on PATH. Installing Git...
79+
"%CHOCO%" install git.install --params "/GitAndUnixToolsOnPath /Editor:Nano /PseudoConsoleSupport /NoAutoCrlf" -y
2780
) else (
28-
echo Git is already installed.
81+
echo Git is already available.
2982
)
3083

31-
REM Check if cygwin is installed
32-
cygcheck -V 2>nul
33-
if %errorlevel% neq 0 (
34-
echo cygwin is not installed. Installing cygwin...
35-
choco install cygwin -y
84+
REM -------------------------------------------------------------
85+
REM Check/install Cygwin (cygcheck in PATH means it's present)
86+
REM -------------------------------------------------------------
87+
where cygcheck >nul 2>nul
88+
if errorlevel 1 (
89+
echo Cygwin is not on PATH. Installing Cygwin...
90+
"%CHOCO%" install cygwin -y
3691
) else (
37-
echo cygwin is already installed.
92+
echo Cygwin is already available.
3893
)
3994

40-
REM Countdown from 5
95+
REM -------------------------------------------------------------
96+
REM Countdown + refresh environment in THIS window
97+
REM -------------------------------------------------------------
98+
echo.
4199
echo cloudmesh has all required dependencies. Starting in 5 seconds...
42-
43100
for /l %%i in (5,-1,1) do (
44-
echo %%i
45-
timeout /t 1 >nul
101+
echo %%i
102+
timeout /t 1 >nul
46103
)
47104

48-
refreshenv
105+
if exist "%CHOCOROOT%\bin\refreshenv.cmd" (
106+
call "%CHOCOROOT%\bin\refreshenv.cmd"
107+
) else (
108+
set "PATH=%PATH%;%CHOCOROOT%\bin"
109+
)
110+
111+
REM --- snapshot refreshed values while SETLOCAL is active ---
112+
set "PATH_SNAP=!PATH!"
113+
set "CHOCO_SNAP=%CHOCOROOT%"
114+
115+
REM --- propagate to the caller after ENDLOCAL ---
116+
ENDLOCAL & (
117+
set "PATH=%PATH_SNAP%"
118+
if not defined ChocolateyInstall set "ChocolateyInstall=%CHOCO_SNAP%"
119+
)

0 commit comments

Comments
 (0)