blob: 21d2e94364022b285e4315fa736713d0eb201693 (
plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
#!/bin/bash
# Cache Cleaner for Arch Linux
# AUR package: cache-cleaner
VERSION="1.1.1"
show_help() {
echo "Cache Cleaner $VERSION"
echo "Usage: cache-cleaner [OPTIONS]"
echo ""
echo "Options:"
echo " -p, --pacman Clean pacman cache only"
echo " -a, --aur Clean AUR helpers cache only"
echo " -u, --user Clean user cache only"
echo " -s, --system Clean system cache only"
echo " -t, --temp Clean temporary files (/tmp)"
echo " -A, --all Clean all caches including /tmp"
echo " -v, --version Show version"
echo " -h, --help Show this help"
echo ""
}
show_version() {
echo "Cache Cleaner $VERSION"
}
clean_pacman() {
echo "đ§š Cleaning pacman cache..."
if command -v pacman >/dev/null 2>&1; then
if sudo pacman -Sc --noconfirm 2>/dev/null; then
echo "â
Pacman cache cleaned"
else
echo "â ī¸ Pacman cache already clean or no access"
fi
else
echo "â pacman not found"
fi
}
clean_aur() {
echo "đ§š Cleaning AUR cache..."
local aur_dirs=(
"$HOME/.cache/yay"
"$HOME/.cache/paru"
"$HOME/.cache/trizen"
)
local cleaned=0
for dir in "${aur_dirs[@]}"; do
if [[ -d "$dir" ]]; then
rm -rf "$dir"/*
echo "â
Cleaned: $dir"
cleaned=1
fi
done
if [[ $cleaned -eq 0 ]]; then
echo "âšī¸ No AUR helper caches found"
fi
}
clean_user_cache() {
echo "đ§š Cleaning user cache..."
if [[ -d "$HOME/.cache" ]]; then
rm -rf "$HOME/.cache"/*
echo "â
User cache cleaned"
else
echo "âšī¸ User cache directory not found"
fi
}
clean_system_cache() {
echo "đ§š Cleaning system cache..."
if [[ -d "/var/cache" ]]; then
sudo find /var/cache -type f -delete 2>/dev/null
echo "â
System cache cleaned"
else
echo "âšī¸ System cache directory not found"
fi
}
clean_temp() {
echo "đ§š Cleaning temporary files (/tmp)..."
if [[ -w "/tmp" ]]; then
find /tmp -type f -mmin +60 -delete 2>/dev/null
find /tmp -type d -empty -mmin +60 -delete 2>/dev/null
echo "â
Temporary files cleaned (files older than 1 hour)"
else
echo "â No write permission for /tmp"
fi
}
# Parse arguments
MODE="all"
while [[ $# -gt 0 ]]; do
case $1 in
-p|--pacman)
MODE="pacman"
shift
;;
-a|--aur)
MODE="aur"
shift
;;
-u|--user)
MODE="user"
shift
;;
-s|--system)
MODE="system"
shift
;;
-t|--temp)
MODE="temp"
shift
;;
-A|--all)
MODE="all"
shift
;;
-v|--version)
show_version
exit 0
;;
-h|--help)
show_help
exit 0
;;
*)
echo "Unknown option: $1"
show_help
exit 1
;;
esac
done
# Main execution
echo "đ Starting cache cleanup..."
echo "Mode: $MODE"
echo ""
case $MODE in
pacman)
clean_pacman
;;
aur)
clean_aur
;;
user)
clean_user_cache
;;
system)
clean_system_cache
;;
temp)
clean_temp
;;
all)
clean_pacman
clean_aur
clean_user_cache
clean_system_cache
clean_temp
;;
esac
echo ""
echo "â
Cache cleanup completed!"
|