#!/usr/bin/env bash
#
# Remove needless noise from file systems before packaging a Vagrant box file.
# This can reduce the size of the box file by 25%.
# Run this with sudo in the guest OS just before "vagrant package" in the host.

set -x

# Discard packages we don't need.
apt-get clean -y
apt-get autoclean -y 

# Clean out pip caches.
find / -type d -path '*/.cache/pip' -print -exec rm -rf '{}/*' \;

# Remove all the .pyc files.
find /edx/app -name '*.pyc' -delete

# Last thing: fill the disk with zeros so they'll compress well.
# The dd command fails because the disk fills, which is the point, so silence
# the error.
dd if=/dev/zero of=/empty bs=1M || true
rm -f /empty
