Skip to content

Instantly share code, notes, and snippets.

@imranbhullar
Last active March 17, 2023 16:44
Show Gist options
  • Save imranbhullar/d7aaafddfd95468e876b4d577429dc2d to your computer and use it in GitHub Desktop.
Save imranbhullar/d7aaafddfd95468e876b4d577429dc2d to your computer and use it in GitHub Desktop.
This script updates all the outdated vagrant boxes and deletes the outdated box post update (one at a time).
Vagrant Box Updater
This script updates Vagrant boxes on your machine to the latest version, one at a time. It removes all versions of each box before updating to the latest version.
Usage:
1. Open a terminal window.
2. Navigate to the directory where the script is located.
3. Make the script executable: chmod +x vagrant_box_updater.sh
4. Run the script: ./vagrant_box_updater.sh
The script will display a message indicating which box is being updated, and whether the update was successful. When all boxes have been updated, a message will be displayed indicating that the script has finished.
Note: This script requires Vagrant to be installed on your machine. If Vagrant is not installed, you can download it from the official website: https://www.vagrantup.com/downloads.html
#!/bin/bash
# Vagrant box updater
#
# This script updates Vagrant boxes on your machine to the latest version, one at a time.
# It removes all versions of the box before updating to the new version.
# Get a list of all installed Vagrant boxes (except for the default box)
boxes=$(vagrant box list| grep -v '^default' | awk '{print $1}')
# Loop through each box and update to the latest version
for box in $boxes; do
# Print the name of the box being updated
echo "Updating $box..."
# Remove all versions of the box
vagrant box remove --force $box
# Update to the latest version
vagrant box add --force $box
# Print a message indicating the update was successful
echo "Successfully updated $box to the latest version"
done
# Print a message indicating the script has finished
echo "All boxes have been updated."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment