PowerShell/Scripts/install-updates.ps1

42 lines
977 B
PowerShell
Raw Normal View History

2021-09-27 10:38:12 +02:00
<#
2021-09-17 16:14:05 +02:00
.SYNOPSIS
2021-10-04 21:29:23 +02:00
Installs updates for the local machine (needs admin rights)
2021-09-17 16:14:05 +02:00
.DESCRIPTION
2021-10-04 21:29:23 +02:00
install-updates.ps1
2021-09-17 16:14:05 +02:00
.EXAMPLE
2021-09-24 17:19:49 +02:00
PS> ./install-updates
2021-09-17 16:14:05 +02:00
.NOTES
Author: Markus Fleschutz · License: CC0
.LINK
https://github.com/fleschutz/PowerShell
#>
#Requires -RunAsAdministrator
try {
$StopWatch = [system.diagnostics.stopwatch]::startNew()
if ($IsLinux) {
2021-10-15 23:09:08 +02:00
"⏳ Fetching update infos for installed Debian packages (step 1/4)..."
2021-09-28 16:28:53 +02:00
& sudo apt update
2021-09-17 16:21:19 +02:00
2021-10-15 23:09:08 +02:00
"⏳ Upgrading installed Debian packages (step 2/4)..."
2021-09-29 08:18:28 +02:00
& sudo apt upgrade --yes
2021-09-17 16:21:19 +02:00
2021-10-15 23:09:08 +02:00
"⏳ Removing obsolete Debian packages (step 3/4)..."
2021-09-29 08:18:28 +02:00
& sudo apt autoremove --yes
2021-09-17 16:21:19 +02:00
2021-10-15 23:09:08 +02:00
"⏳ Upgrading installed Snap packages (step 4/4)..."
2021-09-28 16:28:53 +02:00
& sudo snap refresh
2021-09-17 16:14:05 +02:00
} else {
"Sorry, not supported yet"
}
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
"✔️ installed updates in $Elapsed sec"
2021-09-27 10:09:45 +02:00
exit 0 # success
2021-09-17 16:14:05 +02:00
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}