github.com/hashicorp/packer@v1.14.3/examples/hcl/linux/etc/scripts/100-cleanup.sh (about) 1 #!/bin/sh -eux 2 3 # Delete all Linux headers 4 dpkg --list \ 5 | awk '{ print $2 }' \ 6 | grep 'linux-headers' \ 7 | xargs apt-get -y purge; 8 9 # Remove specific Linux kernels, such as linux-image-3.11.0-15-generic but 10 # keeps the current kernel and does not touch the virtual packages, 11 # e.g. 'linux-image-generic', etc. 12 dpkg --list \ 13 | awk '{ print $2 }' \ 14 | grep 'linux-image-.*-generic' \ 15 | grep -v `uname -r` \ 16 | xargs apt-get -y purge; 17 18 # Delete Linux source 19 dpkg --list \ 20 | awk '{ print $2 }' \ 21 | grep linux-source \ 22 | xargs apt-get -y purge; 23 24 # Delete development packages 25 dpkg --list \ 26 | awk '{ print $2 }' \ 27 | grep -- '-dev$' \ 28 | xargs apt-get -y purge; 29 30 # delete docs packages 31 dpkg --list \ 32 | awk '{ print $2 }' \ 33 | grep -- '-doc$' \ 34 | xargs apt-get -y purge; 35 36 # Delete X11 libraries 37 apt-get -y purge libx11-data xauth libxmuu1 libxcb1 libx11-6 libxext6; 38 39 # Delete obsolete networking 40 apt-get -y purge ppp pppconfig pppoeconf; 41 42 # Delete oddities 43 apt-get -y purge popularity-contest installation-report command-not-found friendly-recovery bash-completion fonts-ubuntu-font-family-console laptop-detect; 44 45 # 19.10+ don't have this package so fail gracefully 46 apt-get -y purge command-not-found-data || true; 47 48 # Exlude the files we don't need w/o uninstalling linux-firmware 49 echo "==> Setup dpkg excludes for linux-firmware" 50 cat <<_EOF_ | cat >> /etc/dpkg/dpkg.cfg.d/excludes 51 #BENTO-BEGIN 52 path-exclude=/lib/firmware/* 53 path-exclude=/usr/share/doc/linux-firmware/* 54 #BENTO-END 55 _EOF_ 56 57 # Delete the massive firmware packages 58 rm -rf /lib/firmware/* 59 rm -rf /usr/share/doc/linux-firmware/* 60 61 apt-get -y autoremove; 62 apt-get -y clean; 63 64 # Remove docs 65 rm -rf /usr/share/doc/* 66 67 # Remove caches 68 find /var/cache -type f -exec rm -rf {} \; 69 70 # truncate any logs that have built up during the install 71 find /var/log -type f -exec truncate --size=0 {} \; 72 73 # Blank netplan machine-id (DUID) so machines get unique ID generated on boot. 74 truncate -s 0 /etc/machine-id 75 76 # remove the contents of /tmp and /var/tmp 77 rm -rf /tmp/* /var/tmp/* 78 79 # clear the history so our install isn't there 80 export HISTSIZE=0 81 rm -f /root/.wget-hsts