Skip to content

Instantly share code, notes, and snippets.

@alexserver
Created February 17, 2017 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexserver/8fc343750f496143bb2a3882931b4558 to your computer and use it in GitHub Desktop.
Save alexserver/8fc343750f496143bb2a3882931b4558 to your computer and use it in GitHub Desktop.
Remove Outdated Vagrant Boxes
#!/bin/bash
# Find all boxes which have updates
AVAILABLE_UPDATES=`vagrant box outdated --global | grep outdated | tr -d "*'" | cut -d ' ' -f 2`
if [ $AVAILABLE_UPDATES ]; then
for box in $AVAILABLE_UPDATES ; do
echo "Found an update for $box"
# Find all current versions
VERSIONS=`vagrant box list | grep $box | cut -d ',' -f 2 | tr -d ' )'`
# Add latest version
vagrant box add --clean $box
BOX_UPDATED="TRUE"
# Remove all old versions
for version in $VERSIONS ; do
vagrant box remove $box -f --box-version=$version
done
done
echo "All boxes are now up to date!"
else
echo "All boxes are already up to date!"
fi
vagrant box outdated --global
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment