Skip to content

Instantly share code, notes, and snippets.

@sc250024
Last active January 12, 2022 11:24
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save sc250024/05a5aa1a1ee2db02080f8714226986e9 to your computer and use it in GitHub Desktop.
Save sc250024/05a5aa1a1ee2db02080f8714226986e9 to your computer and use it in GitHub Desktop.
#!/bin/bash
OLDIFS=$IFS
export IFS=$'\n'
# Find all boxes which have updates
AVAILABLE_UPDATES=$(vagrant box outdated --global | grep outdated | tr -d "*'" | cut -d ' ' -f 2 2>/dev/null)
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
provider=$(echo ${boxtype} | awk -F\( '{print $2}' | awk -F\, '{print $1}')
version=$(echo ${boxtype} | cut -d ',' -f 2 | tr -d ' )')
# Add latest version
vagrant box add --clean ${box} --provider ${provider}
BOX_UPDATED="TRUE"
done
done
echo "All boxes are now up to date! Pruning..."
# Remove all old versions
vagrant box prune -f
else
echo "All boxes are already up to date!"
fi
vagrant box outdated --global
export IFS=$OLDIFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment