Forked from gMagicScott/vagrant-box-update-all.sh
Last active
August 9, 2018 16:12
-
-
Save jlwestsr/40ca22e8152254ec94a23a2b5fb6a6f8 to your computer and use it in GitHub Desktop.
Update all locally installed vagrant boxes and cleanup (prune) older versions.
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 | |
# | |
# FILE: vagrant-box-update-all.sh | |
# Update all locally installed vagrant boxes and cleanup (prune) older versions. | |
# | |
# $ bash ./vagrant-box-update-all.sh | |
# | |
# Find all boxes which have updates | |
AVAILABLE_UPDATES=$(vagrant box outdated --global | grep outdated | tr -d "*'" | cut -d ' ' -f 2) | |
if [[ ${#AVAILABLE_UPDATES[@]} -ne 0 ]]; then | |
for box in $AVAILABLE_UPDATES ; do | |
echo "Found an update for ${box}" | |
# Find all current versions | |
boxinfo=$(vagrant box list | grep ${box}) | |
for boxtype in ${boxinfo}; do | |
# Get the provider | |
provider=$(echo ${boxtype} | awk -F\( '{print $2}' | awk -F\, '{print $1}') | |
# Add latest version | |
vagrant box add ${box} --force --clean --provider ${provider} | |
done | |
done | |
echo "All boxes are now up to date! Pruning..." | |
# Remove all old versions | |
vagrant box prune --force | |
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
curl -LSs https://gist.githubusercontent.com/jlwestsr/40ca22e8152254ec94a23a2b5fb6a6f8/raw/6ccecd92263d39fbeae9c97020927f26ff7c5329/vagrant-box-update-all.sh | bash