Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If MAMBA_ROOT_PREFIX defined use that instead of local appdata #35

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
58 changes: 43 additions & 15 deletions install.bat
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
@ECHO OFF
SETLOCAL
REM Check if environment variable VERSION is set
if "%VERSION%"=="" (
REM If not, set it to "latest"
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 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
Expand All @@ -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
)
@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%
)
41 changes: 24 additions & 17 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -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"
}
& $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"
}