diff --git a/README.md b/README.md index 82e7459..3b7ea79 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # Python-Environment-Setup -This script will setup Miniconda, Visual Studio Code, and Git for you \ No newline at end of file +This script will setup Miniconda, Visual Studio Code, and Git for you + +To run this setup script, from a command line, change to the directory that contains the script and run `powershell -File .\setup.ps1` diff --git a/setup.ps1 b/setup.ps1 index b731554..693d248 100644 --- a/setup.ps1 +++ b/setup.ps1 @@ -4,33 +4,28 @@ $cur_compat_mode = Get-ItemProperty -Path $reg_path -Name IntranetCompatibilityM New-ItemProperty -Path $reg_path -Name IntranetCompatibilityMode -Value 0 -Force | Out-Null #now that compatibility mode is off temporarily, we can scrape the web -$default_install_paths = $HOME, $env:LOCALAPPDATA, $env:ProgramFiles +$default_install_paths = $HOME, $env:ProgramFiles -$conda_installed = $default_install_paths | ForEach-Object -Process { Get-ChildItem | Where-Object -Property "Name" -Like -Value "*conda*" } +Write-Host "Checking for existing installations of Anaconda or Miniconda. This may take a few minutes..." +$conda_installed = $default_install_paths | ForEach-Object -Process {Get-ChildItem -Recurse -File -Force -Filter conda.exe -ErrorAction SilentlyContinue | Select-Object -First 1} -$install_miniconda = -not $conda_installed +$install_miniconda = -Not $conda_installed if ($conda_installed) { write-host " - Found some files that indicate you may already have an Anaconda/Miniconda environment installed. - - $($default_install_paths | - ForEach-Object -Process {Get-ChildItem | - Where-Object -Property "Name" -Like -Value "*conda*" | - ForEach-Object -Process {$_.FullName | - ForEach-Object -Process {$_ + "`n "} - } - } - ) - + You appear to have Anaconda or Miniconda installed already. Installing Miniconda on top of it may have unintended side-effects of breaking your existing installation. " $user_input = (Read-Host -Prompt "Continue Installation of Miniconda anyway? [yes|(no)] ").ToLower() $install_miniconda = ("y","yes") -contains $user_input } +else{ + Write-Host "No Anaconda or Miniconda installation detected.`n" +} if ($install_miniconda) { #Setup Miniconda + Write-Host "Installing Miniconda...`n`n" $miniconda_url = "https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe" $miniconda_installer = $miniconda_url.split('/')[-1] @@ -44,10 +39,25 @@ if ($install_miniconda) { Invoke-Expression "& $conda_exe init --all" } -#Setup Visual Studio Code -$vscode_url = "https://aka.ms/win32-x64-user-stable" +if (-Not (Test-Path "$HOME\AppData\Local\Programs\Microsoft VS Code\Code.exe")){ + #Setup Visual Studio Code + Write-Host "Installing Microsoft Visual Studio Code...`n`n" + $vscode_url = "https://aka.ms/win32-x64-user-stable" + ((Invoke-WebRequest -Method Head $vscode_url).Headers["Content-Disposition"]) -match '"(.+)"' | Out-Null + $vscode_installer = $Matches[1] + Invoke-WebRequest $vscode_url -OutFile $vscode_installer + Invoke-Expression "& .\$vscode_installer /VERYSILENT /LOADINF=.\vscode.inf" +} -$git_url = Invoke-WebRequest "https://git-scm.com/download/win" | Select-Object -ExpandProperty Links | Where-Object innerText -like "64-bit Git for Windows Setup" | Select-Object -ExpandProperty href -$git_installer = $git_url.split('/')[-1] -Invoke-WebRequest $git_url -OutFile $git_installer -Invoke-Expression "& .\$git_installer /VERYSILENT /LOADINF=.\git.inf" + + +if ((Test-Path "$env:LOCALAPPDATA\Programs\Git\bin\git.exe") -or (Test-Path "$env:ProgramFiles\Git\bin\git.exe")){ + Write-Host "Installing Git...`n`n" + $git_url = Invoke-WebRequest "https://git-scm.com/download/win" | Select-Object -ExpandProperty Links | Where-Object innerText -like "64-bit Git for Windows Setup" | Select-Object -ExpandProperty href + $git_installer = $git_url.split('/')[-1] + Invoke-WebRequest $git_url -OutFile $git_installer + Invoke-Expression "& .\$git_installer /VERYSILENT /LOADINF=.\git.inf" +} + +#restore IE compatibility mode setting +New-ItemProperty -Path $reg_path -Name IntranetCompatibilityMode -Value $cur_compat_mode -Force | Out-Null diff --git a/vscode.inf b/vscode.inf new file mode 100644 index 0000000..20afa5c --- /dev/null +++ b/vscode.inf @@ -0,0 +1,6 @@ +[Setup] +Lang=english +Dir=%LOCALAPPDATA%\Programs\Microsoft VS Code +Group=Visual Studio Code +NoIcons=0 +Tasks=desktopicon,addcontextmenufiles,addcontextmenufolders,associatewithfiles,addtopath