]> WPIA git - infra.git/blob - packer/debian-9/scripts/99-cleanup.sh
add: packer template for debian-9 installation
[infra.git] / packer / debian-9 / scripts / 99-cleanup.sh
1 #!/usr/bin/env bash
2
3 set -euo pipefail
4
5 export DEBIAN_FRONTEND=noninteractive
6
7 # Finally, cleanup all the things
8 apt-get install --yes deborphan # Let's try to remove some more
9 apt-get autoremove \
10   $(deborphan) \
11   deborphan \
12   dictionaries-common \
13   iamerican \
14   ibritish \
15   localepurge \
16   task-english \
17   tasksel \
18   tasksel-data \
19   --purge --yes
20
21 # Remove downloaded .deb files
22 apt-get clean
23
24 # Remove instance-specific files: we want this image to be as "impersonal" as
25 # possible.
26 find \
27   /var/cache/apt \
28   /var/lib/apt \
29   /var/lib/dhcp \
30   /var/log \
31   -mindepth 1 -print -delete
32
33 rm -vf \
34   /etc/network/interfaces.d/50-cloud-init.cfg \
35   /etc/adjtime \
36   /etc/hostname \
37   /etc/hosts \
38   /etc/ssh/*key* \
39   /var/cache/ldconfig/aux-cache \
40   /var/lib/systemd/random-seed \
41   ~/.bash_history \
42   "${SUDO_USER}/.bash_history"
43
44 # From https://www.freedesktop.org/software/systemd/man/machine-id.html:
45 # For operating system images which are created once and used on multiple
46 # machines, [...] /etc/machine-id should be an empty file in the generic file
47 # system image.
48 truncate -s 0 /etc/machine-id
49
50 # Recreate some useful files.
51 touch /var/log/lastlog
52 chown root:utmp /var/log/lastlog
53 chmod 664 /var/log/lastlog
54
55
56 # Free all unused storage block. This makes the final image smaller.
57 fstrim --all --verbose