Linux Notice App

Fully Automating System Updates on Linux


Fully Automating System Updates on Linux

Passwordless and Silent

When you step into the Linux world, especially if you are using distributions like Ubuntu, Linux Mint, or Debian, you quickly learn how vital system updates are. Even if you use different architectures like Arch Linux (considering many packages in AUR are actually converted from .deb files), the weight of Debian-based package management in the Linux ecosystem is undeniable.

But aren't you tired of opening the terminal every time and typing sudo apt update && sudo apt full-upgrade -y to update your system? Especially when there are configuration questions or the hassle of entering a sudo password during the process, it can turn into a complete waste of time.

In this article, I will explain step-by-step how to make updates fully automatic, silent, and passwordless on Debian/Ubuntu-based systems.

1. Which Update Command Should We Use?

When you search for Linux updates on the internet, you come across many commands. It's important to know their differences:

  • apt update: Checks if there are new versions of the software on the system and updates the list. (It does not install anything).
  • apt upgrade: Updates existing packages, but if it needs to install a new dependency or remove an old package, it skips that update ("kept back" error).
  • apt full-upgrade: This is the most accurate one. It updates everything, including kernel updates. It removes old conflicting packages and installs new dependencies if necessary.

So our single-command favorite is always: sudo apt update && sudo apt full-upgrade -y

2. Why Isn't Just the -y Parameter Enough?

Even if you add the -y (yes) parameter to your script, apt might sometimes pause. Because during package updates, the system might prompt you with a pink/blue screen asking, "Hey, you've modified this configuration file before. Should I install the one in the new package or keep yours?"

For full automation, we need to close this interface and tell the system to "keep the default old setting". We do this with the following environment variable and dpkg settings:

  • export DEBIAN_FRONTEND=noninteractive
  • --force-confdef and --force-confold

3. Fully Automatic Update Script

In light of all this information, we have prepared a great Bash script that checks your system's packages, silently updates them without an interface if there are any, and then performs a cleanup.

Create a file in your terminal with your favorite text editor (for example: nano ~/bin/update_system.sh) and paste the following codes into it:

#!/bin/bash
# ============================================
# System Update Script - Fully Automatic Version
# ============================================

# --- PERMISSION CHECK ---
# If the script is not running with root privileges, it restarts itself with sudo.
if [ "$EUID" -ne 0 ]; then
    echo -e "\033[1;33mAdministrator permission is required for system update...\033[0m"
    exec sudo "$0" "$@"
fi

# Set noninteractive mode to automatically skip all dpkg/apt questions
export DEBIAN_FRONTEND=noninteractive

# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
DARK_RED='\033[1;31m'
NC='\033[0m'

TIMESTAMP=$(date '+%d/%m/%Y %H:%M:%S')

clear
echo -e "${BLUE}╔══════════════════════════════════════╗${NC}"
echo -e "${BLUE}║    🔄 SYSTEM UPDATE TOOL             ║${NC}"
echo -e "${BLUE}╚══════════════════════════════════════╝${NC}"
echo -e "${DARK_RED}⏰ Start: $TIMESTAMP${NC}\n"

# Stage 1: Update package list
echo -e "${GREEN}[1/3] 📡 Updating package list...${NC}"
apt-get update
echo -e "${GREEN}✓ Package list updated.${NC}\n"

# Find the number of packages to upgrade via simulation
UPGRADABLE=$(apt-get -s full-upgrade 2>/dev/null | grep -c "^Inst")
UPGRADABLE=${UPGRADABLE:-0}

if [ "$UPGRADABLE" -gt 0 ]; then
    echo -e "${DARK_RED}📦 Number of packages to update: $UPGRADABLE${NC}\n"
    echo -e "${GREEN}[2/3] ⬆️  Upgrading packages...${NC}"
    echo -e "${DARK_RED}🔄 Update is starting... (May take a while depending on your system)${NC}"
    
    # Silent full upgrade preventing questions
    apt-get full-upgrade -y -qq \
        -o Dpkg::Options::="--force-confdef" \
        -o Dpkg::Options::="--force-confold" \
        2>/dev/null
        
    echo -e "${GREEN}✓ $UPGRADABLE packages successfully upgraded.${NC}\n"
else
    echo -e "${GREEN}📦 All packages are up to date!${NC}\n"
    echo -e "${GREEN}[2/3] ⬆️  No packages to upgrade, skipping this step.${NC}\n"
fi

# Stage 3: Cleanup
echo -e "${GREEN}[3/3] 🧹 Cleaning up unnecessary packages...${NC}"
apt-get autoremove -y -qq 2>/dev/null
apt-get autoclean -qq 2>/dev/null
echo -e "${GREEN}✓ Cleanup completed.${NC}\n"

TIMESTAMP_END=$(date '+%d/%m/%Y %H:%M:%S')
echo -e "${BLUE}╔══════════════════════════════════════╗${NC}"
echo -e "${BLUE}║    ✅ UPDATE COMPLETED!              ║${NC}"
echo -e "${BLUE}╚══════════════════════════════════════╝${NC}"
echo -e "${DARK_RED}⏰ End: $TIMESTAMP_END${NC}\n"

echo -e "${GREEN}Press any key to close...${NC}"
read -n 1 -s

After saving and exiting the file, don't forget to give execute permission to the script:
chmod +x ~/bin/update_system.sh

4. Final Touch: Preventing Sudo Password Prompts

The script works great, but when you start it, the system will ask for your sudo password for security reasons. If you want to assign this process to a shortcut or just run it by double-clicking, we need to prevent it from asking for a password.

We will configure this securely only for this specific script.

  1. Open the terminal and enter this command: sudo visudo
  2. Scroll to the bottom line of the opened file.
  3. Edit and add the following format according to your own username and file path. For example, if your username is aslan:
aslan ALL=(ALL) NOPASSWD: /home/aslan/bin/update_system.sh

Save the file and exit (Ctrl+O, Enter, Ctrl+X).

Conclusion

That's it! Now when you run your update_system.sh file (whether from the terminal or a desktop shortcut you'll create), the system won't ask you for any password, nor will it get stuck. It will show the package lists on the screen, but it will do the actual time-consuming installations completely silently in the background and present you with a report when it's done.

Happy and up-to-date Linux computing! 🐧

No comments

Powered by Blogger.