From 2711d431eb82914f470c47b5d8c49cd5c2ac402d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Carri=C3=B3n?= Date: Thu, 5 May 2022 13:59:56 +0200 Subject: [PATCH 01/11] Added update script from 1.1.1 to 1.3.0 --- update.ps1 | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 update.ps1 diff --git a/update.ps1 b/update.ps1 new file mode 100644 index 0000000..c337140 --- /dev/null +++ b/update.ps1 @@ -0,0 +1,98 @@ +#region variables + +$script:rancherDesktopExe = "C:\Users\$env:UserName\AppData\Local\Programs\Rancher Desktop\Rancher Desktop.exe" +$script:rancherDesktopExeHash = "CF7E00240316A3654AB66802A8AAA281478824650C4032C1862123C317CF0885" +$script:rancherDesktopVersion = "1.1.1" +$script:windowsBinariesPath = "C:\Users\$env:UserName\AppData\Local\Programs\Rancher Desktop\resources\resources\win32\bin" +$script:linuxBinariesPath = "C:\Users\$env:UserName\AppData\Local\Programs\Rancher Desktop\resources\resources\linux\bin" +$script:rancherDesktopTargetVersion = "1.3.0" +$script:rancherDesktopInstallerName = "Rancher.Desktop.Setup.$script:rancherDesktopTargetVersion" +$script:rancherDesktopUrl = "https://github.com/rancher-sandbox/rancher-desktop/releases/download/v$script:rancherDesktopTargetVersion/$script:rancherDesktopInstallerName.exe" +$script:rancherDesktopInstallerHash = "92108CBBD8C98F99B00A608D8F7D21E12FAECA76F16890585EF212CC5BF1C779" + +#endregion + +#region functions + +function RenameBinariesFunction +{ + Write-Host "Renaming the Rancher Desktop binaries..." -ForegroundColor Blue + Rename-Item -Path "$script:windowsBinariesPath\docker.exe" -NewName dockerw.exe + Rename-Item -Path "$script:windowsBinariesPath\docker-compose.exe" -NewName dockerw-compose.exe + Copy-Item "$script:windowsBinariesPath\nerdctl.exe" "$script:windowsBinariesPath\docker.exe" -Force + + Rename-Item -Path "$script:linuxBinariesPath\docker" -NewName docker.old + Copy-Item "$script:linuxBinariesPath\nerdctl" "$script:linuxBinariesPath\docker" -Force + Write-Host "Renaming done." -ForegroundColor Green +} + +function UpdateRancherDesktop +{ + + Write-Host "Updating Rancher Desktop to version $script:rancherDesktopTargetVersion..." -ForegroundColor Blue + + if(!(Test-Path -Path $script:rancherDesktopExe)) + { + Write-Host "Rancher Desktop was not found in the system." -ForegroundColor Red + exit 1 + } + elseif ((Get-FileHash -Algorithm SHA256 "$script:rancherDesktopExe").Hash -ne "$script:rancherDesktopExeHash") + { + Write-Host "Wrong Rancher Desktop version detected. Please make sure that the version installed is: $script:rancherDesktopVersion" -ForegroundColor Red + exit 2 + } + else # All update preconditions passed + { + # Create backup of dockerd + Copy-Item "$script:windowsBinariesPath\dockerd.exe" "C:\" -Recurse -Force + + $BinariesRenamed = Test-Path -Path "$script:linuxBinariesPath\docker.old" + + if(!(Test-Path -Path "$script:rancherDesktopInstallerName.exe") -or (Get-FileHash -Algorithm SHA256 "$script:rancherDesktopInstallerName.exe").Hash -ne "$script:rancherDesktopInstallerHash") + { + Invoke-WebRequest $script:rancherDesktopUrl -OutFile "$script:rancherDesktopInstallerName.exe" + if((Get-FileHash -Algorithm SHA256 "$script:rancherDesktopInstallerName.exe").Hash -ne "$script:rancherDesktopInstallerHash") + { + Write-Host "Checksum validation of Rancher Desktop installer failed." -ForegroundColor Red + exit 3 + } + } + + Invoke-Expression ".\$script:rancherDesktopInstallerName.exe" + + $setupId = (Get-Process $script:rancherDesktopInstallerName).id 2> $null + + Wait-Process -Id $setupId + + Write-Host "Rancher Desktop successfully updated to version $script:rancherDesktopTargetVersion." -ForegroundColor Green + + # Restore and remove backup of dockerd + Stop-Service -Name "docker" + Copy-Item "C:\dockerd.exe" $script:windowsBinariesPath -Recurse -Force + Remove-Item "C:\dockerd.exe" + Start-Service -Name "docker" + + if ($BinariesRenamed) + { + RenameBinariesFunction + } + + } + +} + +#endregion + +#region main + +# Elevate script if needed. +if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" $($script:parameters)" -Verb RunAs; exit } + +UpdateRancherDesktop + +Write-Host "Update process finished." -ForegroundColor Green +Write-Host -NoNewLine "Press any key to continue..." +$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') +Stop-Process -Force -Id $PID + +#endregion From ac7747509623bd1c066b6f263c1b57793cfe6560 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Carri=C3=B3n?= Date: Fri, 6 May 2022 14:48:07 +0200 Subject: [PATCH 02/11] DownloadDockerD now uses TEMP folder instead of C:\ --- install.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/install.ps1 b/install.ps1 index 5650f0d..131e9e4 100644 --- a/install.ps1 +++ b/install.ps1 @@ -108,11 +108,11 @@ function EnableVirtualMachinePlatformFeature function DownloadDockerD { Write-Host "Installing dockerd..." -ForegroundColor Blue - Invoke-WebRequest $script:dockerPackageUrl -OutFile "docker.zip" - Expand-Archive docker.zip -DestinationPath "C:\" - Copy-Item "C:\docker\dockerd.exe" $script:windowsBinariesPath -Recurse -Force - Remove-Item docker.zip - Remove-Item "C:\docker" -Recurse -Force + Invoke-WebRequest $script:dockerPackageUrl -OutFile "$env:TEMP\docker.zip" + Expand-Archive "$env:TEMP\docker.zip" -DestinationPath $env:TEMP + Copy-Item "$env:TEMP\docker\dockerd.exe" $script:windowsBinariesPath -Recurse -Force + Remove-Item "$env:TEMP\docker.zip" + Remove-Item "$env:TEMP\docker" -Recurse -Force [Environment]::SetEnvironmentVariable("Path", "$($env:path);$script:windowsBinariesPath", [System.EnvironmentVariableTarget]::Machine) $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") From c7b9999dec9c45c189c252bc9eb12b1d6c24b1b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Carri=C3=B3n?= Date: Mon, 9 May 2022 13:49:48 +0200 Subject: [PATCH 03/11] Added missing check when using Windows containers --- update.ps1 | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/update.ps1 b/update.ps1 index c337140..2469181 100644 --- a/update.ps1 +++ b/update.ps1 @@ -9,6 +9,7 @@ $script:rancherDesktopTargetVersion = "1.3.0" $script:rancherDesktopInstallerName = "Rancher.Desktop.Setup.$script:rancherDesktopTargetVersion" $script:rancherDesktopUrl = "https://github.com/rancher-sandbox/rancher-desktop/releases/download/v$script:rancherDesktopTargetVersion/$script:rancherDesktopInstallerName.exe" $script:rancherDesktopInstallerHash = "92108CBBD8C98F99B00A608D8F7D21E12FAECA76F16890585EF212CC5BF1C779" +$script:StaticWindowsDockerdHash = "B63E2B20D66F086C05D85E7E23A61762148F23FABD5D81B20AE3B0CAB797669A" #endregion @@ -43,8 +44,15 @@ function UpdateRancherDesktop } else # All update preconditions passed { - # Create backup of dockerd - Copy-Item "$script:windowsBinariesPath\dockerd.exe" "C:\" -Recurse -Force + $WindowsContainers = $false + $TempFile = New-TemporaryFile + + if ((Get-FileHash -Algorithm SHA256 "$script:windowsBinariesPath\dockerd.exe").Hash -eq $script:StaticWindowsDockerdHash) + { + # Create backup of dockerd + Copy-Item "$script:windowsBinariesPath\dockerd.exe" $TempFile -Force + $WindowsContainers = $true + } $BinariesRenamed = Test-Path -Path "$script:linuxBinariesPath\docker.old" @@ -66,19 +74,21 @@ function UpdateRancherDesktop Write-Host "Rancher Desktop successfully updated to version $script:rancherDesktopTargetVersion." -ForegroundColor Green - # Restore and remove backup of dockerd - Stop-Service -Name "docker" - Copy-Item "C:\dockerd.exe" $script:windowsBinariesPath -Recurse -Force - Remove-Item "C:\dockerd.exe" - Start-Service -Name "docker" + if ($WindowsContainers) + { + # Restore and remove backup of dockerd + Stop-Service -Name "docker" + Copy-Item $TempFile "$script:windowsBinariesPath\dockerd.exe" -Recurse -Force + Start-Service -Name "docker" + } + Remove-Item $TempFile + if ($BinariesRenamed) { RenameBinariesFunction } - } - } #endregion From cd7a413b83a6470c2b299e8227894deb26ca1aef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Carri=C3=B3n?= Date: Mon, 9 May 2022 15:02:46 +0200 Subject: [PATCH 04/11] Set experimentalHostResolver to true in settings.json --- update.ps1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/update.ps1 b/update.ps1 index 2469181..c43f702 100644 --- a/update.ps1 +++ b/update.ps1 @@ -10,6 +10,7 @@ $script:rancherDesktopInstallerName = "Rancher.Desktop.Setup.$script:rancherDesk $script:rancherDesktopUrl = "https://github.com/rancher-sandbox/rancher-desktop/releases/download/v$script:rancherDesktopTargetVersion/$script:rancherDesktopInstallerName.exe" $script:rancherDesktopInstallerHash = "92108CBBD8C98F99B00A608D8F7D21E12FAECA76F16890585EF212CC5BF1C779" $script:StaticWindowsDockerdHash = "B63E2B20D66F086C05D85E7E23A61762148F23FABD5D81B20AE3B0CAB797669A" +$script:appDataSettingsPath = "C:\Users\$env:UserName\AppData\Roaming\rancher-desktop\settings.json" #endregion @@ -65,7 +66,12 @@ function UpdateRancherDesktop exit 3 } } - + + #Set default value of "experimentalHostResolver" to "true" in settings.json + $settingsContent = Get-Content $script:appDataSettingsPath -raw | ConvertFrom-Json + $settingsContent.kubernetes | Add-Member -NotePropertyName experimentalHostResolver -NotePropertyValue $true + $settingsContent | ConvertTo-Json | set-content $script:appDataSettingsPath + Invoke-Expression ".\$script:rancherDesktopInstallerName.exe" $setupId = (Get-Process $script:rancherDesktopInstallerName).id 2> $null From c9198c45ef713f9177929e37673c377564b5c8b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Carri=C3=B3n?= Date: Mon, 9 May 2022 17:42:23 +0200 Subject: [PATCH 05/11] Use LOCALAPPDATA Co-authored-by: albertdb --- update.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update.ps1 b/update.ps1 index c43f702..8f215fb 100644 --- a/update.ps1 +++ b/update.ps1 @@ -1,6 +1,6 @@ #region variables -$script:rancherDesktopExe = "C:\Users\$env:UserName\AppData\Local\Programs\Rancher Desktop\Rancher Desktop.exe" +$script:rancherDesktopExe = "$env:LOCALAPPDATA\Programs\Rancher Desktop\Rancher Desktop.exe" $script:rancherDesktopExeHash = "CF7E00240316A3654AB66802A8AAA281478824650C4032C1862123C317CF0885" $script:rancherDesktopVersion = "1.1.1" $script:windowsBinariesPath = "C:\Users\$env:UserName\AppData\Local\Programs\Rancher Desktop\resources\resources\win32\bin" From 43db7ce7d5204ac4e15ddace550ff174e4ee764c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Carri=C3=B3n?= Date: Mon, 9 May 2022 17:42:42 +0200 Subject: [PATCH 06/11] Use LOCALAPPDATA Co-authored-by: albertdb --- update.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update.ps1 b/update.ps1 index 8f215fb..db9a6ed 100644 --- a/update.ps1 +++ b/update.ps1 @@ -3,7 +3,7 @@ $script:rancherDesktopExe = "$env:LOCALAPPDATA\Programs\Rancher Desktop\Rancher Desktop.exe" $script:rancherDesktopExeHash = "CF7E00240316A3654AB66802A8AAA281478824650C4032C1862123C317CF0885" $script:rancherDesktopVersion = "1.1.1" -$script:windowsBinariesPath = "C:\Users\$env:UserName\AppData\Local\Programs\Rancher Desktop\resources\resources\win32\bin" +$script:windowsBinariesPath = "$env:LOCALAPPDATA\Programs\Rancher Desktop\resources\resources\win32\bin" $script:linuxBinariesPath = "C:\Users\$env:UserName\AppData\Local\Programs\Rancher Desktop\resources\resources\linux\bin" $script:rancherDesktopTargetVersion = "1.3.0" $script:rancherDesktopInstallerName = "Rancher.Desktop.Setup.$script:rancherDesktopTargetVersion" From faed8054e82432279261508a1204c125cd8d35f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Carri=C3=B3n?= Date: Mon, 9 May 2022 17:42:55 +0200 Subject: [PATCH 07/11] Use LOCALAPPDATA Co-authored-by: albertdb --- update.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update.ps1 b/update.ps1 index db9a6ed..61c59d9 100644 --- a/update.ps1 +++ b/update.ps1 @@ -4,7 +4,7 @@ $script:rancherDesktopExe = "$env:LOCALAPPDATA\Programs\Rancher Desktop\Rancher $script:rancherDesktopExeHash = "CF7E00240316A3654AB66802A8AAA281478824650C4032C1862123C317CF0885" $script:rancherDesktopVersion = "1.1.1" $script:windowsBinariesPath = "$env:LOCALAPPDATA\Programs\Rancher Desktop\resources\resources\win32\bin" -$script:linuxBinariesPath = "C:\Users\$env:UserName\AppData\Local\Programs\Rancher Desktop\resources\resources\linux\bin" +$script:linuxBinariesPath = "$env:LOCALAPPDATA\Programs\Rancher Desktop\resources\resources\linux\bin" $script:rancherDesktopTargetVersion = "1.3.0" $script:rancherDesktopInstallerName = "Rancher.Desktop.Setup.$script:rancherDesktopTargetVersion" $script:rancherDesktopUrl = "https://github.com/rancher-sandbox/rancher-desktop/releases/download/v$script:rancherDesktopTargetVersion/$script:rancherDesktopInstallerName.exe" From 4aff52618e44186f67ffee6e65097750a9f10dd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Carri=C3=B3n?= Date: Mon, 9 May 2022 17:46:26 +0200 Subject: [PATCH 08/11] Use APPDATA Co-authored-by: albertdb --- update.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update.ps1 b/update.ps1 index 61c59d9..901c7c1 100644 --- a/update.ps1 +++ b/update.ps1 @@ -10,7 +10,7 @@ $script:rancherDesktopInstallerName = "Rancher.Desktop.Setup.$script:rancherDesk $script:rancherDesktopUrl = "https://github.com/rancher-sandbox/rancher-desktop/releases/download/v$script:rancherDesktopTargetVersion/$script:rancherDesktopInstallerName.exe" $script:rancherDesktopInstallerHash = "92108CBBD8C98F99B00A608D8F7D21E12FAECA76F16890585EF212CC5BF1C779" $script:StaticWindowsDockerdHash = "B63E2B20D66F086C05D85E7E23A61762148F23FABD5D81B20AE3B0CAB797669A" -$script:appDataSettingsPath = "C:\Users\$env:UserName\AppData\Roaming\rancher-desktop\settings.json" +$script:appDataSettingsPath = "$env:APPDATA\rancher-desktop\settings.json" #endregion From 20ea83b1cb626f8d56e91a36243704cf88e5cd26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Carri=C3=B3n?= Date: Mon, 9 May 2022 18:07:07 +0200 Subject: [PATCH 09/11] Use of LOCALAPPDATA and APPDATA when applicable and updated settings.json for v1.3.0 --- install.ps1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/install.ps1 b/install.ps1 index 131e9e4..e6d952c 100644 --- a/install.ps1 +++ b/install.ps1 @@ -23,20 +23,19 @@ foreach ($boundParam in $PSBoundParameters.GetEnumerator()) $script:parameters += '-{0} ' -f $boundParam.Key } -$script:rancherDesktopExe = "C:\Users\$env:UserName\AppData\Local\Programs\Rancher Desktop\Rancher Desktop.exe" -$script:windowsBinariesPath = "C:\Users\$env:UserName\AppData\Local\Programs\Rancher Desktop\resources\resources\win32\bin" -$script:linuxBinariesPath = "C:\Users\$env:UserName\AppData\Local\Programs\Rancher Desktop\resources\resources\linux\bin" -$script:profilePath = "C:\Users\$env:UserName\Documents\WindowsPowerShell\old-profile.ps1" +$script:rancherDesktopExe = "$env:LOCALAPPDATA\Programs\Rancher Desktop\Rancher Desktop.exe" +$script:windowsBinariesPath = "$env:LOCALAPPDATA\Programs\Rancher Desktop\resources\resources\win32\bin" +$script:linuxBinariesPath = "$env:LOCALAPPDATA\Programs\Rancher Desktop\resources\resources\linux\bin" $script:panicFilePath = "C:\ProgramData\docker\panic.log" $script:dockerPackageUrl = "https://download.docker.com/win/static/stable/x86_64/docker-20.10.8.zip" -$script:rancherDesktopVersion = "1.1.1" +$script:rancherDesktopVersion = "1.3.0" $script:rancherDesktopInstallerName = "Rancher.Desktop.Setup.$script:rancherDesktopVersion" -$script:rancherDesktopInstallerHash = "DD3D52501963FD1757E8D0B972DEDA264AFE38D8F0EF3383AAA5B1BD6B6C0747" +$script:rancherDesktopInstallerHash = "92108CBBD8C98F99B00A608D8F7D21E12FAECA76F16890585EF212CC5BF1C779" $script:rancherDesktopUrl = "https://github.com/rancher-sandbox/rancher-desktop/releases/download/v$script:rancherDesktopVersion/$script:rancherDesktopInstallerName.exe" $script:wslVpnKitUrl = "https://github.com/sakai135/wsl-vpnkit/releases/download/v0.3.1/wsl-vpnkit.tar.gz" $script:restartRequired = $false $script:bashProfilePath = "C:\Users\$env:UserName\.bash_profile" -$script:appDataSettingsPath = "C:\Users\$env:UserName\AppData\Roaming\rancher-desktop\settings.json" +$script:appDataSettingsPath = "$env:APPDATA\rancher-desktop\settings.json" #endregion @@ -300,6 +299,7 @@ function SetAppDataSettings $settingsContent = Get-Content $script:appDataSettingsPath -raw | ConvertFrom-Json $settingsContent.kubernetes.enabled=$false $settingsContent.kubernetes.containerEngine="containerd" + $settingsContent.kubernetes.experimentalHostResolver=$true $settingsContent.updater=$false $settingsContent | ConvertTo-Json | set-content $script:appDataSettingsPath } From c4967dc3a0080718d34944ef51779d145808b0f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Carri=C3=B3n?= Date: Mon, 9 May 2022 18:08:39 +0200 Subject: [PATCH 10/11] Added experimentalHostResolver field for v1.3.0 --- settings.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/settings.json b/settings.json index b3ef045..8d76cd2 100644 --- a/settings.json +++ b/settings.json @@ -1,7 +1,8 @@ { "kubernetes": { "enabled": false, - "containerEngine": "containerd" + "containerEngine": "containerd", + "experimentalHostResolver": true }, "updater": false } From 7741552967696464609eef409245bcdc7d3b4feb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Carri=C3=B3n?= Date: Mon, 9 May 2022 18:21:03 +0200 Subject: [PATCH 11/11] Use of LOCALAPPDATA when applicable --- uninstall.ps1 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/uninstall.ps1 b/uninstall.ps1 index 2b14e4f..a294b15 100644 --- a/uninstall.ps1 +++ b/uninstall.ps1 @@ -2,8 +2,8 @@ if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]: #region variables -$script:rancherDesktopUninstallExe = "C:\Users\$env:UserName\AppData\Local\Programs\Rancher Desktop\Uninstall Rancher Desktop.exe" -$script:dockerFilesPath = "C:\Users\$env:UserName\AppData\Local\Programs\Rancher Desktop\resources\resources\win32\bin" +$script:rancherDesktopUninstallExe = "$env:LOCALAPPDATA\Programs\Rancher Desktop\Uninstall Rancher Desktop.exe" +$script:dockerFilesPath = "$env:LOCALAPPDATA\Programs\Rancher Desktop\resources\resources\win32\bin" $script:bashProfilePath = "C:\Users\$env:UserName\.bash_profile" #endregion @@ -95,7 +95,10 @@ function RestoreGitBashProfile function DeleteStartScript { - Remove-Item "${script:dockerFilesPath}\start.ps1" -Force + if(Test-Path -Path "${script:dockerFilesPath}\start.ps1") + { + Remove-Item "${script:dockerFilesPath}\start.ps1" -Force + } } function UninstallRancherDesktop