@@ -15,8 +15,9 @@ $IDT_INSTALL_BMX_URL="https://clis.ng.bluemix.net/install"
1515$IDT_INSTALL_BMX_REPO_NAME = " Bluemix"
1616$IDT_INSTALL_BMX_REPO_URL = " https://plugins.ng.bluemix.net"
1717
18- $FORCE = 0
19- $NEEDS_REBOOT = 0
18+ $Global :FORCE = $false
19+ $Global :NEEDS_REBOOT = $false
20+ $Global :SECS = 0
2021
2122# ------------------------------------------------------------------------------
2223function help {
@@ -67,26 +68,45 @@ function error() {
6768 quit
6869}
6970
71+ # ------------------------------------------------------------------------------
7072function quit () {
71- # If running in the console, wait for input before closing.
72- if ($Host.Name -eq " ConsoleHost" ) {
73- Write-Host " Press any key to continue..."
74- $Host.UI.RawUI.FlushInputBuffer () # Make sure buffered input doesn't "press a key" and skip the ReadKey().
75- $Host.UI.RawUI.ReadKey (" NoEcho,IncludeKeyUp" ) > $null
73+ $Global :SECS = (Get-Date )- $Global :SECS
74+ log " --==[ Finished. Total time: $ ( $Global :SECS.ToString (" hh\:mm\:ss" )) seconds ]==--"
75+ Write-Host " "
76+
77+ # -- Request Restart to save changes to PATH.
78+ if ( $Global :NEEDS_REBOOT ) {
79+ $restart = Read-Host - Prompt " A system restart is required. Would you like to restart now (y/N)?"
80+ if ($restart -match " [Yy]" ) {
81+ Restart-Computer
82+ } else {
83+ Write-Host " Note: Reboot still needed to load env variables."
84+ }
85+ } else {
86+ # If running in the console, wait for input before closing.
87+ if ($Host.Name -eq " ConsoleHost" ) {
88+ Write-Host " Press any key to continue..."
89+ $Host.UI.RawUI.FlushInputBuffer () # Make sure buffered input doesn't "press a key" and skip the ReadKey().
90+ $Host.UI.RawUI.ReadKey (" NoEcho,IncludeKeyUp" ) > $null
91+
92+ # -- turn opff trace
93+ Set-PSDebug - Trace 0
94+ }
7695 }
7796}
7897
7998# ------------------------------------------------------------------------------
8099function uninstall () {
81100 warn " Starting Uninstall..."
82- Write-Output
83- $reply = Read-Host - Prompt " Are you sure you want to remove IDT and IBM Cloud CLI (Y/n)?"
84- Write-Output
85- if ($reply -match " [Yy]*" ) {
101+ Write-Output " "
102+ $reply = Read-Host - Prompt " Are you sure you want to remove IDT and IBM Cloud CLI (y/N)?"
103+ Write-Output " "
104+ if ($reply -match " [Yy]" ) {
105+ log " Uninstalling IDT..."
86106 log " Deleting: C:\Program Files\IBM\Bluemix"
87- Remove-Item - Recurse - Force " C:\Program Files\IBM\Bluemix"
107+ Remove-Item - Recurse - Force " C:\Program Files\IBM\Bluemix" - erroraction ' silentlycontinue '
88108 log " Deleting: ~/.bluemix"
89- Remove-Item - Recurse - Force ~/ .bluemix
109+ Remove-Item - Recurse - Force ~/ .bluemix - erroraction ' silentlycontinue '
90110 log " Uninstall complete."
91111 } else {
92112 log " Uninstall cancelled at user request"
@@ -119,13 +139,6 @@ function install() {
119139
120140 log " Install finished."
121141
122- # -- Request Restart to save changes to PATH.
123- if ($NEEDS_REBOOT -eq 1 ) {
124- $restart = Read-Host " A system restart is required. Would you like to restart now (y/N)?"
125- if ($restart -match " [Yy]*" ) {
126- Restart-Computer
127- }
128- }
129142}
130143
131144
@@ -135,71 +148,78 @@ function install_deps() {
135148
136149 # -- git
137150 log " Checking for external dependency: git"
138- if ( -not (get-command git - erroraction ' silentlycontinue' ) -or $FORCE -eq 1 ) {
151+ if ( -not (get-command git - erroraction ' silentlycontinue' ) -or $Global :FORC ) {
139152 log " Installing/updating external dependency: git"
140153 $gitVersion = (Invoke-WebRequest " https://git-scm.com/downloads/latest" - UseBasicParsing).Content
141154 Invoke-WebRequest " https://github.com/git-for-windows/git/releases/download/v$gitVersion .windows.1/Git-$gitVersion -64-bit.exe" - UseBasicParsing - outfile " git-installer.exe"
142155 .\git-installer.exe / SILENT / PathOption= " Cmd" | Out-Null
143156 Remove-Item " git-installer.exe"
144- $NEEDS_REBOOT = 1
157+ $Global : NEEDS_REBOOT = $true
145158 log " Install/update completed for: git"
146159 }
147160
148161 # -- docker
149162 log " Checking for external dependency: docker"
150- if ( -not (get-command docker - erroraction ' silentlycontinue' ) -or $FORCE -eq 1 ) {
163+ if ( -not (get-command docker - erroraction ' silentlycontinue' ) -or $Global :FORC ) {
151164 log " Installing/updating external dependency: docker"
152165 Invoke-WebRequest " https://download.docker.com/win/stable/InstallDocker.msi" - UseBasicParsing - outfile " InstallDocker.msi"
153166 msiexec / i InstallDocker.msi / passive | Out-Null
154- $NEEDS_REBOOT = 1
167+ $Global : NEEDS_REBOOT = $true
155168 log " Install/update completed for: docker"
156169 }
157170
158171 # -- kubectl
159172 log " Checking for external dependency: kubectl"
160- if ( -not ( get-command kubectl - erroraction ' silentlycontinue' ) -or $FORCE -eq 1 ) {
173+ if ( -not ( get-command kubectl - erroraction ' silentlycontinue' ) -or $Global :FORC ) {
161174 log " Installing/updating external dependency: kubectl"
162175 $kube_version = (Invoke-WebRequest " https://storage.googleapis.com/kubernetes-release/release/stable.txt" - UseBasicParsing).Content
163176 $kube_version = $kube_version -replace " `n |`r "
164177 Invoke-WebRequest " https://storage.googleapis.com/kubernetes-release/release/$kube_version /bin/windows/amd64/kubectl.exe" - UseBasicParsing - outfile " kubectl.exe"
165- mkdir " C:\Program Files\kubectl"
166- Move-Item - Path " kubectl.exe" - Destination " C:\Program Files\kubectl"
167- # Directly edit the registery to add kubectl to PATH. Will require a restart to stick.
168- $regPath = " HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
169- $value = (Get-ItemProperty $regPath - Name Path).Path
170- $newValue = $value + " ;C:\Program Files\kubectl"
171- Set-ItemProperty - Path $regPath - Name Path - Value $newValue | Out-Null
172- $NEEDS_REBOOT = 1
178+ mkdir " C:\Program Files\kubectl" - erroraction ' silentlycontinue'
179+ Move-Item - Path " kubectl.exe" - Destination " C:\Program Files\kubectl" - force
180+ add_to_path(" C:\Program Files\kubectl" )
181+ $Global :NEEDS_REBOOT = $true
173182 log " Install/update completed for: kubectl"
174183 }
175184
176185 # -- helm
177186 log " Checking for external dependency: helm"
178- if ( -not (get-command helm - erroraction ' silentlycontinue' ) -or $FORCE -eq 1 ) {
187+ if ( -not (get-command helm - erroraction ' silentlycontinue' ) -or $Global :FORC ) {
179188 log " Installing/updating external dependency: helm"
180189 $helm_url = ((Invoke-WebRequest https:// github.com / kubernetes/ helm - UseBasicParsing).Links.OuterHTML | Where-Object {$_ -match ' windows-amd64.tar.gz' } | Select-Object - first 1 ).Split(' "' )[1 ]
181- Write-Output " Helm URL : $helm_url "
182- $helm_file = $helm_url.Split (" /" )[$_ .Length - 1 ]
183- Write-Output " Helm File: $helm_file "
190+ log " Helm URL : $helm_url "
191+ $helm_file = $helm_url.Split (" /" )[-1 ]
192+ log " Helm File: $helm_file "
184193 Invoke-WebRequest $helm_url - UseBasicParsing - outfile " $helm_file "
185194 mkdir " C:\Program Files\helm" - ErrorAction SilentlyContinue
186195 if (-not (Get-Command Expand-7Zip - ErrorAction Ignore)) {
187196 Install-Package - Scope CurrentUser - Force 7Zip4PowerShell > $null
188197 }
189198 Expand-7Zip $helm_file .
190- $tar = $helm_file.Replace (' .gz' , ' ' )
191- Expand-7Zip $tar " C:\Program Files\helm"
192- Remove-Item $helm_file $tar
193- # Directly edit the registery to add helm to PATH. Will require a restart to stick.
194- $regPath = " HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
195- $value = (Get-ItemProperty $regPath - Name Path).Path
196- $newValue = $value + " ;C:\Program Files\helm\windows-amd64"
197- Set-ItemProperty - Path $regPath - Name Path - Value $newValue | Out-Null
198- $NEEDS_REBOOT = 1
199+ $tar_file = $helm_file.Replace (' .gz' , ' ' )
200+ Expand-7Zip $tar_file " C:\Program Files\helm"
201+ Remove-Item $helm_file - erroraction ' silentlycontinue'
202+ Remove-Item $tar_file - erroraction ' silentlycontinue'
203+ add_to_path(" C:\Program Files\helm\windows-amd64" )
204+ $Global :NEEDS_REBOOT = $true
199205 log " Install/update completed for: helm"
200206 }
201207}
202208
209+ # ------------------------------------------------------------------------------
210+ # -- Add a dir to the system path
211+ function add_to_path {
212+ Param ($path )
213+ # Directly edit the registery to add kubectl to PATH. Will require a restart to stick.
214+ $regPath = " HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
215+ $value = (Get-ItemProperty $regPath - Name Path).Path
216+ if ( -not ($value -match [Regex ]::Escape(" $path " ) )) {
217+ log " Adding $path to PATH"
218+ $newValue = " $value ;$path "
219+ Set-ItemProperty - Path $regPath - Name Path - Value $newValue | Out-Null
220+ }
221+ }
222+
203223# ------------------------------------------------------------------------------
204224# -- Install Bluemix CLI.
205225function install_bx () {
@@ -211,8 +231,7 @@ function install_bx() {
211231 $url = $IDT_INSTALL_BMX_URL + " /powershell"
212232 log " Downloading and installing IBM Cloud 'bx' CLI from: $url "
213233 Invoke-Expression (New-Object Net.WebClient).DownloadString( $url )
214- C:\" Program Files" \IBM\Bluemix\bin\bx.exe api api.ng.bluemix.net
215- $NEEDS_REBOOT = 1
234+ $Global :NEEDS_REBOOT = $true
216235 }
217236 log " IBM Cloud CLI version:"
218237 C:\" Program Files" \IBM\Bluemix\bin\bx.exe -- version
@@ -276,7 +295,7 @@ REM #-----------------------------------------------------------
276295# ------------------------------------------------------------------------------
277296function main {
278297 log " --==[ $PROG , v$VERSION ]==--"
279- $secs = (Get-Date )
298+ $Global :SECS = (Get-Date )
280299
281300 # -- Check for Windows 10
282301 if ([System.Environment ]::OSVersion.Version.Major -lt 10 ) {
@@ -306,7 +325,7 @@ function main {
306325 Set-PSDebug - Trace 1
307326 }
308327 " --force" {
309- $FORCE = 1
328+ $Global :FORC = $true
310329 warn " Forcing updates for all dependencies and other settings"
311330 }
312331 " update" { $ACTION = " install" }
@@ -322,9 +341,6 @@ function main {
322341 default { help }
323342 }
324343
325- $secs = (Get-Date )- $secs
326- log " --==[ Finished. Total time: $ ( $secs.ToString (" hh\:mm\:ss" )) seconds ]==--"
327-
328344 quit
329345}
330346
0 commit comments