feat: Enhance update script with dynamic log file location and additional package management features

This commit is contained in:
Peter Wood
2025-11-30 19:19:20 -05:00
parent 1287168961
commit e2112206a5

View File

@@ -59,7 +59,13 @@ readonly CYAN='\033[0;36m'
readonly NC='\033[0m' # No Color
# Configuration
readonly LOG_FILE="/var/log/system-update.log"
if [[ -w "/var/log" ]]; then
LOG_FILE="/var/log/system-update.log"
else
LOG_FILE="$HOME/.local/share/system-update.log"
mkdir -p "$(dirname "$LOG_FILE")"
fi
readonly LOG_FILE
# Global variables
ERRORS_DETECTED=0
@@ -516,6 +522,9 @@ perform_system_update() {
increment_error "Failed to upgrade packages with nala"
return 1
fi
log_message "INFO" "Cleaning up unused packages with nala..."
sudo nala autoremove -y
;;
dnf)
log_message "INFO" "Checking for updates with dnf..."
@@ -526,6 +535,9 @@ perform_system_update() {
increment_error "Failed to upgrade packages with dnf"
return 1
fi
log_message "INFO" "Cleaning up unused packages with dnf..."
sudo dnf autoremove -y
;;
apt)
log_message "INFO" "Updating package lists with apt..."
@@ -539,12 +551,42 @@ perform_system_update() {
increment_error "Failed to upgrade packages with apt"
return 1
fi
log_message "INFO" "Cleaning up unused packages with apt..."
sudo apt autoremove -y && sudo apt autoclean
;;
esac
# Universal packages
if command -v flatpak &> /dev/null; then
log_message "INFO" "Updating Flatpak packages..."
flatpak update -y
fi
if command -v snap &> /dev/null; then
log_message "INFO" "Updating Snap packages..."
sudo snap refresh
fi
log_message "INFO" "System package update completed successfully"
}
update_signal() {
# check if hostname is `mini`
if [[ "$(hostname)" != "mini" ]]; then
debug_log "Signal update is only available on host 'mini'"
return 0
fi
# check if distrobox is installed
if ! command -v distrobox-upgrade &> /dev/null; then
debug_log "distrobox is not installed"
return 0
fi
distrobox-upgrade signal
}
################################################################################
# Main Execution
################################################################################
@@ -583,6 +625,9 @@ main() {
upgrade_oh_my_zsh
perform_system_update
# signal is made available using distrobox and is only available on `mini`
update_signal
# Restart services
if [[ "$SKIP_SERVICES" != true ]]; then
if [[ "$SKIP_PLEX" != true ]]; then
@@ -594,6 +639,11 @@ main() {
debug_log "Skipping all service management due to --skip-services flag"
fi
# Check for reboot requirement
if [[ -f /var/run/reboot-required ]]; then
log_message "WARN" "A system reboot is required to complete the update."
fi
# Final status
if [[ $ERRORS_DETECTED -eq 0 ]]; then
log_message "INFO" "System update completed successfully!"