Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added update script from 1.1.1 to 1.3.0 #36

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
24 changes: 12 additions & 12 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -108,11 +107,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")
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"kubernetes": {
"enabled": false,
"containerEngine": "containerd"
"containerEngine": "containerd",
"experimentalHostResolver": true
},
"updater": false
}
9 changes: 6 additions & 3 deletions uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
114 changes: 114 additions & 0 deletions update.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#region variables

$script:rancherDesktopExe = "$env:LOCALAPPDATA\Programs\Rancher Desktop\Rancher Desktop.exe"
$script:rancherDesktopExeHash = "CF7E00240316A3654AB66802A8AAA281478824650C4032C1862123C317CF0885"
$script:rancherDesktopVersion = "1.1.1"
$script:windowsBinariesPath = "$env:LOCALAPPDATA\Programs\Rancher Desktop\resources\resources\win32\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"
$script:rancherDesktopInstallerHash = "92108CBBD8C98F99B00A608D8F7D21E12FAECA76F16890585EF212CC5BF1C779"
$script:StaticWindowsDockerdHash = "B63E2B20D66F086C05D85E7E23A61762148F23FABD5D81B20AE3B0CAB797669A"
$script:appDataSettingsPath = "$env:APPDATA\rancher-desktop\settings.json"

#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
{
$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"

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
}
}

#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

Wait-Process -Id $setupId

Write-Host "Rancher Desktop successfully updated to version $script:rancherDesktopTargetVersion." -ForegroundColor Green

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

#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