139 lines
4.5 KiB
Bash
Executable File
139 lines
4.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# ---
|
|
# @file_name: jau.sh
|
|
# @version: 1.0.0
|
|
# @description: Full system update handler for Fedora-based systems with DNF and Flatpak
|
|
# @author: Jamie Albert (empty_produce)
|
|
# @author_contact: <mailto:empty.produce@flatmail.me>
|
|
# @license: GNU Affero General Public License v3.0 (Included in LICENSE)
|
|
# Copyright (C) 2025, Jamie Albert
|
|
# ---
|
|
set -euo pipefail
|
|
|
|
# ---
|
|
# @description: Perform initial setup checks. Verifies required base commands (dnf, sudo) are available.
|
|
# @return_code: [2] Required tool 'sudo' not found.
|
|
# @return_code: [3] Required tool 'dnf' not found.
|
|
# shellcheck disable=1091,1090
|
|
# ---
|
|
setup() {
|
|
. /usr/local/share/dao/libs/libs_dao.sh
|
|
|
|
command -v sudo >/dev/null || dao::error 2 "sudo not found"
|
|
sudo sh -c 'command -v dnf >/dev/null' || dao::error 3 "dnf not found (script requires a DNF-based system)"
|
|
}
|
|
|
|
# ---
|
|
# @description: Install package if missing.
|
|
# @arg: $1 - The name of the package/command to check and install.
|
|
# @return_code: [1] General dao::error (inherits from set -e).
|
|
# @return_code: [4] Failed to install the specified package.
|
|
# ---
|
|
install_if_missing() {
|
|
declare pkg="$1"
|
|
if ! command -v "$pkg" &>/dev/null; then
|
|
dao::info "Installing missing dependency: $pkg"
|
|
sudo dnf install -y "$pkg" || dao::error 4 "Failed to install $pkg"
|
|
else
|
|
dao::info "Dependency satisfied: $pkg"
|
|
fi
|
|
}
|
|
|
|
# ---
|
|
# @description: Refresh DNF cache and update all packages.
|
|
# @return_code: [1] General dao::error (inherits from set -e).
|
|
# @return_code: [5] Failed to refresh DNF cache.
|
|
# @return_code: [6] DNF update failed.
|
|
# ---
|
|
run_dnf_update() {
|
|
dao::info "Refreshing DNF cache..."
|
|
sudo dnf -y makecache --refresh || dao::error 5 "Failed to refresh DNF cache"
|
|
|
|
dao::info "Updating all packages..."
|
|
sudo dnf -y update || dao::error 6 "DNF update failed"
|
|
}
|
|
|
|
# ---
|
|
# @description: Handle leftover RPM configuration files.
|
|
# @return_code: [1] General dao::error (inherits from set -e).
|
|
# @return_code: [7] rpmconf execution failed.
|
|
# ---
|
|
handle_rpmconf() {
|
|
if command -v rpmconf &>/dev/null; then
|
|
dao::info "Handling leftover RPM configuration files..."
|
|
sudo rpmconf -a || dao::error 7 "rpmconf execution failed"
|
|
else
|
|
dao::info "rpmconf not available; skipping config file handling"
|
|
fi
|
|
}
|
|
|
|
# ---
|
|
# @description: Install security updates if any exist.
|
|
# @return_code: [1] General dao::error (inherits from set -e).
|
|
# @return_code: [8] Security update failed.
|
|
# ---
|
|
install_security_updates() {
|
|
dao::info "Checking for security updates..."
|
|
# dnf check-update returns 100 if updates are available, 1 on error, 0 if not.
|
|
# We only want to proceed if it returns 100 (success with updates) or 0 (no updates).
|
|
# Using || true prevents set -e from triggering on exit code 100.
|
|
if sudo dnf check-update --security &>/dev/null || [[ $? -eq 100 ]]; then
|
|
dao::info "Installing security updates..."
|
|
sudo dnf -y update --security || dao::error 8 "Security update failed"
|
|
else
|
|
dao::info "No security updates available."
|
|
fi
|
|
}
|
|
|
|
# ---
|
|
# @description: Remove unused packages and clean cache.
|
|
# @return_code: [1] General dao::error (inherits from set -e).
|
|
# @return_code: [9] DNF autoremove failed.
|
|
# @return_code: [10] DNF clean failed.
|
|
# ---
|
|
cleanup_packages() {
|
|
dao::info "Removing unused dependencies..."
|
|
sudo dnf -y autoremove || dao::error 9 "DNF autoremove failed"
|
|
|
|
dao::info "Cleaning cached package data..."
|
|
sudo dnf clean all || dao::error 10 "DNF clean failed"
|
|
}
|
|
|
|
# ---
|
|
# @description: Update Flatpak applications and remove unused runtimes.
|
|
# @return_code: [1] General dao::error (inherits from set -e).
|
|
# @return_code: [11] Flatpak update failed.
|
|
# @return_code: [12] Flatpak cleanup failed.
|
|
# ---
|
|
update_flatpak() {
|
|
if command -v flatpak &>/dev/null; then
|
|
dao::info "Updating Flatpak applications..."
|
|
flatpak update -y || dao::error 11 "Flatpak update failed"
|
|
|
|
dao::info "Removing unused Flatpak runtimes..."
|
|
flatpak uninstall --unused -y || dao::error 12 "Flatpak cleanup failed"
|
|
else
|
|
dao::info "Flatpak not installed; skipping Flatpak updates"
|
|
fi
|
|
}
|
|
|
|
# ---
|
|
# @description: Main routine.
|
|
# @arg: $@ - Command-line arguments (currently unused).
|
|
# @return_code: [1] General dao::error (inherits from set -e).
|
|
# @return_code: [N] Errors from called functions (e.g., setup, install_if_missing, etc.).
|
|
# ---
|
|
main() {
|
|
setup
|
|
dao::info "Starting system updates..."
|
|
install_if_missing rpmconf
|
|
install_if_missing flatpak
|
|
run_dnf_update
|
|
handle_rpmconf
|
|
install_security_updates
|
|
cleanup_packages
|
|
update_flatpak
|
|
dao::info "System updates completed successfully."
|
|
}
|
|
|
|
main "$@" |