From 9b9f69c98f387ae7c29de81e061acd26eeaf33d0 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Mon, 16 Aug 2021 16:51:31 +0200 Subject: [PATCH] Improve upgrade-ubuntu.ps1 --- Data/scripts.csv | 1 + README.md | 1 + Scripts/upgrade-ubuntu.ps1 | 77 +++++++++++++++++++++++++------------- 3 files changed, 54 insertions(+), 25 deletions(-) diff --git a/Data/scripts.csv b/Data/scripts.csv index 6fd7fc04..fc6ae7a0 100644 --- a/Data/scripts.csv +++ b/Data/scripts.csv @@ -204,6 +204,7 @@ translate-text.ps1, translates the given text into other languages turn-volume-up.ps1, turns the audio volume up (+10% by default) turn-volume-down.ps1, turns the audio volume down (-10% by default) unmute-audio.ps1, unmutes audio +upgrade-ubuntu.ps1, upgrades Ubuntu Linux to the latest (LTS) release upload-file.ps1, uploads the local file to the given FTP server voice-control.ps1, executes the PowerShell scripts by voice wakeup.ps1, sends a magic packet to the given computer, waking him up diff --git a/README.md b/README.md index f78d745c..189147df 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ Mega Collection of PowerShell Scripts * [poweroff.ps1](Scripts/poweroff.ps1) - halts the local computer (needs admin rights) * [query-smart-data.ps1](Scripts/query-smart-data.ps1) - queries the S.M.A.R.T. data of your HDD/SSD's * [reboot.ps1](Scripts/reboot.ps1) - reboots the local computer (needs admin rights) +* [upgrade-ubuntu.ps1](Scripts/upgrade-ubuntu.ps1) - upgrades Ubuntu Linux to the latest (LTS) release * [wakeup.ps1](Scripts/wakeup.ps1) - sends a magic packet to the given computer, waking him up 💻 Scripts for the Desktop diff --git a/Scripts/upgrade-ubuntu.ps1 b/Scripts/upgrade-ubuntu.ps1 index 4cd360e6..03e05574 100644 --- a/Scripts/upgrade-ubuntu.ps1 +++ b/Scripts/upgrade-ubuntu.ps1 @@ -1,29 +1,56 @@ +<# +.SYNOPSIS + upgrade-ubuntu.ps1 +.DESCRIPTION + Upgrades Ubuntu Linux to the latest (LTS) release +.EXAMPLE + PS> .\upgrade-ubuntu.ps1 +.LINK + https://github.com/fleschutz/PowerShell +.NOTES + Author: Markus Fleschutz + License: CC0 +#> +try { + "" + "Step 1/4: Perform a Backup" + "--------------------------" + "It's strongly recommended to perform a backup of your data BEFORE upgrading the OS!" + $Confirm = read-host "Press to continue..." + "" + "Step 2/4: Install update-manager-core, Upgrade Packages & Reboot" + "----------------------------------------------------------------" + $Confirm = read-host "Enter to perform this step (otherwise this step will be skipped)" + if ($Confirm -eq "yes") { + sudo apt install update-manager-core + sudo apt update + sudo apt list --upgradable + sudo apt upgrade + sudo reboot + } -"Step 1: Make a backup" - -"Step 2: Upgrade all installed packages & reboot" - -sudo apt update -sudo apt list --upgradable -sudo apt upgrade -sudo reboot - -"Step 3: Remove unused old kernel modules" - -sudo apt --purge autoremove - -"Step 4: Make sure update-manager-core package is installed" - -sudo apt install update-manager-core - -"Step 5: Upgrade Ubuntu & reboot" - -sudo do-release-upgrade # to latest LTS version - -sudo do-release-upgrade -d # to latest supported release - -sudo reboot - + "" + "Step 3/4: Remove obsolete Kernel Modules" + "----------------------------------------" + $Confirm = read-host "Enter to perform this step (otherwise this step will be skipped)" + if ($Confirm -eq "yes") { + sudo apt --purge autoremove + } + "" + "Step 4/4: Upgrade Ubuntu & Reboot" + "---------------------------------" + $Confirm = read-host "Enter to perform this step (otherwise this step will be skipped)" + if ($Confirm -eq "yes") { + sudo do-release-upgrade # to latest LTS version + #sudo do-release-upgrade -d # to latest supported release + sudo reboot + } + "Done." + exit 0 +} catch { + write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + exit 1 +}