Skip to content

Instantly share code, notes, and snippets.

@tas50
Created July 14, 2020 01:03
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 tas50/4f5b84f9187aeab700b3cfb400cd0cdc to your computer and use it in GitHub Desktop.
Save tas50/4f5b84f9187aeab700b3cfb400cd0cdc to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Box type must be specified (virtualbox, vmware_desktop, parallels)"
exit 1
fi
# Find all boxes which have updates
AVAILABLE_UPDATES=`vagrant box outdated --global 2>/dev/null | grep outdated | tr -d "*'" | cut -d ' ' -f 2`
if [ ! ${#AVAILABLE_UPDATES[@]} -eq 0 ]; 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 --provider $1 --force
BOX_UPDATED="TRUE"
# Remove all old versions
vagrant box prune -f > /dev/null 2>&1
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