|
| 1 | +#!/bin/sh -e |
| 2 | + |
| 3 | +. ../common-script.sh |
| 4 | + |
| 5 | +cleanup_system() { |
| 6 | + printf "%b\n" "${YELLOW}Performing system cleanup...${RC}" |
| 7 | + case "$PACKAGER" in |
| 8 | + apt-get|nala) |
| 9 | + "$ESCALATION_TOOL" "$PACKAGER" clean |
| 10 | + "$ESCALATION_TOOL" "$PACKAGER" autoremove -y |
| 11 | + "$ESCALATION_TOOL" "$PACKAGER" autoclean |
| 12 | + "$ESCALATION_TOOL" du -h /var/cache/apt |
| 13 | + "$ESCALATION_TOOL" "$PACKAGER" clean |
| 14 | + ;; |
| 15 | + zypper) |
| 16 | + "$ESCALATION_TOOL" "$PACKAGER" clean -a |
| 17 | + "$ESCALATION_TOOL" "$PACKAGER" tidy |
| 18 | + "$ESCALATION_TOOL" "$PACKAGER" cc -a |
| 19 | + ;; |
| 20 | + dnf) |
| 21 | + "$ESCALATION_TOOL" "$PACKAGER" clean all |
| 22 | + "$ESCALATION_TOOL" "$PACKAGER" autoremove -y |
| 23 | + ;; |
| 24 | + pacman) |
| 25 | + "$ESCALATION_TOOL" "$PACKAGER" -Sc --noconfirm |
| 26 | + "$ESCALATION_TOOL" "$PACKAGER" -Rns "$(pacman -Qtdq)" --noconfirm |
| 27 | + ;; |
| 28 | + *) |
| 29 | + printf "%b\n" "${RED}Unsupported package manager: $PACKAGER${RC}" |
| 30 | + return 1 |
| 31 | + ;; |
| 32 | + esac |
| 33 | +} |
| 34 | + |
| 35 | +common_cleanup() { |
| 36 | + "$ESCALATION_TOOL" find /var/tmp -type f -atime +5 -delete |
| 37 | + "$ESCALATION_TOOL" find /tmp -type f -atime +5 -delete |
| 38 | + "$ESCALATION_TOOL" find /var/log -type f -name "*.log" -exec truncate -s 0 {} \; |
| 39 | + "$ESCALATION_TOOL" journalctl --vacuum-time=3d |
| 40 | +} |
| 41 | + |
| 42 | +clean_data() { |
| 43 | + printf "%b\n" "${YELLOW}Clean up old cache files and empty the trash? (y/N): ${RC}" |
| 44 | + read -r clean_response |
| 45 | + case $clean_response in |
| 46 | + y|Y) |
| 47 | + printf "%b\n" "${YELLOW}Cleaning up old cache files and emptying trash...${RC}" |
| 48 | + find "$HOME/.cache/" -type f -atime +5 -delete |
| 49 | + find "$HOME/.local/share/Trash" -mindepth 1 -delete |
| 50 | + printf "%b\n" "${GREEN}Cache and trash cleanup completed.${RC}" |
| 51 | + ;; |
| 52 | + *) |
| 53 | + printf "%b\n" "${YELLOW}Skipping cache and trash cleanup.${RC}" |
| 54 | + ;; |
| 55 | + esac |
| 56 | +} |
| 57 | + |
| 58 | +checkEnv |
| 59 | +checkEscalationTool |
| 60 | +cleanup_system |
| 61 | +common_cleanup |
| 62 | +clean_data |
0 commit comments