-
-
Notifications
You must be signed in to change notification settings - Fork 434
/
install-updates.ps1
executable file
·68 lines (62 loc) · 1.95 KB
/
install-updates.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
<#
.SYNOPSIS
Installs software updates
.DESCRIPTION
This PowerShell script installs software updates for the local machine (might need admin rights).
HINT: Use the script 'list-updates.ps1' to list the latest software updates in advance.
.EXAMPLE
PS> ./install-updates.ps1
⏳ (1/2) Checking update requirements...
✅ Drive C: has 441 GB free (56% of 1TB used)
✅ Swap space has 1GB free (2% of 1GB used)
✅ No pending system reboot
⏳ (2/2) Installing updates from winget and Microsoft Store...
...
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
try {
$stopWatch = [system.diagnostics.stopwatch]::startNew()
if ($IsLinux) {
"⏳ (1/5) Checking update requirements..."
& "$PSScriptRoot/check-smart-devices.ps1"
& "$PSScriptRoot/check-drive-space.ps1" /
& "$PSScriptRoot/check-swap-space.ps1"
& "$PSScriptRoot/check-pending-reboot.ps1"
Start-Sleep -seconds 3
""
"⏳ (2/5) Querying latest package information..."
& sudo apt update
"⏳ (3/5) Removing obsolete packages..."
& sudo apt autoremove --yes
"⏳ (4/5) Upgrading installed packages..."
& sudo apt upgrade --yes
"⏳ (5/5) Upgrading installed Snaps..."
& sudo snap refresh
} elseif ($IsMacOS) {
Write-Progress "⏳ Installing updates..."
& sudo softwareupdate -i -a
Write-Progress -completed " "
} else {
# Windows:
"⏳ (1/2) Checking update requirements..."
& "$PSScriptRoot/check-smart-devices.ps1"
& "$PSScriptRoot/check-drive-space.ps1" C
& "$PSScriptRoot/check-swap-space.ps1"
& "$PSScriptRoot/check-pending-reboot.ps1"
Start-Sleep -seconds 3
""
"⏳ (2/2) Installing updates from winget..."
""
& winget upgrade --all --source=winget
# & winget upgrade --all --source=msstore # does not work
}
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
"✅ Updates installed in $($elapsed)s."
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}