-
Notifications
You must be signed in to change notification settings - Fork 1
/
snap-cleaner.sh
62 lines (53 loc) · 2.48 KB
/
snap-cleaner.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
# Script to remove old revisions of snaps
# IMPORTANT: CLOSE ALL SNAPS BEFORE RUNNING THIS SCRIPT
# Enable strict error handling
set -eu
# Define color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
# Display ASCII art
echo -e "${GREEN}"
echo "░█▀▀░█▀█░█▀█░█▀█░░░█▀▀░█░░░█▀▀░█▀█░█▀█░█▀▀░█▀▄"
echo "░▀▀█░█░█░█▀█░█▀▀░░░█░░░█░░░█▀▀░█▀█░█░█░█▀▀░█▀▄"
echo "░▀▀▀░▀░▀░▀░▀░▀░░░░░▀▀▀░▀▀▀░▀▀▀░▀░▀░▀░▀░▀▀▀░▀░▀"
echo " @sakibulalikhan."
echo -e "${NC}"
# Warning message
echo -e "${RED}IMPORTANT: CLOSE ALL SNAP APPS BEFORE RUNNING THIS SCRIPT${NC}"
echo ""
# User confirmation for clearing cache
read -p "This will clear the snapd cache. Do you want to continue? (y/n): " confirm_cache
if [ "$confirm_cache" != "y" ] && [ "$confirm_cache" != "Y" ]; then
echo -e "${YELLOW}Cache clearing operation cancelled by the user.${NC}"
else
# Clear the snapd cache
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}Clearing Snapd Cache${NC}"
echo -e "${GREEN}This may take a moment...${NC}"
sudo rm -rf /var/lib/snapd/cache/*
echo -e "${GREEN}Cache cleared successfully.${NC}"
fi
# User confirmation for removing old snap revisions
read -p "This will remove old snap revisions. Do you want to continue? (y/n): " confirm_revisions
if [ "$confirm_revisions" != "y" ] && [ "$confirm_revisions" != "Y" ]; then
echo -e "${YELLOW}Old revisions removal operation cancelled by the user.${NC}"
exit 0
fi
# Notify the user about the removal process
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}Removing Old Snap Revisions${NC}"
echo -e "${GREEN}========================================${NC}"
# Remove old revisions of snaps
snap list --all | awk '/disabled/{print $1, $3}' |
while read -r snapname revision; do
echo -e "${YELLOW}Removing $snapname (revision $revision)...${NC}"
snap remove "$snapname" --revision="$revision"
sleep 1 # Optional: Add a short delay for better visibility
done
# Final message
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}Process Complete${NC}"
echo -e "${GREEN}Old revisions removed successfully.${NC}"