Forked from tas50/gist:a072a027a63ffad752ee7b5199c95875
Created
July 28, 2017 03:55
-
-
Save mehrdad-shokri/a0cf31223ae95c53240fa77ef654f906 to your computer and use it in GitHub Desktop.
Update all global vagrant boxes (useful for test kitchen)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 | |
| 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