@@ -67,6 +67,33 @@ check_command() {
6767 return 0
6868}
6969
70+ # Function: cleanup_snapd
71+ # Description: Performs cleanup tasks for Snap packages by removing old revisions,
72+ # purging unused dependencies, and freeing up disk space.
73+ # Provides feedback on the cleanup process and handles errors gracefully.
74+ # Usage: Call this function to automate Snap-related cleanup tasks.
75+ cleanup_snapd () {
76+ if ! check_command snap; then
77+ return
78+ fi
79+
80+ rm -rf /var/lib/snapd/cache/*
81+
82+ # List all snaps and filter for disabled ones
83+ snap list --all | awk ' /disabled/{print $1, $3}' | while read -r snapname revision; do
84+ # Check if variables are set and not empty
85+ if [ -z " $snapname " ] || [ -z " $revision " ]; then
86+ print_err " Error: Snap name or revision is empty. Skipping..."
87+ continue
88+ fi
89+
90+ # Attempt to remove the snap revision
91+ if ! snap remove " $snapname " --revision=" $revision " ; then
92+ print_err " Error: Failed to remove $snapname (revision $revision )."
93+ fi
94+ done
95+ }
96+
7097# Function: clean_up
7198# Description: Performs system cleanup tasks based on the detected Linux distribution.
7299# Executes commands to clean package cache and remove unnecessary packages.
@@ -75,17 +102,18 @@ check_command() {
75102clean_up () {
76103 case ${ADJUSTED_ID} in
77104 debian)
78- rm -rf /var/lib/apt/lists/*
105+ # rm -rf /var/lib/apt/lists/*
106+ cleanup_snapd
79107 ;;
80108 rhel)
81- rm -rf /var/cache/dnf/* /var/cache/yum/*
109+ # rm -rf /var/cache/dnf/* /var/cache/yum/*
82110 rm -rf /tmp/yum.log
83111 ;;
84112 alpine)
85- rm -rf /var/cache/apk/*
113+ # rm -rf /var/cache/apk/*
86114 ;;
87115 arch)
88- rm -rf /var/cache/pacman/pkg/*
116+ # rm -rf /var/cache/pacman/pkg/*
89117 ;;
90118 * )
91119 print_err " Error: Clean up not implemented for Linux distro: ${ADJUSTED_ID} "
394422fi
395423
396424if check_internet; then
397- # clean_up
425+ clean_up
398426 os_pkg_update
399427 update_brew
400428 update_vscode_ext
0 commit comments