From cad6db3b9a198c10bbb72cb86ad5be49471419ad Mon Sep 17 00:00:00 2001 From: jpfleischer <70083705+jpfleischer@users.noreply.github.com> Date: Fri, 12 Sep 2025 18:05:28 -0400 Subject: [PATCH 1/5] Update Shell.py --- src/cloudmesh/common/Shell.py | 41 ++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/cloudmesh/common/Shell.py b/src/cloudmesh/common/Shell.py index 18b2676..51cedbb 100755 --- a/src/cloudmesh/common/Shell.py +++ b/src/cloudmesh/common/Shell.py @@ -27,6 +27,7 @@ from cloudmesh.common.util import path_expand from cloudmesh.common.util import readfile from cloudmesh.common.util import writefile +from cloudmesh.common.util import yn_choice from tqdm import tqdm import shlex @@ -613,6 +614,24 @@ def install_chocolatey(): Console.error("Please run the terminal as administrator.") return False + # is this a good idea? + #see if chocolatey exists. + programdata = os.environ.get("ProgramData", r"C:\ProgramData") + target = os.path.join(programdata, "chocolatey") + # Safety guard: only allow deletes inside ProgramData + pd_abs = os.path.abspath(programdata) + tgt_abs = os.path.abspath(target) + if not tgt_abs.lower().startswith(pd_abs.lower()): + sys.exit("Refusing to delete a path outside ProgramData.") + if os.path.isdir(target): + if yn_choice("Chocolatey seems to exist already! Delete it?"): + shutil.rmtree(tgt_abs) + else: + sys.exit("Not deleting chocolatey because the user said not to.") + # + # + # + # Get the full path of the current Python script current_script_path = os.path.abspath(__file__) @@ -1044,16 +1063,18 @@ def live(cls, command, cwd=None): process = subprocess.Popen( shlex.split(command), cwd=cwd, stdout=subprocess.PIPE ) - - output_lines = [] - for line in iter(process.stdout.readline, b''): - sys.stdout.write(line.decode("utf-8")) - sys.stdout.flush() - output_lines.append(line) - - rc = process.wait() - full_output = b"".join(output_lines).decode("utf-8") - return dotdict({"status": rc, "text": full_output}) + result = b"" + while True: + output = process.stdout.read(1) + if output == b"" and process.poll() is not None: + break + if output: + result = result + output + sys.stdout.write(output.decode("utf-8")) + sys.stdout.flush() + rc = process.poll() + data = dotdict({"status": rc, "text": output.decode("utf-8")}) + return data @staticmethod def calculate_disk_space(directory): From 8fb50274987bcd0826033ba37618cd2d6e28470c Mon Sep 17 00:00:00 2001 From: jpfleischer <70083705+jpfleischer@users.noreply.github.com> Date: Fri, 12 Sep 2025 18:19:57 -0400 Subject: [PATCH 2/5] Update Shell.py --- src/cloudmesh/common/Shell.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/cloudmesh/common/Shell.py b/src/cloudmesh/common/Shell.py index 51cedbb..09fbced 100755 --- a/src/cloudmesh/common/Shell.py +++ b/src/cloudmesh/common/Shell.py @@ -1063,18 +1063,16 @@ def live(cls, command, cwd=None): process = subprocess.Popen( shlex.split(command), cwd=cwd, stdout=subprocess.PIPE ) - result = b"" - while True: - output = process.stdout.read(1) - if output == b"" and process.poll() is not None: - break - if output: - result = result + output - sys.stdout.write(output.decode("utf-8")) - sys.stdout.flush() - rc = process.poll() - data = dotdict({"status": rc, "text": output.decode("utf-8")}) - return data + + output_lines = [] + for line in iter(process.stdout.readline, b''): + sys.stdout.write(line.decode("utf-8")) + sys.stdout.flush() + output_lines.append(line) + + rc = process.wait() + full_output = b"".join(output_lines).decode("utf-8") + return dotdict({"status": rc, "text": full_output}) @staticmethod def calculate_disk_space(directory): From 5cb3dfac72769b1ae329cc44ac9e0d6190d1bfcb Mon Sep 17 00:00:00 2001 From: jpfleischer <70083705+jpfleischer@users.noreply.github.com> Date: Fri, 12 Sep 2025 20:20:33 -0400 Subject: [PATCH 3/5] Update Shell.py --- src/cloudmesh/common/Shell.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/cloudmesh/common/Shell.py b/src/cloudmesh/common/Shell.py index 09fbced..9a6aacc 100755 --- a/src/cloudmesh/common/Shell.py +++ b/src/cloudmesh/common/Shell.py @@ -613,24 +613,6 @@ def install_chocolatey(): if not pyuac.isUserAdmin(): Console.error("Please run the terminal as administrator.") return False - - # is this a good idea? - #see if chocolatey exists. - programdata = os.environ.get("ProgramData", r"C:\ProgramData") - target = os.path.join(programdata, "chocolatey") - # Safety guard: only allow deletes inside ProgramData - pd_abs = os.path.abspath(programdata) - tgt_abs = os.path.abspath(target) - if not tgt_abs.lower().startswith(pd_abs.lower()): - sys.exit("Refusing to delete a path outside ProgramData.") - if os.path.isdir(target): - if yn_choice("Chocolatey seems to exist already! Delete it?"): - shutil.rmtree(tgt_abs) - else: - sys.exit("Not deleting chocolatey because the user said not to.") - # - # - # # Get the full path of the current Python script current_script_path = os.path.abspath(__file__) From 2d5ca91ee8f9e4dd4db4ac9eba23ce343bc90604 Mon Sep 17 00:00:00 2001 From: jpfleischer <70083705+jpfleischer@users.noreply.github.com> Date: Fri, 12 Sep 2025 20:22:16 -0400 Subject: [PATCH 4/5] Update Shell.py --- src/cloudmesh/common/Shell.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cloudmesh/common/Shell.py b/src/cloudmesh/common/Shell.py index 9a6aacc..18b2676 100755 --- a/src/cloudmesh/common/Shell.py +++ b/src/cloudmesh/common/Shell.py @@ -27,7 +27,6 @@ from cloudmesh.common.util import path_expand from cloudmesh.common.util import readfile from cloudmesh.common.util import writefile -from cloudmesh.common.util import yn_choice from tqdm import tqdm import shlex @@ -613,7 +612,7 @@ def install_chocolatey(): if not pyuac.isUserAdmin(): Console.error("Please run the terminal as administrator.") return False - + # Get the full path of the current Python script current_script_path = os.path.abspath(__file__) From a214a3ba12caa280419bdc49f3ef983b93abb08a Mon Sep 17 00:00:00 2001 From: jpfleischer <70083705+jpfleischer@users.noreply.github.com> Date: Fri, 12 Sep 2025 20:22:50 -0400 Subject: [PATCH 5/5] Update win-setup.bat --- src/cloudmesh/common/bin/win-setup.bat | 133 +++++++++++++++++++------ 1 file changed, 102 insertions(+), 31 deletions(-) diff --git a/src/cloudmesh/common/bin/win-setup.bat b/src/cloudmesh/common/bin/win-setup.bat index ef67a2f..ee80851 100644 --- a/src/cloudmesh/common/bin/win-setup.bat +++ b/src/cloudmesh/common/bin/win-setup.bat @@ -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%" +)