forked from ScoopInstaller/Scoop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.ps1
74 lines (61 loc) · 2.02 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
param($global)
. "$psscriptroot\..\lib\core.ps1"
. "$psscriptroot\..\lib\install.ps1"
. "$psscriptroot\..\lib\shortcuts.ps1"
. "$psscriptroot\..\lib\versions.ps1"
. "$psscriptroot\..\lib\manifest.ps1"
if($global -and !(is_admin)) {
"ERROR: You need admin rights to uninstall globally."; exit 1
}
warn 'This will uninstall Scoop and all the programs that have been installed with Scoop!'
$yn = read-host 'Are you sure? (yN)'
if($yn -notlike 'y*') { exit }
$errors = $false
function do_uninstall($app, $global) {
$version = current_version $app $global
$dir = versiondir $app $version $global
$manifest = installed_manifest $app $version $global
$install = install_info $app $version $global
$architecture = $install.architecture
echo "Uninstalling '$app'"
run_uninstaller $manifest $architecture $dir
rm_shims $manifest $global $architecture
# If a junction was used during install, that will have been used
# as the reference directory. Othewise it will just be the version
# directory.
$refdir = unlink_current (appdir $app $global)
env_rm_path $manifest $refdir $global
env_rm $manifest $global
$appdir = appdir $app $global
try {
rm -r -force $appdir -ea stop
} catch {
$errors = $true
warn "Couldn't remove $(friendly_path $appdir): $_.exception"
}
}
function rm_dir($dir) {
try {
rm -r -force $dir -ea stop
} catch {
abort "Couldn't remove $(friendly_path $dir): $_"
}
}
# run uninstallation for each app if necessary, continuing if there's
# a problem deleting a directory (which is quite likely)
if($global) {
installed_apps $true | % { # global apps
do_uninstall $_ $true
}
}
installed_apps $false | % { # local apps
do_uninstall $_ $false
}
if($errors) {
abort "Not all apps could be deleted. Try again or restart."
}
rm_dir $scoopdir
if($global) { rm_dir $globaldir }
remove_from_path (shimdir $false)
if($global) { remove_from_path (shimdir $true) }
success "Scoop has been uninstalled."