Jarno Rankinen revised this gist . Go to revision
1 file changed, 2 insertions
cleanup.sh
@@ -1,6 +1,8 @@ | |||
1 | 1 | #!/bin/sh -eux | |
2 | 2 | ||
3 | 3 | ## VM cleanup script for generating templates | |
4 | + | ## | |
5 | + | ## Download from https://gist.githubusercontent.com/0ranki/a2fb607c41a4112c410befc9be004646/raw/e7f2ce00636170416c2f65b63196358320166624/cleanup.sh | |
4 | 6 | ||
5 | 7 | major_version="`sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/redhat-release | awk -F. '{print $1}'`"; | |
6 | 8 |
Jarno Rankinen revised this gist . Go to revision
1 file changed, 2 insertions
cleanup.sh
@@ -1,5 +1,7 @@ | |||
1 | 1 | #!/bin/sh -eux | |
2 | 2 | ||
3 | + | ## VM cleanup script for generating templates | |
4 | + | ||
3 | 5 | major_version="`sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/redhat-release | awk -F. '{print $1}'`"; | |
4 | 6 | ||
5 | 7 | # make sure we use dnf on EL 8+ |
Jarno Rankinen revised this gist . Go to revision
1 file changed, 61 insertions
cleanup.sh(file created)
@@ -0,0 +1,61 @@ | |||
1 | + | #!/bin/sh -eux | |
2 | + | ||
3 | + | major_version="`sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/redhat-release | awk -F. '{print $1}'`"; | |
4 | + | ||
5 | + | # make sure we use dnf on EL 8+ | |
6 | + | if [ "$major_version" -ge 8 ]; then | |
7 | + | pkg_cmd="dnf" | |
8 | + | else | |
9 | + | pkg_cmd="yum" | |
10 | + | fi | |
11 | + | ||
12 | + | ||
13 | + | echo "Remove development and kernel source packages" | |
14 | + | $pkg_cmd -y remove gcc cpp gc kernel-devel kernel-headers glibc-devel elfutils-libelf-devel glibc-headers kernel-devel kernel-headers | |
15 | + | ||
16 | + | if [ "$major_version" -ge 8 ]; then | |
17 | + | echo "remove orphaned packages" | |
18 | + | dnf -y autoremove | |
19 | + | echo "Remove previous kernels that preserved for rollbacks" | |
20 | + | dnf -y remove -y $(dnf repoquery --installonly --latest-limit=-1 -q) | |
21 | + | else | |
22 | + | echo "Remove previous kernels that preserved for rollbacks" | |
23 | + | if ! command -v package-cleanup >/dev/null 2>&1; then | |
24 | + | yum -y install yum-utils | |
25 | + | fi | |
26 | + | package-cleanup --oldkernels --count=1 -y | |
27 | + | fi | |
28 | + | ||
29 | + | # Avoid ~200 meg firmware package we don't need | |
30 | + | # this cannot be done in the KS file so we do it here | |
31 | + | echo "Removing extra firmware packages" | |
32 | + | $pkg_cmd -y remove linux-firmware | |
33 | + | ||
34 | + | echo "clean all package cache information" | |
35 | + | $pkg_cmd -y clean all --enablerepo=\*; | |
36 | + | ||
37 | + | # Clean up network interface persistence | |
38 | + | rm -f /etc/udev/rules.d/70-persistent-net.rules; | |
39 | + | mkdir -p /etc/udev/rules.d/70-persistent-net.rules; | |
40 | + | rm -f /lib/udev/rules.d/75-persistent-net-generator.rules; | |
41 | + | rm -rf /dev/.udev/; | |
42 | + | ||
43 | + | for ndev in `ls -1 /etc/sysconfig/network-scripts/ifcfg-*`; do | |
44 | + | if [ "`basename $ndev`" != "ifcfg-lo" ]; then | |
45 | + | sed -i '/^HWADDR/d' "$ndev"; | |
46 | + | sed -i '/^UUID/d' "$ndev"; | |
47 | + | fi | |
48 | + | done | |
49 | + | ||
50 | + | ||
51 | + | echo "truncate any logs that have built up during the install" | |
52 | + | find /var/log -type f -exec truncate --size=0 {} \; | |
53 | + | ||
54 | + | echo "remove the install log" | |
55 | + | rm -f /root/anaconda-ks.cfg /root/original-ks.cfg | |
56 | + | ||
57 | + | echo "remove the contents of /tmp and /var/tmp" | |
58 | + | rm -rf /tmp/* /var/tmp/* | |
59 | + | ||
60 | + | echo "Clear the history so our install commands aren't there" | |
61 | + | rm -f /root/.wget-hsts |