-
-
Notifications
You must be signed in to change notification settings - Fork 545
Expand file tree
/
Copy pathinstall-updates.ps1
More file actions
executable file
·74 lines (67 loc) · 2.41 KB
/
install-updates.ps1
File metadata and controls
executable file
·74 lines (67 loc) · 2.41 KB
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
<#
.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 requirements...
✅ Drive C: uses 56% of 1TB: 441GB free
✅ Swap space uses 22% of 4GB: 3GB free
⏳ (2/2) Querying Microsoft Store...
...
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
try {
$stopWatch = [system.diagnostics.stopwatch]::startNew()
Write-Host "`n⏳ Checking requirements..." -foregroundColor green
& "$PSScriptRoot/check-power.ps1"
& "$PSScriptRoot/check-smart-devices.ps1"
if ($IsLinux -or $IsMacOS) {
& "$PSScriptRoot/check-drive-space.ps1" /
} else {
& "$PSScriptRoot/check-drive-space.ps1" C
}
& "$PSScriptRoot/check-swap-space.ps1"
Start-Sleep -seconds 3
if (Get-Command apt -ErrorAction SilentlyContinue) {
Write-Host "`n⏳ Querying APT package updates..." -foregroundColor green
& sudo apt update
Write-Host "`n⏳ Removing obsolete packages to save space..." -foregroundColor green
& sudo apt autoremove --yes
Write-Host "`n⏳ Upgrading installed packages..." -foregroundColor green
& sudo apt upgrade --yes
}
if (Get-Command snap -ErrorAction SilentlyContinue) {
Write-Host "`n⏳ Upgrading installed Snaps..." -foregroundColor green
& sudo snap refresh
}
if (Get-Command softwareupdate -ErrorAction SilentlyContinue) {
Write-Host "`n⏳ Updating software..." -foregroundColor green
& sudo softwareupdate -i -a
}
if (Get-Command winget -errorAction SilentlyContinue) {
Write-Host "`n⏳ Upgrading apps from Microsoft Store..." -foregroundColor green
& winget upgrade --all --source=msstore --include-unknown
}
if (Get-Command winget -errorAction SilentlyContinue) {
Write-Host "`n⏳ Upgrading apps from WinGet..." -foregroundColor green
& winget upgrade --all --source=winget --include-unknown
}
if (Get-Command choco -errorAction SilentlyContinue) {
Write-Host "`n⏳ Upgrading by Chocolatey..." -foregroundColor green
& choco upgrade all -y
}
& "$PSScriptRoot/check-pending-reboot.ps1"
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
"✅ Updates installed in $($elapsed)s."
exit 0 # success
} catch {
"⚠️ ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
exit 1
}