Streamlining Your Debian/Ubuntu Updates: Introducing Linux Mint Update script

Page content

Updater

Streamlining Your Debian/Ubuntu Updates: Introducing Linux Mint Update script

Maintaining an up-to-date Linux system is paramount for security and performance. However, the process of updating system packages, individual applications like Discord, Flatpak installations, and desktop environment components can be fragmented and time-consuming. This article introduces a Bash script designed to automate this task on Debian/Ubuntu-based systems. I personally created this script to help keep my Linux Mint Desktop updated.

Purpose

The core function is to provide a single command to update a Linux Mint system. This includes refreshing system packages via apt, managing Discord installations or updates, updating Flatpak applications and runtimes, and refreshing Cinnamon desktop “Spices.”

Use Cases

The systemupdate.sh script adds value in several common scenarios:

  • Automated Desktop Maintenance: Simplifies the update routine for users of Debian-based distributions, particularly those leveraging the Cinnamon desktop environment,
  • Scheduled Updates: Facilitates integration with cron or systemd timers for fully automated, regular system upkeep without manual intervention.
  • System Standardisation: Aids users in quickly bringing newly provisioned Debian/Ubuntu systems to a current and consistent software state.

Prerequisites

Successful execution of the script requires the following:

  • Operating System: A Debian-based Linux distribution, Tested on Linux Mint 22.1 x86_64, will require changes for other systems.
  • Shell: bash.
  • Permissions: sudo privileges for package management and system-level changes.
  • Required Utilities:
    • apt-get, dpkg, apt-mark
    • awk, grep
    • curl
    • mktemp, pushd, popd, rm
  • Flatpak: The flatpak utility, if Flatpak application updates are intended.
  • Cinnamon Desktop: The cinnamon-spice-updater utility for Cinnamon Spice updates (typically present in a Cinnamon DE installation).
  • Network Access: An active internet connection to download updates.

How the Script Works

The script executes a sequential workflow to update system components:

  1. APT Package Management: It begins by refreshing apt package lists. Any “held” packages are automatically unheld to ensure they are included in the upgrade process. The script then performs a dist-upgrade followed by an upgrade to comprehensively update all system packages. Finally, it removes unused dependency packages (autoremove) and cleans the local apt cache (autoclean).
  2. Discord Update Logic: The script checks if Discord is installed and identifies its version. It then fetches the latest version information directly from Discord’s API. If an update is available, or if Discord is not installed, the script downloads the latest .deb package to a temporary directory, installs it using dpkg, and resolves any dependencies using apt-get install -f.
  3. Flatpak Management: It checks for available Flatpak application updates. If any are found, it proceeds to update them. Subsequently, it removes any unused Flatpak runtimes to free disk space.
  4. Cinnamon Spice Updates: For systems with the Cinnamon desktop environment, the script invokes cinnamon-spice-updater --update-all to update installed applets, desklets, extensions, and themes.

The script is configured with set -e, causing it to exit immediately if any command fails, thereby preventing subsequent problematic operations.

Quick-Start Guide

To use the script:

  1. Save the Script: Copy the script content (provided below) into a file named system-and-discord-update.sh.
  2. Make it Executable:
    chmod +x system-and-discord-update.sh
    
  3. Run the Script:
    ./system-and-discord-update.sh
    
    You will be prompted for your sudo password as required by the script’s operations.

The Script

#!/usr/bin/env bash
#
# system-and-discord-update.sh
#
# 1) Updates and upgrades all packages on a Debian/Ubuntu-based system
# 2) Cleans up unused dependencies and package caches
# 3) Calls the Discord update script
# 4) Updates flatpak
# 5) Handles held APT updates and phasing
#

set -e

echo "[INFO] Starting full system update..."

# 1) Refresh the package list
echo "[INFO] Running: sudo apt-get update"
sudo apt-get update

# 2) Check for held packages and unhold them
echo "[INFO] Checking for held packages..."
held_packages=$(dpkg --get-selections | grep hold | awk '{print $1}')

if [ -n "$held_packages" ]; then
    echo "[INFO] Unholding the following packages: $held_packages"
    for package in $held_packages; do
        echo "[INFO] Unholding package: $package"
        sudo apt-mark unhold "$package"
    done
else
    echo "[INFO] No held packages found."
fi

# 3) Upgrade all packages to the newest versions (including those kept back)
echo "[INFO] Running: sudo apt-get -y dist-upgrade"
sudo apt-get -y dist-upgrade

# 4) Optionally upgrade the rest of the packages using upgrade
echo "[INFO] Running: sudo apt-get -y upgrade"
sudo apt-get -y upgrade

echo "[INFO] System upgrade is complete."

# 5) Remove unused packages
echo "[INFO] Removing unused packages..."
sudo apt-get -y autoremove

# 6) Clean up the package cache
echo "[INFO] Cleaning up apt cache (autoclean)..."
sudo apt-get autoclean

# If you want to clear out *all* downloaded archive files:
# echo "[INFO] Cleaning up apt cache completely (clean)..."
# sudo apt-get clean

echo "[INFO] System cleanup is complete."

# 7) Now calling the Discord update script (update-discord.sh)
echo "[INFO] Now calling the Discord update script (update-discord.sh)..."
# Function: Extract the Discord version from the .deb file URL (e.g. "discord-0.0.90.deb" -> "0.0.90")
extract_version_from_url() {
    local url="$1"
    # Grab the substring that matches discord-<digits>.<digits>.<digits>.deb
    echo "$url" | grep -oP 'discord-\K[0-9]+\.[0-9]+\.[0-9]+'
}

echo "[INFO] Checking if Discord is installed..."
INSTALLED_VERSION=""
if dpkg-query -W -f='${Status}' discord 2>/dev/null | grep -q "install ok installed"; then
    INSTALLED_VERSION="$(dpkg-query --showformat='${Version}' --show discord 2>/dev/null || true)"
    echo "[INFO] Discord is installed. Installed version: $INSTALLED_VERSION"
else
    echo "[INFO] Discord is not currently installed."
fi

echo "[INFO] Retrieving final Discord .deb URL by following redirects..."
DOWNLOAD_URL="$(curl -Ls -o /dev/null -w '%{url_effective}' 'https://discord.com/api/download?platform=linux')"

if [ -z "$DOWNLOAD_URL" ]; then
    echo "[ERROR] Could not retrieve Discord download URL."
    echo "[ERROR] Check your internet connection, proxy settings, or firewall."
fi

echo "[INFO] Discord .deb URL found: $DOWNLOAD_URL"

echo "[INFO] Extracting remote Discord version..."
REMOTE_VERSION="$(extract_version_from_url "$DOWNLOAD_URL")"
if [ -z "$REMOTE_VERSION" ]; then
    echo "[ERROR] Could not parse remote Discord version from URL: $DOWNLOAD_URL"
fi

echo "[INFO] Latest available Discord version: $REMOTE_VERSION"

# Compare versions if already installed
if [ -n "$INSTALLED_VERSION" ]; then
    if [ "$INSTALLED_VERSION" = "$REMOTE_VERSION" ]; then
        echo "[INFO] Installed version $INSTALLED_VERSION matches the latest version $REMOTE_VERSION."
        echo "[INFO] No update is required. Exiting."
    else
        echo "[INFO] A newer version is available. Proceeding with download and install."

        # Download and install
        TMP_DIR="$(mktemp -d)"
        echo "[INFO] Downloading Discord $REMOTE_VERSION into temporary directory: $TMP_DIR"
        pushd "$TMP_DIR" >/dev/null

        echo "[INFO] Downloading the .deb package..."
        curl -LO "$DOWNLOAD_URL"

        echo "[INFO] Installing Discord. You may be prompted for sudo password."
        sudo dpkg -i discord-*.deb

        # If any dependencies are missing, fix them
        echo "[INFO] Fixing missing dependencies (if any)..."
        sudo apt-get install -f

        popd >/dev/null
        rm -rf "$TMP_DIR"

        echo "[INFO] Discord version $REMOTE_VERSION installed (or upgraded) successfully!"
    fi
else
    echo "[INFO] No installed version found. Installing Discord $REMOTE_VERSION."
fi

# 8) Check for Flatpak updates
echo "[INFO] Checking for Flatpak updates... "
updates=$(flatpak remote-ls --updates --columns=application 2>/dev/null)

if [ -z "$updates" ]; then
    echo "[INFO] No Flatpak updates are available."
else
    echo "[INFO] The following Flatpaks have updates available:"
    echo "$updates"
    echo

    echo "[INFO] Updating Flatpak applications..."
    flatpak update -y
fi

# 9) Clean up unused Flatpak runtimes
echo "[INFO] Removing any unused Flatpak runtimes..."
flatpak remove --unused -y
echo "[INFO] Unused Flatpak runtimes removed."

# 10) Update cinnamon-spice applications
echo "[INFO] Updating cinnamon-spice applications."
cinnamon-spice-updater --update-all
echo "[INFO] Updates complete."

echo "[INFO]"
echo "[INFO] All updates (system, flatpak, cinnamon-spice, discord) are complete."

Security Considerations

  • Privileged Operations: The script uses sudo for many of its core functions. It must be run by a user with appropriate administrative privileges. Ensure the script itself is obtained from a trusted source and its integrity is verified to prevent execution of malicious commands with elevated rights.
  • External Content: The Discord update mechanism relies on downloading a .deb package from https://discord.com/api/download?platform=linux. The security of this step is contingent upon the security of the Discord distribution channel and the integrity of the downloaded file. The script uses curl with the -L flag, which follows redirects.
  • APT, Flatpak, and Cinnamon Repositories: The security of updates fetched by apt, flatpak, and cinnamon-spice-updater depends on the correct configuration and trustworthiness of their respective software repositories and the GPG keys used for package verification.

Limitations

  • Distribution Specificity: This script is tailored for Debian/Ubuntu-based systems and will not function correctly on distributions using different package management systems (e.g., dnf, pacman).
  • Cinnamon DE Focus: The Cinnamon Spice update feature targets the Cinnamon Desktop Environment. On systems without cinnamon-spice-updater, this part of the script will fail. This also fails when running remote over SSH.
  • Discord Update Scope: The Discord update logic is specific to installations managed via .deb packages obtained from the official source. It does not manage Discord installations from other sources like Snap or Flatpak.
  • Basic Error Reporting: While set -e stops the script on any error, detailed diagnostics for failures within external tools (like apt-get) might require manual investigation.

Future Work / Enhancement Ideas

  • Selective Updates: Introduce command-line flags to allow users to run only specific parts of the script (e.g., only system updates, or only Discord updates).
  • Improved Error Handling: Implement more specific error checks and potentially offer more descriptive error messages or logging.
  • Desktop Environment Check: Before attempting Cinnamon Spice updates, verify that cinnamon-spice-updater is available and the system is likely running Cinnamon.

Conclusion

The script provides a utility for automating and simplifying the update process on Debian/Ubuntu systems. By consolidating multiple update tasks into a single script, it promotes regular maintenance, which is essential for a secure and stable computing environment. Thius script has become part of my weekly tasks to keep my systems up to date and I extend its funcations as new applications require specific steps to update, like Discord.

References

Blog Header image source, OpenAI, “Header image generated with DALL·E 3,” created 27 May 2025. Unpublished.