Skip to content

Instantly share code, notes, and snippets.

@conorbranagan
Last active November 21, 2021 21:36
Show Gist options
  • Save conorbranagan/7710603 to your computer and use it in GitHub Desktop.
Save conorbranagan/7710603 to your computer and use it in GitHub Desktop.
Vagrant Pre-package script
#!/bin/bash
#
# Script to run before trying to re-package this box.
# Usage: sudo ~/prepackage.sh
echo 'Stopping all supervisor tasks'
sudo supervisorctl stop all
echo 'Removing custom dotfiles'
for dotfile in 'gitconfig pypirc'; do
[ -f "/home/vagrant/.$dotfile" ] && rm "/home/vagrant/.$dotfile"
done
echo 'Cleaning up history'
for historyfile in 'bash_history rediscli_history psql_history'; do
[ -f "/home/vagrant/.$historyfile" ] && rm "/home/vagrant/$historyfile"
done
[ -f /home/vagrant/.gitconfig ] && rm /home/vagrant/.gitconfig
echo 'Cleanup bash history'
unset HISTFILE
[ -f /root/.bash_history ] && rm /root/.bash_history
[ -f /home/vagrant/.bash_history ] && rm /home/vagrant/.bash_history
echo 'Clean out cached apt packages'
apt-get clean
echo 'Zero out the log files'
find /var/log -type f | while read f; do echo -ne '' > $f; done;
echo 'Remove network settings so NFS mounts work after packaging'
rm /etc/udev/rules.d/70-persistent-net.rules
echo 'Zero free space to aid VM compression'
dd if=/dev/zero of=/EMPTY bs=1M
rm -f /EMPTY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment