-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean-script.sh
executable file
·117 lines (96 loc) · 3.15 KB
/
clean-script.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
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
#!/usr/bin/env bash
# Update package repositories (may vary by distribution)
if [ -x "$(command -v apt-get)" ]; then
sudo apt-get update
elif [ -x "$(command -v dnf)" ]; then
sudo dnf check-update
elif [ -x "$(command -v yum)" ]; then
sudo yum check-update
elif [ -x "$(command -v zypper)" ]; then
sudo zypper refresh
elif [ -x "$(command -v nix-env)" ]; then
sudo nixos-rebuild switch --upgrade
fi
# Upgrade system packages
if [ -x "$(command -v apt-get)" ]; then
sudo apt-get -y upgrade
elif [ -x "$(command -v dnf)" ]; then
sudo dnf -y upgrade
elif [ -x "$(command -v yum)" ]; then
sudo yum -y update
elif [ -x "$(command -v zypper)" ]; then
sudo zypper update
fi
# Remove orphaned packages (may vary by distribution)
if [ -x "$(command -v apt-get)" ]; then
sudo apt-get autoremove --purge
elif [ -x "$(command -v dnf)" ]; then
sudo dnf autoremove
elif [ -x "$(command -v yum)" ]; then
sudo package-cleanup --leaves
elif [ -x "$(command -v zypper)" ]; then
sudo zypper packages --unneeded
elif [ -x "$(command -v nix-env)" ]; then
sudo sudo nix-collect-garbage --delete-older-than 14d
fi
# Clean package cache
if [ -x "$(command -v apt-get)" ]; then
sudo apt-get clean
elif [ -x "$(command -v dnf)" ]; then
sudo dnf clean packages
elif [ -x "$(command -v yum)" ]; then
sudo yum clean all
elif [ -x "$(command -v zypper)" ]; then
sudo zypper clean --all
elif [ -x "$(command -v nix-env)" ]; then
sudo nix-store --optimise
fi
# Check if Flatpak is installed
if command -v flatpak &> /dev/null; then
echo "Flatpak is installed. Updating and removing unused runtimes and apps..."
# Update Flatpak
flatpak update
# Remove unused runtimes and apps
flatpak uninstall --unused
echo "Flatpak update and cleanup completed."
else
echo "Flatpak is not installed. Skipping the process."
fi
# Check if Snap is installed
if command -v snap &> /dev/null; then
echo "Snap is installed. Updating snap packages and cleaning unused ones..."
# Update Snap packages
sudo snap refresh
# Clean unused Snap revisions
sudo snap set system refresh.retain=2 # Keep 2 latest revisions
sudo snap refresh --amend
echo "Snap update and cleanup completed."
else
echo "Snap is not installed. Skipping the process."
fi
# Remove old logs (may vary by distribution)
sudo journalctl --vacuum-time=2d
# Clean temporary files
sudo rm -rf /tmp/*
# Clean thumbnail cache
rm -rf ~/.cache/thumbnails/*
# Remove old kernels (may vary by distribution)
if [ -x "$(command -v apt-get)" ]; then
sudo apt-get autoremove --purge
elif [ -x "$(command -v dnf)" ]; then
sudo package-cleanup --oldkernels --count=1
elif [ -x "$(command -v yum)" ]; then
sudo package-cleanup --oldkernels --count=1
elif [ -x "$(command -v zypper)" ]; then
sudo zypper remove-old-kernels --keep 1
fi
# Remove old logs in /var/log
sudo find /var/log -type f -name '*.gz' -exec rm -f {} \;
sudo find /var/log -type f -name '*.1' -exec rm -f {} \;
# Remove cached package data (apt)
if [ -x "$(command -v apt-get)" ]; then
sudo apt-get clean
sudo rm -rf /var/lib/apt/lists/*
fi
# Print a message
echo "System cleanup and update completed."