From ffdd8150431383463e65e91d36ec6abbedca3114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Carri=C3=B3n?= Date: Wed, 20 Apr 2022 11:04:52 +0200 Subject: [PATCH 1/8] Improved profile restoring --- uninstall.ps1 | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/uninstall.ps1 b/uninstall.ps1 index 888168d..fd64373 100644 --- a/uninstall.ps1 +++ b/uninstall.ps1 @@ -4,7 +4,7 @@ $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:profilePath = "C:\Users\$env:UserName\Documents\WindowsPowerShell\old-profile.ps1" +$script:bashProfilePath = "C:\Users\$env:UserName\.bash_profile" #endregion @@ -45,13 +45,28 @@ function UninstallDockerAccessHelper function RestorePowershellProfile { - Write-Host "Removing the alias from your computer..." -ForegroundColor Green + Write-Host "Restoring PowerShell Profile from your computer..." -ForegroundColor Green - New-Item -Type File -Path $PROFILE -Force - Get-Content "${script:profilePath}" >> $PROFILE - Remove-Item -Path "${script:profilePath}" -Force + Set-Content -Path $PROFILE -Value (get-content -Path $PROFILE | Select-String -Pattern 'docker' -NotMatch) + Set-Content -Path $PROFILE -Value (get-content -Path $PROFILE | Select-String -Pattern 'nerdctl' -NotMatch) + Set-Content -Path $PROFILE -Value (get-content -Path $PROFILE | Select-String -Pattern 'Rancher-Desktop' -NotMatch) + Set-Content -Path $PROFILE -Value (get-content -Path $PROFILE -Raw | Select-String -Pattern '{*\n.*}' -NotMatch) + Set-Content -Path $PROFILE -Value (get-content -Path $PROFILE | Select-String -Pattern 'VPN' -NotMatch) + Set-Content -Path $PROFILE -Value (get-content -Path $PROFILE | Select-String -Pattern 'wsl' -NotMatch) - Write-Host "Profile restored successfully." -ForegroundColor Green + Write-Host "PowerShell Profile restored successfully." -ForegroundColor Green +} + +function RestoreGitBashProfile +{ + Write-Host "Restoring GitBash Profile from your computer..." -ForegroundColor Green + + Set-Content -Path $script:bashProfilePath -Value (get-content -Path $script:bashProfilePath | Select-String -Pattern 'Rancher-Desktop' -NotMatch) + Set-Content -Path $script:bashProfilePath -Value (get-content -Path $script:bashProfilePath | Select-String -Pattern 'docker' -NotMatch) + Set-Content -Path $script:bashProfilePath -Value (get-content -Path $script:bashProfilePath | Select-String -Pattern 'VPN' -NotMatch) + Set-Content -Path $script:bashProfilePath -Value (get-content -Path $script:bashProfilePath | Select-String -Pattern 'wsl' -NotMatch) + + Write-Host "GitBash Profile restored successfully." -ForegroundColor Green } function DeleteStartScript @@ -91,6 +106,7 @@ function RemoveWslVpnKit RemoveDockerD UninstallDockerAccessHelper RestorePowershellProfile +RestoreGitBashProfile DeleteStartScript RemoveWslVpnKit UninstallRancherDesktop From 908978aa13e10039e6f66201180720df74de8a8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Carri=C3=B3n?= Date: Wed, 20 Apr 2022 11:12:14 +0200 Subject: [PATCH 2/8] PowerShell profile backup no longer needed --- install.ps1 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/install.ps1 b/install.ps1 index d5949fc..ade800d 100644 --- a/install.ps1 +++ b/install.ps1 @@ -11,7 +11,6 @@ param( $script:rancherDesktopExe = "C:\Users\$env:UserName\AppData\Local\Programs\Rancher Desktop\Rancher Desktop.exe" $script:dockerFilesPath = "C:\Users\$env:UserName\AppData\Local\Programs\Rancher Desktop\resources\resources\win32\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.2.1/Rancher.Desktop.Setup.1.2.1.exe" @@ -127,9 +126,7 @@ function CreatePowershellProfile { New-Item -Type File -Path $PROFILE -Force } - - Copy-Item $PROFILE "$script:profilePath" - + Write-Host "" >> $PROFILE Get-Content "profile.ps1" >> "$PROFILE" From fa54e099ec216dc883919ba7d48d8d33705f34e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Carri=C3=B3n?= Date: Wed, 27 Apr 2022 11:22:30 +0200 Subject: [PATCH 3/8] Added start and end region markers --- profile.ps1 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/profile.ps1 b/profile.ps1 index a4c1a88..724dbdd 100644 --- a/profile.ps1 +++ b/profile.ps1 @@ -1,3 +1,4 @@ +#region generated by rd-installer for Alias support in Powershell # Path to the docker binaries $dockerBinaries = "C:\Users\$env:UserName\AppData\Local\Programs\Rancher Desktop\resources\resources\win32\bin" @@ -28,6 +29,4 @@ function dockerw-start { & $dockerBinaries\start.ps1 } - -# Start the VPN support -wsl -d wsl-vpnkit service wsl-vpnkit start 2> $null \ No newline at end of file +#endregion From c5fc39f766324055023754499bb60902b3870a07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Carri=C3=B3n?= Date: Wed, 27 Apr 2022 13:52:02 +0200 Subject: [PATCH 4/8] Use of regions in profiles --- install.ps1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/install.ps1 b/install.ps1 index ade800d..a7b0926 100644 --- a/install.ps1 +++ b/install.ps1 @@ -128,20 +128,21 @@ function CreatePowershellProfile } Write-Host "" >> $PROFILE - Get-Content "profile.ps1" >> "$PROFILE" + Add-Content $PROFILE (Get-Content "profile.ps1") . $PROFILE } function UpdateGitBashProfile { - $search = (Get-Content $script:bashProfilePath | Select-String -Pattern '# generated by rd-installer for Alias support in Git Bash').Matches.Success + $search = (Get-Content $script:bashProfilePath | Select-String -Pattern '#region generated by rd-installer for Alias support in Git Bash').Matches.Success if( -Not $search){ - Add-Content $script:bashProfilePath "# generated by rd-installer for Alias support in Git Bash" + Add-Content $script:bashProfilePath "#region generated by rd-installer for Alias support in Git Bash" Add-Content $script:bashProfilePath "alias docker=""nerdctl""" Add-Content $script:bashProfilePath "alias docker-compose=""nerdctl compose""" Add-Content $script:bashProfilePath "alias dockerw=""/c/Users/$(whoami)/AppData/Local/Programs/Rancher\ Desktop/resources/resources/win32/bin/docker.exe --context win""" Add-Content $script:bashProfilePath "alias dockerw-compose=""/c/Users/$(whoami)/AppData/Local/Programs/Rancher\ Desktop/resources/resources/win32/bin/docker-compose.exe --context win""" + Add-Content $script:bashProfilePath "#endregion" } } From 1299b6cc05b03498fac107257f4e1bab522bb563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Carri=C3=B3n?= Date: Wed, 27 Apr 2022 14:02:15 +0200 Subject: [PATCH 5/8] Support for region based profiles and old profiles --- uninstall.ps1 | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/uninstall.ps1 b/uninstall.ps1 index fd64373..4cc95ad 100644 --- a/uninstall.ps1 +++ b/uninstall.ps1 @@ -47,12 +47,23 @@ function RestorePowershellProfile { Write-Host "Restoring PowerShell Profile from your computer..." -ForegroundColor Green - Set-Content -Path $PROFILE -Value (get-content -Path $PROFILE | Select-String -Pattern 'docker' -NotMatch) - Set-Content -Path $PROFILE -Value (get-content -Path $PROFILE | Select-String -Pattern 'nerdctl' -NotMatch) - Set-Content -Path $PROFILE -Value (get-content -Path $PROFILE | Select-String -Pattern 'Rancher-Desktop' -NotMatch) - Set-Content -Path $PROFILE -Value (get-content -Path $PROFILE -Raw | Select-String -Pattern '{*\n.*}' -NotMatch) - Set-Content -Path $PROFILE -Value (get-content -Path $PROFILE | Select-String -Pattern 'VPN' -NotMatch) - Set-Content -Path $PROFILE -Value (get-content -Path $PROFILE | Select-String -Pattern 'wsl' -NotMatch) + $startMarker = Select-String -Path $PROFILE -Pattern "#region generated by rd-installer" + + if ($startMarker -ne $null) + { + #Delete rd-installer blocks from profile + Set-Content -Path $PROFILE -Value ( (get-content -Path $PROFILE -Raw) -replace '#region generated by rd-installer(?s)(.*)#endregion','' ) + } + + else + { + #Delete profile content from old installations (TO REMOVE after adoption of profiles with regions) + Set-Content -Path $PROFILE -Value (get-content -Path $PROFILE | Select-String -Pattern 'docker' -NotMatch) + Set-Content -Path $PROFILE -Value (get-content -Path $PROFILE | Select-String -Pattern 'nerdctl' -NotMatch) + Set-Content -Path $PROFILE -Value (get-content -Path $PROFILE | Select-String -Pattern '# Start the VPN support' -NotMatch) + Set-Content -Path $PROFILE -Value (get-content -Path $PROFILE | Select-String -Pattern 'wsl -d wsl-vpnkit' -NotMatch) + Set-Content -Path $PROFILE -Value (get-content -Path $PROFILE -Raw | Select-String -Pattern '{*\n.*}' -NotMatch) + } Write-Host "PowerShell Profile restored successfully." -ForegroundColor Green } @@ -61,10 +72,23 @@ function RestoreGitBashProfile { Write-Host "Restoring GitBash Profile from your computer..." -ForegroundColor Green - Set-Content -Path $script:bashProfilePath -Value (get-content -Path $script:bashProfilePath | Select-String -Pattern 'Rancher-Desktop' -NotMatch) - Set-Content -Path $script:bashProfilePath -Value (get-content -Path $script:bashProfilePath | Select-String -Pattern 'docker' -NotMatch) - Set-Content -Path $script:bashProfilePath -Value (get-content -Path $script:bashProfilePath | Select-String -Pattern 'VPN' -NotMatch) - Set-Content -Path $script:bashProfilePath -Value (get-content -Path $script:bashProfilePath | Select-String -Pattern 'wsl' -NotMatch) + $startMarker = Select-String -Path $script:bashProfilePath -Pattern "#region generated by rd-installer" + + if ($startMarker -ne $null) + { + #Delete rd-installer blocks from profile + Set-Content -Path $script:bashProfilePath -Value ( (get-content -Path $PROFILE -Raw) -replace '#region generated by rd-installer(?s)(.*)#endregion','' ) + } + + else + { + #Delete profile content from old installations (TO REMOVE after adoption of profiles with regions) + Set-Content -Path $script:bashProfilePath -Value (get-content -Path $script:bashProfilePath | Select-String -Pattern 'rd-installer' -NotMatch) + Set-Content -Path $script:bashProfilePath -Value (get-content -Path $script:bashProfilePath | Select-String -Pattern 'alias docker' -NotMatch) + Set-Content -Path $script:bashProfilePath -Value (get-content -Path $script:bashProfilePath | Select-String -Pattern '# Start the VPN support' -NotMatch) + Set-Content -Path $script:bashProfilePath -Value (get-content -Path $script:bashProfilePath | Select-String -Pattern 'wsl -d wsl-vpnkit' -NotMatch) + + } Write-Host "GitBash Profile restored successfully." -ForegroundColor Green } From 3f080b5c491ab4003f39b3bd8a4053daeabf0fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Carri=C3=B3n?= Date: Thu, 28 Apr 2022 14:01:16 +0200 Subject: [PATCH 6/8] Fixed missing profile tags in ActivateWslVpnkit --- install.ps1 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/install.ps1 b/install.ps1 index a7b0926..e817f69 100644 --- a/install.ps1 +++ b/install.ps1 @@ -198,22 +198,28 @@ function ActivateWslVpnkit Remove-Item wsl-vpnkit.tar.gz -Force - $search = (Get-Content $PROFILE | Select-String -Pattern '# generated by rd-installer for VPN support in Powershell').Matches.Success + $search = (Get-Content $PROFILE | Select-String -Pattern '#region generated by rd-installer for VPN support in Powershell').Matches.Success if( -Not $search){ - Add-Content $PROFILE "# generated by rd-installer for VPN support in Powershell" + Add-Content $PROFILE "#region generated by rd-installer for VPN support in Powershell" Add-Content $PROFILE "# Start the VPN support" Add-Content $PROFILE "wsl -d wsl-vpnkit service wsl-vpnkit start 2> `$null" + Add-Content $PROFILE "#endregion" + Add-Content $script:bashProfilePath "" + } - $search = (Get-Content $script:bashProfilePath | Select-String -Pattern '# generated by rd-installer for VPN support in Git Bash').Matches.Success + $search = (Get-Content $script:bashProfilePath | Select-String -Pattern '#region generated by rd-installer for VPN support in Git Bash').Matches.Success if( -Not $search){ - Add-Content $script:bashProfilePath "# generated by rd-installer for VPN support in Git Bash" + Add-Content $script:bashProfilePath "#region generated by rd-installer for VPN support in Git Bash" Add-Content $script:bashProfilePath "# Start the VPN support" Add-Content $script:bashProfilePath "wsl -d wsl-vpnkit service wsl-vpnkit start 2> /dev/null" + Add-Content $script:bashProfilePath "#endregion" + Add-Content $script:bashProfilePath "" } Write-Host "VPN tool activated." -ForegroundColor Green } + function ChangeFilePermissions { $isReadOnly = Get-ItemProperty -Path $script:panicFilePath 2> $null | Select-Object IsReadOnly From 17aee357e62970dba834751e24e2fe8163bea663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Carri=C3=B3n?= Date: Thu, 28 Apr 2022 20:41:55 +0200 Subject: [PATCH 7/8] Fixed wrong file path when restoring Git Bash profile --- uninstall.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uninstall.ps1 b/uninstall.ps1 index 4cc95ad..9d06c0d 100644 --- a/uninstall.ps1 +++ b/uninstall.ps1 @@ -77,7 +77,7 @@ function RestoreGitBashProfile if ($startMarker -ne $null) { #Delete rd-installer blocks from profile - Set-Content -Path $script:bashProfilePath -Value ( (get-content -Path $PROFILE -Raw) -replace '#region generated by rd-installer(?s)(.*)#endregion','' ) + Set-Content -Path $script:bashProfilePath -Value ( (get-content -Path $script:bashProfilePath -Raw) -replace '#region generated by rd-installer(?s)(.*)#endregion','' ) } else From ef5e275757a6ed6de3e898ff935a791e2ae845ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Carri=C3=B3n?= Date: Mon, 2 May 2022 15:38:23 +0200 Subject: [PATCH 8/8] Fixed adding empty line to Git Bash profile instead of PowerShell profile Co-authored-by: albertdb --- install.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.ps1 b/install.ps1 index e817f69..2a930c6 100644 --- a/install.ps1 +++ b/install.ps1 @@ -204,7 +204,7 @@ function ActivateWslVpnkit Add-Content $PROFILE "# Start the VPN support" Add-Content $PROFILE "wsl -d wsl-vpnkit service wsl-vpnkit start 2> `$null" Add-Content $PROFILE "#endregion" - Add-Content $script:bashProfilePath "" + Add-Content $PROFILE "" } $search = (Get-Content $script:bashProfilePath | Select-String -Pattern '#region generated by rd-installer for VPN support in Git Bash').Matches.Success