Update of Packer builder for Vagrant and various clouds
[osm/devops.git] / packer / packer_templates / osm / scripts / cleanup.sh
1 #!/bin/sh -eux
2
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Delete all Linux headers
16 dpkg --list \
17 | awk '{ print $2 }' \
18 | grep 'linux-headers' \
19 | xargs apt-get -y purge;
20
21 # Remove specific Linux kernels, such as linux-image-3.11.0-15-generic but
22 # keeps the current kernel and does not touch the virtual packages,
23 # e.g. 'linux-image-generic', etc.
24 dpkg --list \
25 | awk '{ print $2 }' \
26 | grep 'linux-image-.*-generic' \
27 | grep -v `uname -r` \
28 | xargs apt-get -y purge;
29
30 # Delete Linux source
31 dpkg --list \
32 | awk '{ print $2 }' \
33 | grep linux-source \
34 | xargs apt-get -y purge;
35
36 # Delete development packages
37 dpkg --list \
38 | awk '{ print $2 }' \
39 | grep -- '-dev$' \
40 | xargs apt-get -y purge;
41
42 # delete docs packages
43 dpkg --list \
44 | awk '{ print $2 }' \
45 | grep -- '-doc$' \
46 | xargs apt-get -y purge;
47
48 # Delete X11 libraries
49 apt-get -y purge libx11-data xauth libxmuu1 libxcb1 libx11-6 libxext6;
50
51 # Delete obsolete networking
52 apt-get -y purge ppp pppconfig pppoeconf;
53
54 # Delete oddities
55 apt-get -y purge popularity-contest installation-report command-not-found friendly-recovery bash-completion fonts-ubuntu-font-family-console laptop-detect;
56
57 # 19.10+ don't have this package so fail gracefully
58 apt-get -y purge command-not-found-data || true;
59
60 # Exlude the files we don't need w/o uninstalling linux-firmware
61 echo "==> Setup dpkg excludes for linux-firmware"
62 cat <<_EOF_ | cat >> /etc/dpkg/dpkg.cfg.d/excludes
63 #BEGIN
64 path-exclude=/lib/firmware/*
65 path-exclude=/usr/share/doc/linux-firmware/*
66 #END
67 _EOF_
68
69 # Delete the massive firmware packages
70 rm -rf /lib/firmware/*
71 rm -rf /usr/share/doc/linux-firmware/*
72
73 apt-get -y autoremove;
74 apt-get -y clean;
75
76 # Remove docs
77 rm -rf /usr/share/doc/*
78
79 # Remove caches
80 find /var/cache -type f -exec rm -rf {} \;
81
82 # truncate any logs that have built up during the install
83 find /var/log -type f -exec truncate --size=0 {} \;
84
85 # Blank netplan machine-id (DUID) so machines get unique ID generated on boot.
86 truncate -s 0 /etc/machine-id
87
88 # remove the contents of /tmp and /var/tmp
89 rm -rf /tmp/* /var/tmp/*
90
91 # clear the history so our install isn't there
92 export HISTSIZE=0
93 rm -f /root/.wget-hsts