mirror of
https://github.com/acedanger/shell.git
synced 2025-12-06 03:20:12 -08:00
feat: Enhance update script with dynamic log file location and additional package management features
This commit is contained in:
52
update.sh
52
update.sh
@@ -59,7 +59,13 @@ readonly CYAN='\033[0;36m'
|
|||||||
readonly NC='\033[0m' # No Color
|
readonly NC='\033[0m' # No Color
|
||||||
|
|
||||||
# Configuration
|
# 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
|
# Global variables
|
||||||
ERRORS_DETECTED=0
|
ERRORS_DETECTED=0
|
||||||
@@ -516,6 +522,9 @@ perform_system_update() {
|
|||||||
increment_error "Failed to upgrade packages with nala"
|
increment_error "Failed to upgrade packages with nala"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
log_message "INFO" "Cleaning up unused packages with nala..."
|
||||||
|
sudo nala autoremove -y
|
||||||
;;
|
;;
|
||||||
dnf)
|
dnf)
|
||||||
log_message "INFO" "Checking for updates with dnf..."
|
log_message "INFO" "Checking for updates with dnf..."
|
||||||
@@ -526,6 +535,9 @@ perform_system_update() {
|
|||||||
increment_error "Failed to upgrade packages with dnf"
|
increment_error "Failed to upgrade packages with dnf"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
log_message "INFO" "Cleaning up unused packages with dnf..."
|
||||||
|
sudo dnf autoremove -y
|
||||||
;;
|
;;
|
||||||
apt)
|
apt)
|
||||||
log_message "INFO" "Updating package lists with apt..."
|
log_message "INFO" "Updating package lists with apt..."
|
||||||
@@ -539,12 +551,42 @@ perform_system_update() {
|
|||||||
increment_error "Failed to upgrade packages with apt"
|
increment_error "Failed to upgrade packages with apt"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
log_message "INFO" "Cleaning up unused packages with apt..."
|
||||||
|
sudo apt autoremove -y && sudo apt autoclean
|
||||||
;;
|
;;
|
||||||
esac
|
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"
|
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
|
# Main Execution
|
||||||
################################################################################
|
################################################################################
|
||||||
@@ -583,6 +625,9 @@ main() {
|
|||||||
upgrade_oh_my_zsh
|
upgrade_oh_my_zsh
|
||||||
perform_system_update
|
perform_system_update
|
||||||
|
|
||||||
|
# signal is made available using distrobox and is only available on `mini`
|
||||||
|
update_signal
|
||||||
|
|
||||||
# Restart services
|
# Restart services
|
||||||
if [[ "$SKIP_SERVICES" != true ]]; then
|
if [[ "$SKIP_SERVICES" != true ]]; then
|
||||||
if [[ "$SKIP_PLEX" != true ]]; then
|
if [[ "$SKIP_PLEX" != true ]]; then
|
||||||
@@ -594,6 +639,11 @@ main() {
|
|||||||
debug_log "Skipping all service management due to --skip-services flag"
|
debug_log "Skipping all service management due to --skip-services flag"
|
||||||
fi
|
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
|
# Final status
|
||||||
if [[ $ERRORS_DETECTED -eq 0 ]]; then
|
if [[ $ERRORS_DETECTED -eq 0 ]]; then
|
||||||
log_message "INFO" "System update completed successfully!"
|
log_message "INFO" "System update completed successfully!"
|
||||||
|
|||||||
Reference in New Issue
Block a user