THE PROBLEM
Keeping a Linux system fully updated usually means doing several things by hand:
-
Update APT package lists.
-
Upgrade installed packages.
-
Remove unused dependencies and cached files.
-
Update Flatpak apps (if you use Flatpak).
-
Update firmware via fwupd (if available).
-
Decide whether to reboot or shut down.
None of that is hard, but it is repetitive and easy to skip steps, especially firmware updates.
This script turns that whole workflow into a single, safe command.
REQUIREMENTS
This script assumes:
Package manager
Uses APT.
Example: Debian, Ubuntu, Linux Mint and similar.
Init system
Uses systemd (for systemctl reboot/poweroff).
Shell
bash (script uses #!/usr/bin/env bash and set -euo pipefail).
Location & name
You will save it as /usr/local/sbin/update.
You can run it with:
Privileges
Your user has sudo rights.
Optional components
-
Flatpak (optional).
If not installed, Flatpak steps are skipped.
-
fwupd (fwupdmgr, optional).
If not installed, firmware steps are skipped.
Other tools
mktemp, grep, tee.
Present on any normal distro.
If an optional tool is missing, the script just prints a message and continues.
WHAT THE SCRIPT AUTOMATES
APT updates
apt update
Refresh package lists from repositories.
apt upgrade
Install updated versions of packages.
apt autoremove
Remove packages that are no longer needed as dependencies.
apt autoclean
Remove old cached .deb files.
Flatpak updates (if Flatpak is installed)
Flatpak has its own update mechanism, separate from APT:
flatpak update
Updates Flatpak apps and runtimes.
flatpak uninstall --unused
Removes unused runtimes and extensions.
Firmware updates (if fwupdmgr is installed)
fwupdmgr talks to the Linux Vendor Firmware Service (LVFS) to update device firmware:
fwupdmgr refresh --force
Refresh metadata.
fwupdmgr get-updates
Check for available firmware updates.
fwupdmgr update
Apply or stage those updates for the next reboot.
fwupdmgr uses exit codes such as:
The script treats 0 and 2 as non-fatal. Other codes are treated as errors.
Safety features
set -euo pipefail
-e: exit on error.
-u: fail on unset variables.
-o pipefail: fail if any command in a pipeline fails.
sudo -v at the beginning
Caches sudo auth so the script does not get stuck mid-run asking for a password.
Command checks
Uses command -v flatpak and command -v fwupdmgr so it only runs those sections if the tools exist.
SCRIPT: SAFE SYSTEM AND FIRMWARE UPDATER
Paste this into a file named:
/usr/local/sbin/update
Then mark it executable (see “HOW I USE IT” below).
HOW I USE IT
Save the script as:
/usr/local/sbin/update
Make it executable:
Run it when you want to fully update the system:
At the prompt, choose:
-
r = reboot after updates.
-
s = shut down after updates.
-
n = do nothing (you can reboot later).
That’s it: one script to safely update packages, Flatpaks, and firmware in a single run.
Comments
Post a Comment