Skip to content

Commit

Permalink
Merge pull request #34 from devonfw-forge/feature/auto-elevate
Browse files Browse the repository at this point in the history
Auto-elevating, setting default flags when run from context menu and not downloading again if checksum is valid
  • Loading branch information
albertdb authored May 3, 2022
2 parents 8d6aa70 + a2f5d18 commit 3d22e1b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 19 deletions.
14 changes: 8 additions & 6 deletions README.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@ If you are new to containers or you are not already familiar with Docker, we enc

The script `install.ps1` will install the Rancher Desktop solution along with some extra features:

* Support for usual Docker commands in Powershell and Bash (flag `-Alias`).
* Support for enterprise VPNs (flag `-VPN`).
* Support (additional) for Windows Containers using Docker binary (flag `-WindowsContainers`). You do not need to choose anymore!
* Support for usual Docker commands in Powershell and Bash (flag `-Alias`).

To install it, clone the repository and run `install.ps1` with the desired flags as administrator.
To install it, clone the repository and run `install.ps1` with the desired flags.

*Tipically, you just need to*:
*Tipically, you just need to either*:

```
.\install.ps1 -VPN -WindowsContainers -Alias
.\install.ps1 -Alias -VPN -WindowsContainers
```

IMPORTANT: *Do not enable auto-update in Rancher Desktop settings. VPN support is known to break after v1.1.1.*
*or right-click on the install script and select "Run with PowerShell"*, it will default to the above flags.

IMPORTANT: You may be asked to reboot your computer. This happens when you do not have the required Windows features already enabled. If so, relaunch installation process after restart.

CAUTION: Do not enable auto-update in Rancher Desktop settings. VPN support is known to break after v1.1.1.

== Usage

Using Linux containers is very simple, just make sure Rancher Desktop is started, that you don't change default containerd runtime, and go ahead running the Docker commands you are used to:
Expand Down Expand Up @@ -74,6 +76,6 @@ This feature comes disabled by default, but you can activate it on Rancher Deskt

== Uninstall

To uninstall Rancher Desktop and all the extra features execute the script `uninstall.ps1` as administrator.
To uninstall Rancher Desktop and all the extra features execute the script `uninstall.ps1`.

The uninstall script will cleanup the environment variables, folders and tools, leaving your computer as clean as it was.
48 changes: 38 additions & 10 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
#Requires -RunAsAdministrator

#region variables

param(
[switch]$Help = $false,
[switch]$Alias = $false,
[switch]$VPN = $false,
[switch]$WindowsContainers = $false,
[switch]$Alias = $false,
[switch]$RenameBinaries = $false
)

# When run from context menu (also other situations, but not relevant)
if($MyInvocation.InvocationName -eq "&" -and $PSBoundParameters.count -eq 0)
{
$PSBoundParameters."Alias" = $true
$PSBoundParameters."VPN" = $true
$PSBoundParameters."WindowsContainers" = $true
}

$script:parameters = ""

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:panicFilePath = "C:\ProgramData\docker\panic.log"
$script:dockerPackageUrl = "https://download.docker.com/win/static/stable/x86_64/docker-20.10.8.zip"
$script:rancherDesktopUrl = "https://github.com/rancher-sandbox/rancher-desktop/releases/download/v1.1.1/Rancher.Desktop.Setup.1.1.1.exe"
$script:rancherDesktopVersion = "1.1.1"
$script:rancherDesktopInstallerName = "Rancher.Desktop.Setup.$script:rancherDesktopVersion"
$script:rancherDesktopInstallerHash = "DD3D52501963FD1757E8D0B972DEDA264AFE38D8F0EF3383AAA5B1BD6B6C0747"
$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"
Expand All @@ -33,9 +49,9 @@ function Help
Write-Host " .\install.ps1 [flags]"
Write-Host ""
Write-Host "Flags:"
Write-Host " -Alias Creates alias for usual Docker commands in Powershell and Bash."
Write-Host " -VPN Enables support for enterprise VPNs."
Write-Host " -WindowsContainers Enables support for Windows Containers using Docker binary."
Write-Host " -Alias Creates alias for usual Docker commands in Powershell and Bash."
Write-Host ""
Write-Host "Advanced Flags:"
Write-Host " -RenameBinaries Renames binaries to provide universal docker command support in cases where shell profiles are of no use, but comes with some caveats (e.g. requires using docker compose instead of docker-compose). Incompatible with -Alias flag."
Expand Down Expand Up @@ -201,10 +217,19 @@ function IsDockerDesktopInstalled
function InstallRancherDesktop
{
Write-Host "Installing Rancher Desktop..." -ForegroundColor Blue
Invoke-WebRequest $script:rancherDesktopUrl -OutFile "Rancher.Desktop.Setup.1.1.1.exe"
.\Rancher.Desktop.Setup.1.1.1.exe

$setupId = (Get-Process Rancher.Desktop.Setup.1.1.1).id 2> $null
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 1
}
}
Invoke-Expression ".\$script:rancherDesktopInstallerName.exe"

$setupId = (Get-Process $script:rancherDesktopInstallerName).id 2> $null

Wait-Process -Id $setupId

Expand Down Expand Up @@ -238,7 +263,7 @@ function ActivateWslVpnkit
Add-Content $script:bashProfilePath ""
}

Write-Host "VPN tool activated." -ForegroundColor Green
Write-Host "VPN support successfully installed." -ForegroundColor Green
}


Expand Down Expand Up @@ -294,9 +319,12 @@ if($Alias -and $RenameBinaries)
if($Help)
{
Help
exit 1
exit 0
}

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

IsDockerDesktopInstalled

if($WindowsContainers)
Expand Down
4 changes: 2 additions & 2 deletions start.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" $($args)" -Verb RunAs; exit }

Start-Service docker

Add-AccountToDockerAccess "$env:UserDomain\$env:UserDomain"
Add-AccountToDockerAccess "$env:UserDomain\$env:UserDomain"
2 changes: 1 addition & 1 deletion uninstall.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Requires -RunAsAdministrator
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" $($args)" -Verb RunAs; exit }

#region variables

Expand Down

0 comments on commit 3d22e1b

Please sign in to comment.