From a2e2acfbded5dd0f655b112f39ba452e8c52a5a0 Mon Sep 17 00:00:00 2001 From: alexpolo1 Date: Wed, 5 Aug 2026 17:07:50 +0200 Subject: [PATCH] fix(install): install conda without admin + verify git download install.bat could fail to auto-install conda on a fresh, non-admin machine: - winget install used the default (machine) scope, landing conda in %ProgramData% and requiring elevation. A normal double-click without admin failed silently and conda never installed. Add --scope user so it installs to %USERPROFILE%\miniforge3 with no admin needed. - winget returns non-zero when the package is already present, so its exit code was unreliable. Rescan for conda.exe after winget and only fall through to the direct download when it is genuinely missing. - The GitHub (git) download fallback never validated the file before running it: a truncated download or an HTML error page served with a 200 would be launched as the "installer" and silently do nothing. Add a size check (<40 MB => failed download, clear error + bail) plus a pre-download cleanup of any stale temp file. Co-Authored-By: Claude Opus 4.8 --- install.bat | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/install.bat b/install.bat index af9ca9e..37c3c3d 100644 --- a/install.bat +++ b/install.bat @@ -59,13 +59,25 @@ echo This is a one-time setup (~100 MB). Please wait. echo. :: --- Method 1: winget (cleanest; available on Win10 1709+ and all Win11) --- +:: --scope user is critical: without it winget defaults to a machine-wide +:: install (lands in %ProgramData%) which REQUIRES admin. A normal double-click +:: (no elevation) then fails silently and conda never installs. --scope user +:: installs to %USERPROFILE%\miniforge3 with no admin needed — which is also one +:: of the locations :rescan_conda searches. winget --version >nul 2>&1 if %errorlevel% equ 0 ( echo Installing via winget... - winget install --id CondaForge.Miniforge3 --exact --silent ^ + winget install --id CondaForge.Miniforge3 --exact --silent --scope user ^ --accept-package-agreements --accept-source-agreements - if !errorlevel! equ 0 goto :rescan_conda - echo winget install failed — falling back to direct download. + :: winget returns non-zero when the package is already installed, so don't + :: trust the exit code — rescan for conda and only fall through to the + :: direct download if it's genuinely still missing. + for %%C in ( + "%LOCALAPPDATA%\miniforge3\Scripts\conda.exe" + "%USERPROFILE%\miniforge3\Scripts\conda.exe" + "%ProgramData%\miniforge3\Scripts\conda.exe" + ) do if exist %%C goto :rescan_conda + echo winget did not produce a usable conda — falling back to direct download. echo. ) @@ -78,6 +90,7 @@ if %errorlevel% equ 0 ( set "MF_INSTALLER=%TEMP%\Miniforge3-installer.exe" set "MF_URL=https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Windows-x86_64.exe" +del /q "%MF_INSTALLER%" >nul 2>&1 echo Downloading Miniforge3... curl -Lk --progress-bar "%MF_URL%" -o "%MF_INSTALLER%" 2>&1 if %errorlevel% neq 0 ( @@ -95,6 +108,23 @@ if not exist "%MF_INSTALLER%" ( exit /b 1 ) +:: Verify the download is a real installer, not a truncated file or an HTML +:: error page served with a 200. The Miniforge installer is ~78 MB; anything +:: under 40 MB means the download failed even though a file exists. +for %%A in ("%MF_INSTALLER%") do set "MF_SIZE=%%~zA" +if not defined MF_SIZE set "MF_SIZE=0" +if %MF_SIZE% LSS 41943040 ( + echo. + echo ERROR: Downloaded Miniforge3 installer is only %MF_SIZE% bytes — the + echo download was incomplete or blocked. Check your internet/proxy, or install + echo manually then re-run install.bat: + echo https://github.com/conda-forge/miniforge/releases/latest + echo. + del /q "%MF_INSTALLER%" >nul 2>&1 + pause + exit /b 1 +) + echo Installing Miniforge3 (this takes ~1 minute)... start /wait "" "%MF_INSTALLER%" /S /InstallationType=JustMe /AddToPath=0 /RegisterPython=0 /NoShortcuts=1 /NoRegistry=1 if %errorlevel% neq 0 (