From a9f1fe6cde94e23c346252a98328c11c11a4926c Mon Sep 17 00:00:00 2001 From: Matt Wilkie Date: Tue, 30 Jan 2024 13:41:01 -0700 Subject: [PATCH 1/2] bug fix: missing assignment command --- install.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.bat b/install.bat index 3cd3684..70d8f67 100644 --- a/install.bat +++ b/install.bat @@ -4,7 +4,7 @@ if "%VERSION%"=="" ( SET VERSION=latest ) -RELEASE_URL="https://github.com/mamba-org/micromamba-releases/releases/%VERSION%/download/micromamba-win-64" +SET RELEASE_URL="https://github.com/mamba-org/micromamba-releases/releases/%VERSION%/download/micromamba-win-64" REM Download micromamba using curl.exe curl.exe -L -o micromamba.exe %RELEASE_URL% From 82f84fb65ad067a968aea3e65434e9941ebdf2b4 Mon Sep 17 00:00:00 2001 From: Matt Wilkie Date: Tue, 30 Jan 2024 14:11:46 -0700 Subject: [PATCH 2/2] for Honour MAMBA_ROOT_PREFIX? #34 --- install.bat | 56 +++++++++++++++++++++++++++++++++++++++-------------- install.ps1 | 41 +++++++++++++++++++++++---------------- 2 files changed, 66 insertions(+), 31 deletions(-) diff --git a/install.bat b/install.bat index 70d8f67..8a061bc 100644 --- a/install.bat +++ b/install.bat @@ -1,3 +1,5 @@ +@ECHO OFF +SETLOCAL REM Check if environment variable VERSION is set if "%VERSION%"=="" ( REM If not, set it to "latest" @@ -6,19 +8,34 @@ if "%VERSION%"=="" ( SET RELEASE_URL="https://github.com/mamba-org/micromamba-releases/releases/%VERSION%/download/micromamba-win-64" +REM If MAMBA_ROOT_PREFIX is defined, use it as install location +if DEFINED MAMBA_ROOT_PREFIX ( + SET _installPath=%MAMBA_ROOT_PREFIX% + SET _profilePath=%MAMBA_ROOT_PREFIX% +) else ( + SET _installPath=%LOCALAPPDATA%\micromamba + SET _profilePath=%USERPROFILE%\micromamba +) + +REM Report var values +SET VERSION +SET RELEASE_URL +SET _installPath +SET _profilePath + REM Download micromamba using curl.exe curl.exe -L -o micromamba.exe %RELEASE_URL% REM Create a directory for micromamba -MKDIR %LOCALAPPDATA%\micromamba +MKDIR %_installPath% REM Move micromamba.exe to the final directory -MOVE /Y micromamba.exe %LOCALAPPDATA%\micromamba\micromamba.exe +MOVE /Y micromamba.exe %_installPath%\micromamba.exe REM check if this is an interactive shell if "%PROMPT%"=="" ( - echo Initializing micromamba in %USERPROFILE%\micromamba - %LOCALAPPDATA%\micromamba\micromamba.exe init -p %USERPROFILE%\micromamba + echo Initializing micromamba in %_profilePath% + %_installPath%\micromamba.exe init -p %_profilePath% ) @REM REM Ask user if micromamba should be added to the PATH @@ -34,14 +51,25 @@ if "%PROMPT%"=="" ( @REM setx PATH "%PATH%;%LOCALAPPDATA%\micromamba" @REM ) +:: Choice is probably the safer method, as it only allows a single keypress REM Ask user if micromamba should be initialized -ECHO Initialize micromamba? -ECHO y) Yes (default) -ECHO n) No -SET /P INITIALIZE="Enter your choice: " - -if "%INITIALIZE:~0,1%"=="y" || "%INITIALIZE"=="" ( - REM Initialize micromamba - echo Initializing micromamba in %USERPROFILE%\micromamba - %LOCALAPPDATA%\micromamba\micromamba.exe init -p %USERPROFILE%\micromamba -) \ No newline at end of file +@REM ECHO Initialize micromamba? +@REM ECHO y) Yes (default) +@REM ECHO n) No +@REM SET /P INITIALIZE="Enter your choice: " + +@REM if "%INITIALIZE:~0,1%"=="y" || "%INITIALIZE"=="" ( +@REM REM Initialize micromamba +@REM echo Initializing micromamba in %_profilePath% +@REM %_installPath%\micromamba.exe init -p %_profilePath% +@REM ) + +:init +choice /N /M "Initialize micromamba? (y/n) " +if errorlevel 2 ( + ECHO Skipped initialization + goto :EOF +) else ( + ECHO Initializing micromamba in %_profilePath% + %_installPath%\micromamba.exe shell init -p %_profilePath% +) diff --git a/install.ps1 b/install.ps1 index 3c61c6f..60b7426 100644 --- a/install.ps1 +++ b/install.ps1 @@ -1,44 +1,51 @@ # check if VERSION env variable is set, otherwise use "latest" $VERSION = if ($null -eq $Env:VERSION) { "latest" } else { $Env:VERSION } -$RELEASE_URL="https://github.com/mamba-org/micromamba-releases/releases/$VERSION/download/micromamba-win-64" +$RELEASE_URL = "https://github.com/mamba-org/micromamba-releases/releases/$VERSION/download/micromamba-win-64" Write-Output "Downloading micromamba from $RELEASE_URL" curl.exe -L -o micromamba.exe $RELEASE_URL -New-Item -ItemType Directory -Force -Path $Env:LocalAppData\micromamba | out-null +# check if MAMBA_ROOT_PREFIX env variable is set, otherwise use Local AppData and UserProfile +$installPath = if ($null -eq $Env:MAMBA_ROOT_PREFIX) { "$Env:LocalAppData\micromamba" } else { $Env:MAMBA_ROOT_PREFIX } +$profilePath = if ($null -eq $Env:MAMBA_ROOT_PREFIX) { "$Env:UserProfile\micromamba" } else { $Env:MAMBA_ROOT_PREFIX } -$MAMBA_INSTALL_PATH = Join-Path -Path $Env:LocalAppData -ChildPAth micromamba\micromamba.exe +if (!(Test-Path $installPath)) { + New-Item -ItemType Directory -Force -Path $installPath | out-null +} + +$MAMBA_INSTALL_PATH = Join-Path -Path $installPath -ChildPAth micromamba.exe -Write-Output "`nInstalling micromamba to $Env:LocalAppData\micromamba`n" +Write-Output "`nInstalling micromamba to $installPath`n" Move-Item -Force micromamba.exe $MAMBA_INSTALL_PATH | out-null # Add micromamba to PATH if the folder is not already in the PATH variable $PATH = [Environment]::GetEnvironmentVariable("Path", "User") -if ($PATH -notlike "*$Env:LocalAppData\micromamba*") { +if ($PATH -notlike "*$installPath*") { Write-Output "Adding $MAMBA_INSTALL_PATH to PATH`n" - [Environment]::SetEnvironmentVariable("Path", "$Env:LocalAppData\micromamba;" + [Environment]::GetEnvironmentVariable("Path", "User"), "User") -} else { + [Environment]::SetEnvironmentVariable("Path", "$installPath;" + [Environment]::GetEnvironmentVariable("Path", "User"), "User") +} +else { Write-Output "$MAMBA_INSTALL_PATH is already in PATH`n" } # check if this is an interactive session if ($null -eq $Host.UI.RawUI) { - Write-Output "`nNot an interactive session, initializing micromamba to $Env:UserProfile\micromamba`n" - & $MAMBA_INSTALL_PATH shell init -s powershell -p $Env:UserProfile\micromamba + Write-Output "`nNot an interactive session, initializing micromamba to $profilePath`n" + & $MAMBA_INSTALL_PATH shell init -s powershell -p $profilePath } $choice = Read-Host "Do you want to initialize micromamba for the shell activate command? (Y/n)" if ($choice -eq "y" -or $choice -eq "Y" -or $choice -eq "") { - $prefix = Read-Host "Enter the path to the micromamba prefix (default: $Env:UserProfile\micromamba)" + $prefix = Read-Host "Enter the path to the micromamba prefix (default: $profilePath)" if ($prefix -eq "") { - $prefix = "$Env:UserProfile\micromamba" + $prefix = "$profilePath" } - Write-Output "Initializing micromamba in $prefix" - $MAMBA_INSTALL_PATH = Join-Path -Path $Env:LocalAppData -ChildPAth micromamba\micromamba.exe + Write-Output "Initializing micromamba in $prefix" Write-Output $MAMBA_INSTALL_PATH - & $MAMBA_INSTALL_PATH shell init -s powershell -p $Env:UserProfile\micromamba -} else { - Write-Output "`nYou can always initialize powershell pr cmd.exe with micromamba by running `nmicromamba shell init -s powershell -p $Env:UserProfile\micromamba`n" -} \ No newline at end of file + & $MAMBA_INSTALL_PATH shell init -s powershell -p $profilePath +} +else { + Write-Output "`nYou can always initialize powershell pr cmd.exe with micromamba by running `nmicromamba shell init -s powershell -p $profilePath`n" +}