SHOW:
|
|
- or go back to the newest paste.
1 | function Get-Boxstarter { | |
2 | - | # https://pastebin.com/raw/XYVDV2kn |
2 | + | # https://pastebin.com/raw/bg5pfwYK |
3 | # . { iwr -useb https://boxstarter.org/bootstrapper.ps1 } | iex; get-boxstarter -Force | |
4 | # . C:\downloads_temp\boxstarter-bootstrapper.ps1; iex Get-Boxstarter -Force | |
5 | Param( | |
6 | [string] $Version = "2.12.0", | |
7 | [switch] $Force | |
8 | ) | |
9 | if(!(Test-Admin)) { | |
10 | $bootstrapperFile = ${function:Get-Boxstarter}.File | |
11 | if($bootstrapperFile) { | |
12 | Write-Host "User is not running with administrative rights. Attempting to elevate..." | |
13 | $command = "-ExecutionPolicy bypass -noexit -command . '$bootstrapperFile';Get-Boxstarter $($args)" | |
14 | Start-Process powershell -verb runas -argumentlist $command | |
15 | } | |
16 | else { | |
17 | Write-Host "User is not running with administrative rights.`nPlease open a PowerShell console as administrator and try again." | |
18 | } | |
19 | return | |
20 | } | |
21 | ||
22 | $badPolicy = $false | |
23 | @("Restricted", "AllSigned") | ? { $_ -eq (Get-ExecutionPolicy).ToString() } | % { | |
24 | Write-Host "Your current PowerShell Execution Policy is set to '$(Get-ExecutionPolicy)' and will prohibit boxstarter from operating properly." | |
25 | Write-Host "Please use Set-ExecutionPolicy to change the policy to RemoteSigned or Unrestricted." | |
26 | $badPolicy = $true | |
27 | } | |
28 | if($badPolicy) { return } | |
29 | ||
30 | - | Write-Output "Welcome to the Boxstarter Module installer!" |
30 | + | Write-Output "Welcome to the Boxstarter Module installer -------- Lynn" |
31 | if(Check-Chocolatey -Force:$Force){ | |
32 | ||
33 | $message = "Chocolatey extensions..." | |
34 | Write-Host $message | |
35 | # configure license correctly | |
36 | # https://chocolatey.org/docs/installation-licensed | |
37 | # https://chocolatey.org/docs/features-install-directory-override | |
38 | $command = "choco install chocolatey.extension --install-directory=$env:ChocolateyToolsLocation -y" | |
39 | Invoke-Expression $command | |
40 | ||
41 | # Create python directory. Install to it. | |
42 | New-Item c:\python -Force -type directory | Out-Null | |
43 | $command = "choco install python --install-directory=c:\python -y" | |
44 | Invoke-Expression $command | |
45 | ||
46 | $command = "choco list -lo" | |
47 | Invoke-Expression $command | |
48 | ||
49 | Write-Output "Chocolatey installed, licensed, and configured. Boxstarter modules commented out." | |
50 | Write-Output "Fin" | |
51 | # Write-Output "Chocolatey installed, Installing Boxstarter Modules." | |
52 | ||
53 | # Alt+Shift, Shift+# | |
54 | # $chocoVersion = "2.9.17" | |
55 | # try { | |
56 | # New-Object -TypeName Version -ArgumentList $chocoVersion.split('-')[0] | Out-Null | |
57 | # $command = "cinst Boxstarter -y" | |
58 | # } | |
59 | # catch{ | |
60 | # # if there is no -v then its an older version with no -y | |
61 | # $command = "cinst Boxstarter" | |
62 | # } | |
63 | # $command += " --version $version" | |
64 | # Invoke-Expression $command | |
65 | # Import-Module "$env:ProgramData\boxstarter\boxstarter.chocolatey\boxstarter.chocolatey.psd1" -Force | |
66 | # $Message = "Boxstarter Module Installer completed" | |
67 | # | |
68 | ||
69 | } | |
70 | else { | |
71 | $Message = "Did not detect Chocolatey and unable to install. Installation of Boxstarter has been aborted." | |
72 | } | |
73 | if($Force) { | |
74 | Write-Host $Message | |
75 | } | |
76 | else { | |
77 | Read-Host $Message | |
78 | } | |
79 | } | |
80 | ||
81 | function Check-Chocolatey { | |
82 | Param( | |
83 | [switch] $Force | |
84 | ) | |
85 | if(-not $env:ChocolateyInstall){ | |
86 | $message = "Chocolatey environment variables and directories will be created." | |
87 | Write-Host $message | |
88 | $env:ChocolateyInstall = "c:\choco" | |
89 | ||
90 | # [System.Environment]::SetEnvironmentVariable('Z_TEST', '001', [System.EnvironmentVariableTarget]::Machine) | |
91 | ||
92 | $env:ChocolateyLicenseDir = "c:\choco\license" | |
93 | $env:ChocolateyToolsLocation = "c:\ctools" | |
94 | New-Item $env:ChocolateyInstall -Force -type directory | Out-Null | |
95 | New-Item $env:ChocolateyLicenseDir -Force -type directory | Out-Null | |
96 | New-Item $env:ChocolateyToolsLocation -Force -type directory | Out-Null | |
97 | # Copy chocolatey license file | |
98 | Copy-Item -Path C:\downloads_temp\chocolatey.license.xml -Destination $env:ChocolateyLicenseDir | |
99 | # Directories exist and license is in correct place | |
100 | } | |
101 | ||
102 | if(-not $env:ChocolateyInstall -or -not (Test-Path "$env:ChocolateyInstall\bin\choco.exe")){ | |
103 | ||
104 | $message = "Chocolatey not installed. Also .NET Framework Version 4 or greater." | |
105 | Write-Host $message | |
106 | if($Force -OR (Confirm-Install)){ | |
107 | $exitCode = Enable-Net40 | |
108 | if($exitCode -ne 0) { | |
109 | Write-Warning ".net install returned $exitCode. You likely need to reboot your computer before proceeding with the install." | |
110 | return $false | |
111 | } | |
112 | ||
113 | $message = "Chocolatey downloading..." | |
114 | Write-Host $message | |
115 | $url="https://chocolatey.org/api/v2/package/chocolatey/" | |
116 | $wc=new-object net.webclient | |
117 | $wp=[system.net.WebProxy]::GetDefaultProxy() | |
118 | $wp.UseDefaultCredentials=$true | |
119 | $wc.Proxy=$wp | |
120 | ||
121 | $message = "Chocolatey installing..." | |
122 | Write-Host $message | |
123 | # install chocolatey | |
124 | iex ($wc.DownloadString("https://chocolatey.org/install.ps1")) | |
125 | ||
126 | $message = "Chocolatey added to bin.." | |
127 | Write-Host $message | |
128 | # add to path | |
129 | $env:path="$env:path;$env:ChocolateyInstall\bin" | |
130 | Write-Host "env: $env:path" | |
131 | ||
132 | } | |
133 | else{ | |
134 | return $false | |
135 | } | |
136 | } | |
137 | return $true | |
138 | } | |
139 | ||
140 | function Is64Bit { [IntPtr]::Size -eq 8 } | |
141 | ||
142 | function Enable-Net40 { | |
143 | if(Is64Bit) {$fx="framework64"} else {$fx="framework"} | |
144 | if(!(test-path "$env:windir\Microsoft.Net\$fx\v4.0.30319")) { | |
145 | Write-Host "Downloading .net 4.5..." | |
146 | Get-HttpToFile "https://download.microsoft.com/download/b/a/4/ba4a7e71-2906-4b2d-a0e1-80cf16844f5f/dotnetfx45_full_x86_x64.exe" "$env:temp\net45.exe" | |
147 | Write-Host "Installing .net 4.5..." | |
148 | $pinfo = New-Object System.Diagnostics.ProcessStartInfo | |
149 | $pinfo.FileName = "$env:temp\net45.exe" | |
150 | $pinfo.Verb="runas" | |
151 | $pinfo.Arguments = "/quiet /norestart /log $env:temp\net45.log" | |
152 | $p = New-Object System.Diagnostics.Process | |
153 | $p.StartInfo = $pinfo | |
154 | $p.Start() | Out-Null | |
155 | $p.WaitForExit() | |
156 | $e = $p.ExitCode | |
157 | if($e -ne 0){ | |
158 | Write-Host "Installer exited with $e" | |
159 | } | |
160 | return $e | |
161 | } | |
162 | return 0 | |
163 | } | |
164 | ||
165 | function Get-HttpToFile ($url, $file){ | |
166 | Write-Verbose "Downloading $url to $file" | |
167 | if(Test-Path $file){Remove-Item $file -Force} | |
168 | $downloader=new-object net.webclient | |
169 | $wp=[system.net.WebProxy]::GetDefaultProxy() | |
170 | $wp.UseDefaultCredentials=$true | |
171 | $downloader.Proxy=$wp | |
172 | try { | |
173 | $downloader.DownloadFile($url, $file) | |
174 | } | |
175 | catch{ | |
176 | if($VerbosePreference -eq "Continue"){ | |
177 | Write-Error $($_.Exception | fl * -Force | Out-String) | |
178 | } | |
179 | throw $_ | |
180 | } | |
181 | } | |
182 | ||
183 | function Confirm-Install { | |
184 | $caption = "Installing Chocolatey" | |
185 | $message = "Do you want to proceed?" | |
186 | $yes = new-Object System.Management.Automation.Host.ChoiceDescription "&Yes","Yes"; | |
187 | $no = new-Object System.Management.Automation.Host.ChoiceDescription "&No","No"; | |
188 | $choices = [System.Management.Automation.Host.ChoiceDescription[]]($yes,$no); | |
189 | $answer = $host.ui.PromptForChoice($caption,$message,$choices,0) | |
190 | ||
191 | switch ($answer){ | |
192 | 0 {return $true; break} | |
193 | 1 {return $false; break} | |
194 | } | |
195 | } | |
196 | ||
197 | function Test-Admin { | |
198 | $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent() | |
199 | $principal = New-Object System.Security.Principal.WindowsPrincipal( $identity ) | |
200 | return $principal.IsInRole( [System.Security.Principal.WindowsBuiltInRole]::Administrator ) | |
201 | } |