From 70dd8d74e55f7c0fc9401f4d27e345f386226a67 Mon Sep 17 00:00:00 2001 From: Mashruk Kabir <120426030+mashrukk@users.noreply.github.com> Date: Thu, 19 Sep 2024 00:31:54 +0000 Subject: [PATCH] cleanup (#478) --- tabs/system-setup/system-cleanup.sh | 62 +++++++++++++++++++++++++++++ tabs/system-setup/tab_data.toml | 4 ++ 2 files changed, 66 insertions(+) create mode 100644 tabs/system-setup/system-cleanup.sh diff --git a/tabs/system-setup/system-cleanup.sh b/tabs/system-setup/system-cleanup.sh new file mode 100644 index 000000000..625bc5bf4 --- /dev/null +++ b/tabs/system-setup/system-cleanup.sh @@ -0,0 +1,62 @@ +#!/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 + "$ESCALATION_TOOL" "$PACKAGER" autoremove -y + "$ESCALATION_TOOL" "$PACKAGER" autoclean + "$ESCALATION_TOOL" du -h /var/cache/apt + "$ESCALATION_TOOL" "$PACKAGER" clean + ;; + 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 + "$ESCALATION_TOOL" "$PACKAGER" -Rns "$(pacman -Qtdq)" --noconfirm + ;; + *) + printf "%b\n" "${RED}Unsupported package manager: $PACKAGER${RC}" + return 1 + ;; + esac +} + +common_cleanup() { + "$ESCALATION_TOOL" find /var/tmp -type f -atime +5 -delete + "$ESCALATION_TOOL" find /tmp -type f -atime +5 -delete + "$ESCALATION_TOOL" find /var/log -type f -name "*.log" -exec truncate -s 0 {} \; + "$ESCALATION_TOOL" journalctl --vacuum-time=3d +} + +clean_data() { + printf "%b\n" "${YELLOW}Clean up old cache files and empty the trash? (y/N): ${RC}" + read -r clean_response + case $clean_response in + y|Y) + printf "%b\n" "${YELLOW}Cleaning up old cache files and emptying trash...${RC}" + find "$HOME/.cache/" -type f -atime +5 -delete + find "$HOME/.local/share/Trash" -mindepth 1 -delete + 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 diff --git a/tabs/system-setup/tab_data.toml b/tabs/system-setup/tab_data.toml index 6d1307b49..19dd00efd 100644 --- a/tabs/system-setup/tab_data.toml +++ b/tabs/system-setup/tab_data.toml @@ -36,6 +36,10 @@ name = "RPM Fusion Setup" description = "RPM Fusion provides software that the Fedora Project or Red Hat doesn't want to ship.\nThat software is provided as precompiled RPMs for all current Fedora versions and current Red Hat Enterprise Linux or clones versions; you can use the RPM Fusion repositories with tools like yum and PackageKit.\nFor more information visit: https://rpmfusion.org/" script = "fedora/rpm-fusion-setup.sh" +[[data]] +name = "Full System Cleanup" +script = "system-cleanup.sh" + [[data]] name = "Full System Update" description = "This command updates your system to the latest packages available for your distro"