-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate-vagrant-boxes.sh
executable file
·35 lines (30 loc) · 1.19 KB
/
update-vagrant-boxes.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
# 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
}
update_vagrant_boxes