-
Notifications
You must be signed in to change notification settings - Fork 4
/
uninstall.ps1
143 lines (106 loc) · 5.14 KB
/
uninstall.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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
$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:bashProfilePath = "C:\Users\$env:UserName\.bash_profile"
#endregion
#region functions
function RemoveDockerD
{
Write-Host "Uninstalling dockerd..." -ForegroundColor Blue
dockerw context rm win -f
Stop-Service docker
dockerd --unregister-service
$path = [System.Environment]::GetEnvironmentVariable(
'PATH',
'Machine'
)
$path = ($path.Split(';') | Where-Object { $_ -ne "$script:dockerFilesPath" }) -join ';'
[System.Environment]::SetEnvironmentVariable(
'PATH',
$path,
'Machine'
)
Remove-Item -Path "${script:dockerFilesPath}\dockerd.exe" -Force
Write-Host "dockerd uninstalled successfully." -ForegroundColor Green
}
function UninstallDockerAccessHelper
{
Write-Host "Uninstalling dockeraccesshelper..." -ForegroundColor Blue
Uninstall-Module -Name dockeraccesshelper -Force
Write-Host "dockeraccesshelper uninstalled successfully." -ForegroundColor Green
}
function RestorePowershellProfile
{
Write-Host "Restoring PowerShell Profile from your computer..." -ForegroundColor Green
$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
}
function RestoreGitBashProfile
{
Write-Host "Restoring GitBash Profile from your computer..." -ForegroundColor Green
$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 $script:bashProfilePath -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
}
function DeleteStartScript
{
Remove-Item "${script:dockerFilesPath}\start.ps1" -Force
}
function UninstallRancherDesktop
{
Write-Host "Uninstalling Rancher Desktop..." -ForegroundColor Blue
& $script:rancherDesktopUninstallExe
Start-Sleep -s 5
$uninstallid = (Get-Process Un_A).id 2> $null
Wait-Process -Id $uninstallId
wsl --unregister rancher-desktop
wsl --unregister rancher-desktop-data
Write-Host "Rancher Desktop successfully uninstalled." -ForegroundColor Green
}
function RemoveWslVpnKit
{
Write-Host "Removing the VPN tool..." -ForegroundColor Blue
wsl --unregister wsl-vpnkit
Write-Host "VPN tool removed successfully." -ForegroundColor Green
}
#endregion
#region main
RemoveDockerD
UninstallDockerAccessHelper
RestorePowershellProfile
RestoreGitBashProfile
DeleteStartScript
RemoveWslVpnKit
UninstallRancherDesktop
Write-Host "Uninstall finished." -ForegroundColor Green
Write-Host -NoNewLine "Press any key to continue..."
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
Stop-Process -Force -Id $PID
#endregion