@@ -4,10 +4,51 @@ set -o errexit
4
4
set -o xtrace
5
5
shopt -s nullglob
6
6
7
- # clear the APT cache and delete everything from /var/cache/apt/archives/
8
- # removed /etc/ssh/ssh_host_* \ - this probably caused issues with ssh connection for some reason..
9
7
apt clean
10
8
9
+ echo " Cleaning APT..."
10
+ apt-get autoremove -y || true
11
+ apt-get clean || true
12
+
13
+ echo " Cleaning Node.js and Yarn..."
14
+ if command -v yarn & > /dev/null; then
15
+ yarn cache clean || true
16
+ fi
17
+
18
+ if command -v npm & > /dev/null; then
19
+ npm cache clean --force || true
20
+ fi
21
+
22
+ echo " Cleaning Yarn directories..."
23
+ rm -rf /tmp/.yarn-* || true
24
+ rm -rf /root/.npm /root/.yarn || true
25
+ rm -rf /home/* /.npm /home/* /.yarn || true
26
+ rm -rf /usr/local/share/.cache/yarn || true
27
+ rm -rf /usr/local/yarn-* /cache || true
28
+ find /usr/local/yarn-* -type d -name " node_modules" -exec rm -rf {} + 2> /dev/null || true
29
+
30
+ if command -v docker & > /dev/null; then
31
+ echo " Cleaning Docker..."
32
+ docker system prune -af || true
33
+ fi
34
+
35
+ if command -v pip3 & > /dev/null; then
36
+ echo " Cleaning pip..."
37
+ pip3 cache purge || true
38
+ fi
39
+
40
+ if command -v apt & > /dev/null; then
41
+ echo " Removing old kernels..."
42
+ dpkg -l ' linux-*' | awk ' /^ii/{ print $2}' | grep -v -e " $( uname -r | sed -r ' s/-[a-z]+//' ) " | grep -E ' (image|headers)' | xargs apt-get -y purge || true
43
+ fi
44
+
45
+ if command -v snap & > /dev/null; then
46
+ echo " Cleaning snap..."
47
+ snap list --all | awk ' /disabled/{print $1, $3}' | while read -r snapname revision; do
48
+ snap remove " $snapname " --revision=" $revision " || true
49
+ done
50
+ fi
51
+
11
52
rm -rf \
12
53
/etc/apparmor* \
13
54
/etc/profile.d/jdk.csh \
@@ -22,7 +63,12 @@ rm -rf \
22
63
/var/log/installer \
23
64
/var/tmp/* \
24
65
VBoxGuestAdditions_* .iso \
25
- VBoxGuestAdditions_* .iso.?
66
+ VBoxGuestAdditions_* .iso.? \
67
+ /var/cache/* \
68
+ /usr/share/doc/* \
69
+ /usr/share/man/*
70
+
71
+ find /usr/share/locale -mindepth 1 -maxdepth 1 -type d -not -name ' en' -not -name ' en_US' -exec rm -rf {} \; || true
26
72
27
73
if [[ $CLEANUP_APT_LISTS ]]; then
28
74
rm -rf /var/lib/apt/lists/* || echo " Suppressing exit $? "
@@ -36,21 +82,21 @@ if [[ -d /home/travis ]]; then
36
82
rm -f /home/travis/linux.iso /home/travis/shutdown.sh
37
83
fi
38
84
85
+ echo " Cleaning logs..."
39
86
find /var/log -type f | while read -r f; do
40
87
dd if=/dev/null of=" ${f} "
41
88
done
42
89
43
- #
44
- # Disable motd
45
- # in /etc/default/motd-news set ENABLED=0
46
- #
90
+ echo " Removing large files..."
91
+ find / -type f -size +100M -not -path " /proc/*" -not -path " /sys/*" -not -path " /dev/*" -not -path " /run/*" -print -delete 2> /dev/null || true
92
+
93
+ journalctl --vacuum-time=1d || true
94
+ journalctl --vacuum-size=10M || true
95
+
47
96
if test -f /etc/default/motd-news >& /dev/null; then
48
97
sed -i ' s|ENABLED=1|ENABLED=0|' /etc/default/motd-news
49
98
fi
50
99
51
- #
52
- # Disable services to speed up boot time
53
- #
54
100
if command -v systemctl >& /dev/null; then
55
101
systemctl --all --type service | grep -q lxd-containers.service && systemctl disable lxd-containers.service
56
102
systemctl --all --type service | grep -q accounts-daemon.service && systemctl mask accounts-daemon.service
@@ -64,12 +110,9 @@ if command -v systemctl >&/dev/null; then
64
110
systemctl --all --type service | grep -q motd-news.service && systemctl disable motd-news.service
65
111
fi
66
112
67
- #
68
- # Disable package update on boot
69
- #
70
113
if test -f /etc/cloud/cloud.cfg >& /dev/null; then
71
114
sed -i ' /package-update-upgrade-install/d' /etc/cloud/cloud.cfg
72
115
fi
73
116
74
117
echo " PubkeyAcceptedKeyTypes +ssh-rsa" >> /etc/ssh/sshd_config
75
- echo " HostKeyAlgorithms +ssh-rsa" >> /etc/ssh/sshd_config
118
+ echo " HostKeyAlgorithms +ssh-rsa" >> /etc/ssh/sshd_config
0 commit comments