|
| 1 | +# Define variables |
| 2 | +$condaInstallerUrl = "https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe" |
| 3 | +$condaInstallerPath = "$env:TEMP\Miniconda3-latest-Windows-x86_64.exe" |
| 4 | +$condaPath = "$env:USERPROFILE\Miniconda3" |
| 5 | +$envName = "oi" |
| 6 | +$pythonVersion = "3.11.7" |
| 7 | +$packageName = "open-interpreter litellm openai" |
| 8 | +$desktopPath = [System.IO.Path]::Combine([System.Environment]::GetFolderPath('Desktop'), 'Open Interpreter.lnk') |
| 9 | +$condaExePath = "$condaPath\Scripts\conda.exe" |
| 10 | + |
| 11 | +# URL of the .ico file |
| 12 | +$icoUrl = "https://raw.githubusercontent.com/OpenInterpreter/open-interpreter/main/docs/assets/favicon.ico" |
| 13 | +$icoPath = "$env:TEMP\open-interpreter.ico" |
| 14 | + |
| 15 | +# Function to download a file with progress |
| 16 | +function DownloadFileWithProgress { |
| 17 | + param ( |
| 18 | + [string]$url, |
| 19 | + [string]$output |
| 20 | + ) |
| 21 | + |
| 22 | + $request = [System.Net.HttpWebRequest]::Create($url) |
| 23 | + $response = $request.GetResponse() |
| 24 | + $totalLength = $response.ContentLength |
| 25 | + $readBytes = 0 |
| 26 | + $buffer = New-Object byte[] 1024 |
| 27 | + $percentComplete = 0 |
| 28 | + |
| 29 | + $stream = $response.GetResponseStream() |
| 30 | + $fileStream = New-Object IO.FileStream ($output, [System.IO.FileMode]::Create) |
| 31 | + |
| 32 | + try { |
| 33 | + while (($read = $stream.Read($buffer, 0, $buffer.Length)) -gt 0) { |
| 34 | + $fileStream.Write($buffer, 0, $read) |
| 35 | + $readBytes += $read |
| 36 | + $newPercentComplete = [math]::Round(($readBytes / $totalLength) * 100) |
| 37 | + |
| 38 | + if ($newPercentComplete -ne $percentComplete) { |
| 39 | + $percentComplete = $newPercentComplete |
| 40 | + Write-Progress -Activity "Downloading Miniconda Installer" -Status "$percentComplete% Complete" -PercentComplete $percentComplete |
| 41 | + } |
| 42 | + } |
| 43 | + } finally { |
| 44 | + $fileStream.Close() |
| 45 | + $stream.Close() |
| 46 | + } |
| 47 | + |
| 48 | + Write-Progress -Activity "Downloading Miniconda Installer" -Completed |
| 49 | +} |
| 50 | + |
| 51 | +# Download the .ico file |
| 52 | +Write-Host "Downloading icon file..." |
| 53 | +DownloadFileWithProgress -url $icoUrl -output $icoPath |
| 54 | + |
| 55 | +# Function to check if Conda is installed |
| 56 | +function Test-CondaInstalled { |
| 57 | + try { |
| 58 | + & conda --version > $null 2>&1 |
| 59 | + return $true |
| 60 | + } catch { |
| 61 | + return $false |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +# Check if Conda is installed |
| 66 | +if (-Not (Test-CondaInstalled)) { |
| 67 | + Write-Host "Conda is not installed." |
| 68 | + |
| 69 | + # Download Miniconda installer if not already downloaded |
| 70 | + if (-Not (Test-Path $condaInstallerPath)) { |
| 71 | + DownloadFileWithProgress -url $condaInstallerUrl -output $condaInstallerPath |
| 72 | + } else { |
| 73 | + Write-Host "Miniconda installer already downloaded." |
| 74 | + } |
| 75 | + |
| 76 | + # Run the Miniconda installer with messages before and after |
| 77 | + Write-Host "Starting Miniconda installation... (there will be no progress bar)" |
| 78 | + Start-Process -Wait -FilePath $condaInstallerPath -ArgumentList "/InstallationType=JustMe", "/AddToPath=1", "/RegisterPython=0", "/S", "/D=$condaPath" |
| 79 | + Write-Host "Miniconda installation complete." |
| 80 | + |
| 81 | + # Ensure Conda is in the PATH for the current session |
| 82 | + $env:Path += ";$condaPath\Scripts;$condaPath" |
| 83 | +} else { |
| 84 | + Write-Host "Conda is already installed." |
| 85 | +} |
| 86 | + |
| 87 | +# Create and activate the Conda environment, and show progress |
| 88 | +Write-Host "Creating Conda environment '$envName'..." |
| 89 | +& $condaExePath create -n $envName python=$pythonVersion -y |
| 90 | +Write-Host "Conda environment '$envName' created." |
| 91 | + |
| 92 | +# Dynamically generate the user's paths for the shortcut |
| 93 | +$userCondaScriptsPath = "$condaPath\Scripts" |
| 94 | +$userEnvName = $envName |
| 95 | + |
| 96 | +# Create a shortcut on the desktop to activate the environment, install OpenInterpreter, and run it |
| 97 | +$targetPath = "$env:SystemRoot\System32\cmd.exe" |
| 98 | +$arguments = "/K `"$userCondaScriptsPath\activate.bat` $userEnvName && echo Updating Open Interpreter && pip install -U $packageName && cls && echo Launching Open Interpreter && interpreter`"" |
| 99 | + |
| 100 | +$shell = New-Object -ComObject WScript.Shell |
| 101 | +$shortcut = $shell.CreateShortcut($desktopPath) |
| 102 | +$shortcut.TargetPath = $targetPath |
| 103 | +$shortcut.Arguments = $arguments |
| 104 | +$shortcut.WorkingDirectory = $env:USERPROFILE |
| 105 | +$shortcut.WindowStyle = 1 # Normal window |
| 106 | +$shortcut.IconLocation = $icoPath |
| 107 | +$shortcut.Save() |
| 108 | + |
| 109 | +Write-Host "Shortcut 'Open Interpreter.lnk' has been created on the desktop with the custom icon." |
| 110 | + |
| 111 | +# Open the shortcut |
| 112 | +Start-Process -FilePath $desktopPath |
0 commit comments