-
Notifications
You must be signed in to change notification settings - Fork 0
/
syssweep.bash
159 lines (141 loc) · 3.5 KB
/
syssweep.bash
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
#!/bin/bash
# Function to check if a command exists
command_exists() {
type "$1" &>/dev/null
}
# Function to print colored messages
print_message() {
local message="$1"
local emoji="☀️"
local color_code=$((31 + RANDOM % 6))
# Add some space before and after the message
echo -e ""
echo -e "\e[${color_code}m${emoji} ${message} ${emoji}\e[0m"
echo -e ""
}
clean_temp_directories() {
print_message "Cleaning temporary directories"
sudo rm -rfv /tmp/*
sudo rm -rfv /var/tmp/*
sudo rm -rfv /var/log/*
sudo rm -rfv ~/.local/share/Trash/info/*
sudo rm -rfv ~/.local/share/Trash/files/*
sudo rm -rfv /root/.local/share/Trash/info/*
sudo rm -rfv /root/.local/share/Trash/files/*
sudo rm -rfv ~/.npm/
sudo rm -rfv /root/.npm
sudo rm -rfv ~/.cache/ksycoca5*
sudo rm -rfv /root/.cache/ksycoca5*
sudo rm -rfv ~/.cache/thumbnails/*
sudo find /usr/lib/python* -name '__pycache__' -exec rm -r {} +
sudo find /home/mlibre/.local/lib/python* -name '__pycache__' -exec rm -r {} +
}
find_and_delete_trash_folders() {
print_message "Cleaning .Trash folders"
mounted_devices=$(df -h | awk 'NR > 1 {print $NF}')
while read -r mount_point; do
sudo rm -rfv "${mount_point}"/.Trash-*
done <<<"$mounted_devices"
}
clean_journal_logs() {
if command_exists journalctl; then
print_message "Cleaning journal logs"
sudo journalctl --flush
sudo journalctl --flush --vacuum-time=1s
journalctl --user --flush --vacuum-time=1s
fi
}
clean_flatpak_cache() {
if command_exists flatpak; then
print_message "Cleaning flatpak cache"
flatpak uninstall --unused -y --force-remove
sudo flatpak uninstall --unused -y --force-remove
fi
}
clean_docker() {
if command_exists docker; then
print_message "Cleaning Docker"
docker system prune -af
docker volume prune -f
fi
}
clean_pacman_cache() {
if command_exists paccache; then
print_message "Cleaning pacman cache"
sudo paccache -r
sudo paccache -ruk0
yes | sudo pacman -Rns $(pacman -Qdtq)
yes | sudo pacman -Rns $(pacman -Qdtq)
yes | sudo pacman -Scc
fi
}
clean_pamac_cache() {
if command_exists pamac; then
print_message "Cleaning with pamac"
sudo pamac clean --keep 0 --no-confirm
fi
}
clean_apt_cache() {
if command_exists apt; then
print_message "Cleaning apt cache"
sudo apt autoremove --purge -y
sudo apt clean
sudo apt -s clean
sudo apt clean all
fi
if command_exists apt-get; then
print_message "Cleaning apt-get cache"
sudo apt-get autoremove --purge -y
sudo apt-get clean
sudo apt-get -s clean
sudo apt-get clean all
sudo apt-get autoclean
fi
}
clean_python_cache() {
if command_exists pip; then
print_message "Cleaning pip and Python caches"
pip cache purge
sudo pip cache purge
fi
}
clean_npm_cache() {
if command_exists npm; then
print_message "Cleaning npm cache"
npm cache clean -f
sudo npm cache clean -f
fi
}
clean_yarn_cache() {
if command_exists yarn; then
print_message "Cleaning yarn cache"
yarn cache clean
fi
}
# Function to update locate database
update_locate_database() {
if command_exists updatedb; then
print_message "Updating locate database"
sudo updatedb
fi
}
# Main function to perform all cleanup tasks
main() {
clean_temp_directories
find_and_delete_trash_folders
clean_journal_logs
clean_flatpak_cache
clean_docker
clean_pacman_cache
clean_pamac_cache
clean_apt_cache
clean_python_cache
clean_npm_cache
clean_yarn_cache
update_locate_database
# Display disk space usage
print_message "Disk space usage:"
df -h
}
# Call the main function to execute all cleanup tasks
main