2024-09-19 01:31:54 +01:00
|
|
|
#!/bin/sh -e
|
|
|
|
|
|
|
|
. ../common-script.sh
|
|
|
|
|
|
|
|
cleanup_system() {
|
|
|
|
printf "%b\n" "${YELLOW}Performing system cleanup...${RC}"
|
|
|
|
case "$PACKAGER" in
|
|
|
|
apt-get|nala)
|
|
|
|
"$ESCALATION_TOOL" "$PACKAGER" clean
|
2024-09-30 08:08:40 +01:00
|
|
|
"$ESCALATION_TOOL" "$PACKAGER" autoremove -y
|
2024-09-19 01:31:54 +01:00
|
|
|
"$ESCALATION_TOOL" du -h /var/cache/apt
|
|
|
|
;;
|
|
|
|
zypper)
|
|
|
|
"$ESCALATION_TOOL" "$PACKAGER" clean -a
|
|
|
|
"$ESCALATION_TOOL" "$PACKAGER" tidy
|
|
|
|
"$ESCALATION_TOOL" "$PACKAGER" cc -a
|
|
|
|
;;
|
|
|
|
dnf)
|
|
|
|
"$ESCALATION_TOOL" "$PACKAGER" clean all
|
|
|
|
"$ESCALATION_TOOL" "$PACKAGER" autoremove -y
|
|
|
|
;;
|
|
|
|
pacman)
|
|
|
|
"$ESCALATION_TOOL" "$PACKAGER" -Sc --noconfirm
|
2024-10-03 11:13:46 +01:00
|
|
|
"$ESCALATION_TOOL" "$PACKAGER" -Rns $(pacman -Qtdq) --noconfirm > /dev/null 2>&1
|
2024-09-19 01:31:54 +01:00
|
|
|
;;
|
|
|
|
*)
|
2024-10-24 20:59:23 +01:00
|
|
|
printf "%b\n" "${RED}Unsupported package manager: ${PACKAGER}. Skipping.${RC}"
|
2024-09-19 01:31:54 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
common_cleanup() {
|
2024-10-24 20:59:23 +01:00
|
|
|
if [ -d /var/tmp ]; then
|
|
|
|
"$ESCALATION_TOOL" find /var/tmp -type f -atime +5 -delete
|
|
|
|
fi
|
|
|
|
if [ -d /tmp ]; then
|
|
|
|
"$ESCALATION_TOOL" find /tmp -type f -atime +5 -delete
|
|
|
|
fi
|
|
|
|
if [ -d /var/log ]; then
|
|
|
|
"$ESCALATION_TOOL" find /var/log -type f -name "*.log" -exec truncate -s 0 {} \;
|
|
|
|
fi
|
2024-09-19 01:31:54 +01:00
|
|
|
"$ESCALATION_TOOL" journalctl --vacuum-time=3d
|
|
|
|
}
|
|
|
|
|
|
|
|
clean_data() {
|
2024-09-22 18:59:39 +01:00
|
|
|
printf "%b" "${YELLOW}Clean up old cache files and empty the trash? (y/N): ${RC}"
|
2024-09-19 01:31:54 +01:00
|
|
|
read -r clean_response
|
|
|
|
case $clean_response in
|
|
|
|
y|Y)
|
|
|
|
printf "%b\n" "${YELLOW}Cleaning up old cache files and emptying trash...${RC}"
|
2024-10-24 20:59:23 +01:00
|
|
|
if [ -d "$HOME/.cache" ]; then
|
|
|
|
find "$HOME/.cache/" -type f -atime +5 -delete
|
|
|
|
fi
|
|
|
|
if [ -d "$HOME/.local/share/Trash" ]; then
|
|
|
|
find "$HOME/.local/share/Trash" -mindepth 1 -delete
|
|
|
|
fi
|
2024-09-19 01:31:54 +01:00
|
|
|
printf "%b\n" "${GREEN}Cache and trash cleanup completed.${RC}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
printf "%b\n" "${YELLOW}Skipping cache and trash cleanup.${RC}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
checkEnv
|
|
|
|
checkEscalationTool
|
|
|
|
cleanup_system
|
|
|
|
common_cleanup
|
|
|
|
clean_data
|