Skip to content

Commit

Permalink
Update update-vagrant-boxes.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
fazlearefin committed May 23, 2022
1 parent 8ac85aa commit 013b30d
Showing 1 changed file with 27 additions and 40 deletions.
67 changes: 27 additions & 40 deletions update-vagrant-boxes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,33 @@
# Purpose: Updates all installed vagrant boxes and purges outdated versions

function update_vagrant_boxes {
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

while read box; do

echo "Found an update for ${box}"

# Find all current versions
boxinfo=$(vagrant box list | grep ${box})

while read boxtype; 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 <<< ${boxinfo}

done <<< ${AVAILABLE_UPDATES}

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
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
while read box; do
echo "Found an update for ${box}"
# Find all current versions
boxinfo=$(vagrant box list | grep ${box})
while read boxtype; 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 <<< ${boxinfo}
done <<< ${AVAILABLE_UPDATES}
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
}

update_vagrant_boxes

0 comments on commit 013b30d

Please sign in to comment.