forked from ScoopInstaller/Scoop
-
Notifications
You must be signed in to change notification settings - Fork 11
/
scoop-hold.ps1
65 lines (51 loc) · 2.15 KB
/
scoop-hold.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
# Usage: scoop hold [<OPTIONS>] <APP>...
# Summary: Hold an application(s) to disable updates.
# Help: Application which is configured as held, cannot be updated, unless it is un-holded manually.
#
# Options:
# -h, --help Show help for this command.
# -g, --global Hold globally installed application(s).
'core', 'getopt', 'help', 'Helpers', 'Applications' | ForEach-Object {
. (Join-Path $PSScriptRoot "..\lib\$_.ps1")
}
Reset-Alias
$ExitCode = 0
$Problems = 0
$Options, $Applications, $_err = getopt $args 'g' 'global'
if ($_err) { Stop-ScoopExecution -Message "scoop hold: $_err" -ExitCode 2 }
if (!$Applications) { Stop-ScoopExecution -Message 'Parameter <APP> missing' -Usage (my_usage) }
$Global = $Options.g -or $Options.global
if ($Global -and !(is_admin)) { Stop-ScoopExecution -Message 'Admin privileges are required to interact with globally installed applications' -ExitCode 4 }
foreach ($app in $Applications) {
# Not at all installed
if (!(installed $app)) {
Write-UserMessage -Message "'$app' is not installed" -Err
++$Problems
continue
}
# Global required, but not installed globally
if ($Global -and (!(installed $app $Global))) {
Write-UserMessage -Message "'$app' not installed globally" -Err
++$Problems
continue
}
# Globally installed, but required locally
if (!$Global -and ((installed $app $true))) {
Write-UserMessage -Message "'$app' installed globally" -Err
++$Problems
continue
}
$splat = @{ 'AppName' = $app; 'Global' = $Global }
$info = Get-InstalledApplicationInformation @splat
$splat.Add('Property', 'hold')
$splat.Add('InputObject', $info)
$current = Get-InstalledApplicationInformationPropertyValue @splat
if (($null -ne $current) -and ($current -eq $true)) {
Write-UserMessage -Message "'$app' is already held" -Warning
continue
}
Set-InstalledApplicationInformationPropertyValue @splat -Value $true -Force
Write-UserMessage -Message "$app is now held and cannot be updated anymore" -Success
}
if ($Problems -gt 0) { $ExitCode = 10 + $Problems }
exit $ExitCode