diff --git a/images/linux/scripts/installers/cleanup.sh b/images/linux/scripts/installers/cleanup.sh new file mode 100644 index 000000000..fe284f339 --- /dev/null +++ b/images/linux/scripts/installers/cleanup.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# before cleanup +before=$(df / -Pm | awk 'NR==2{print $4}') + +# clears out the local repository of retrieved package files +# It removes everything but the lock file from /var/cache/apt/archives/ and /var/cache/apt/archives/partial +apt-get clean + +# after cleanup +after=$(df / -Pm | awk 'NR==2{print $4}') + +# display size + echo "Before: $before MB" + echo "After : $after MB" + echo "Delta : $(($after-$before)) MB" \ No newline at end of file diff --git a/images/linux/ubuntu1604.json b/images/linux/ubuntu1604.json index 38f6a20e5..7ef1a820c 100644 --- a/images/linux/ubuntu1604.json +++ b/images/linux/ubuntu1604.json @@ -289,6 +289,13 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" }, + { + "type": "shell", + "scripts":[ + "{{template_dir}}/scripts/installers/cleanup.sh" + ], + "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" + }, { "type": "file", "source": "{{user `metadata_file`}}", diff --git a/images/linux/ubuntu1804.json b/images/linux/ubuntu1804.json index dccbbe964..8217608bf 100644 --- a/images/linux/ubuntu1804.json +++ b/images/linux/ubuntu1804.json @@ -293,6 +293,13 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" }, + { + "type": "shell", + "scripts":[ + "{{template_dir}}/scripts/installers/cleanup.sh" + ], + "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" + }, { "type": "file", "source": "{{user `metadata_file`}}",