Skip to content

Instantly share code, notes, and snippets.

@k3karthic
Last active October 2, 2025 11:19
Show Gist options
  • Save k3karthic/b2e0c8d99fa4a95fe6520c32dfa25cf8 to your computer and use it in GitHub Desktop.
Save k3karthic/b2e0c8d99fa4a95fe6520c32dfa25cf8 to your computer and use it in GitHub Desktop.
Fedora Silverblue - Update all toolboxes
#!/bin/bash
#
# Script to update all packages in all available Toolbox containers.
# It automatically detects the distro (Fedora, Debian, Ubuntu, Arch, etc.)
# and uses the correct package manager.
# Exit immediately if a command exits with a non-zero status.
set -e
echo "🔍 Starting update process for all Toolbox containers..."
# Get a list of container names, one per line.
# The 'toolbox list -c' command is used for its clean, machine-readable output.
containers=$(toolbox list -c | grep -v 'CONTAINER ID' | awk '{ print $2 }')
# Check if any containers were found.
if [ -z "$containers" ]; then
echo "No Toolbox containers found. Exiting."
exit 0
fi
# Loop through each container name.
for container in $containers; do
echo "---"
echo "📦 Processing container: '$container'"
# Identify the distribution by reading the ID from /etc/os-release inside the container.
# We use awk for robust parsing and tr to remove any surrounding quotes.
distro_id=$(toolbox run -c "$container" awk -F'=' '/^ID=/{print $2}' /etc/os-release | tr -d '"')
if [ -z "$distro_id" ]; then
echo "⚠️ Could not determine distribution for '$container'. Skipping."
continue
fi
echo " Distro detected: '$distro_id'"
# Set the appropriate update command based on the detected distribution ID.
update_command=""
case "$distro_id" in
fedora)
update_command="sudo dnf upgrade -y"
;;
ubuntu|debian)
update_command="sudo apt-get update && sudo apt-get upgrade -y"
;;
arch)
update_command="sudo pacman -Syu --noconfirm"
;;
*)
echo " ⚠️ Unsupported distribution '$distro_id'. Skipping update for '$container'."
continue
;;
esac
echo " Running update command: '$update_command'"
# Execute the update command inside the specific container.
if toolbox run -c "$container" sh -c "$update_command"; then
echo " ✅ Successfully updated '$container'."
else
echo " ❌ Failed to update '$container'."
fi
done
echo "---"
echo "✨ All containers have been processed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment