Skip to content

Instantly share code, notes, and snippets.

@thom8
Last active September 15, 2017 16:33
Show Gist options
  • Save thom8/791f6c9978abda5e4e84 to your computer and use it in GitHub Desktop.
Save thom8/791f6c9978abda5e4e84 to your computer and use it in GitHub Desktop.
Update all your vagrant base 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[@]} -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
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
@tas50
Copy link

tas50 commented Jul 19, 2016

You probably want to redirect errors since vagrant gets upset when it can't find a box on Atlas anyone.

vagrant box outdated --global 2>/dev/null

@tas50
Copy link

tas50 commented Jul 19, 2016

Also this blows up if the box has multiple providers, which most do now. It just hands waiting for the user to specify what provider they want

@sc250024
Copy link

Updated version based on what @thom8 did to account for all providers

https://gist.github.com/sc250024/05a5aa1a1ee2db02080f8714226986e9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment