Skip to content

Commit

Permalink
improve windows scripts (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Mar 10, 2023
1 parent 5b50831 commit 4b94eba
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 5 deletions.
41 changes: 39 additions & 2 deletions install.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
RELEASE_URL="https://github.com/mamba-org/micromamba-releases/releases/latest/download/micromamba-win-64"
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"

REM Download micromamba using curl.exe
curl.exe -L -o micromamba.exe %RELEASE_URL%
Expand All @@ -7,4 +13,35 @@ REM Create a directory for micromamba
MKDIR %LOCALAPPDATA%\micromamba

REM Move micromamba.exe to the final directory
MOVE /Y micromamba.exe %LOCALAPPDATA%\micromamba\micromamba.exe
MOVE /Y micromamba.exe %LOCALAPPDATA%\micromamba\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
)

@REM REM Ask user if micromamba should be added to the PATH
@REM ECHO Add micromamba to the PATH?
@REM ECHO y) Yes
@REM ECHO n) No
@REM SET /P ADD_TO_PATH="Enter your choice: "

@REM REM check if add to path is either y or Y (case insensitive)
@REM if "%ADD_TO_PATH:~0,1%"=="y" (
@REM REM Add micromamba to the PATH
@REM echo Adding micromamba to the PATH
@REM setx PATH "%PATH%;%LOCALAPPDATA%\micromamba"
@REM )

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
)
43 changes: 40 additions & 3 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
$RELEASE_URL="https://github.com/mamba-org/micromamba-releases/releases/latest/download/micromamba-win-64"
# 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"

Write-Output "Downloading micromamba from $RELEASE_URL"
curl.exe -L -o micromamba.exe $RELEASE_URL

New-Item -ItemType Directory -Force -Path $Env:LocalAppData\micromamba
New-Item -ItemType Directory -Force -Path $Env:LocalAppData\micromamba | out-null

$MAMBA_INSTALL_PATH = Join-Path -Path $Env:LocalAppData -ChildPAth micromamba\micromamba.exe

Write-Output "`nInstalling micromamba to $Env:LocalAppData\micromamba`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*") {
Write-Output "Adding $MAMBA_INSTALL_PATH to PATH`n"
[Environment]::SetEnvironmentVariable("Path", "$Env:LocalAppData\micromamba;" + [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
}

$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)"
if ($prefix -eq "") {
$prefix = "$Env:UserProfile\micromamba"
}

Move-Item -Force micromamba.exe $Env:LocalAppData\micromamba\micromamba.exe
Write-Output "Initializing micromamba in $prefix"
$MAMBA_INSTALL_PATH = Join-Path -Path $Env:LocalAppData -ChildPAth micromamba\micromamba.exe
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"
}

0 comments on commit 4b94eba

Please sign in to comment.