Skip to content

Instantly share code, notes, and snippets.

@mdarse
Created August 4, 2015 12:19
Show Gist options
  • Save mdarse/5be2f9b1e89a4992bd83 to your computer and use it in GitHub Desktop.
Save mdarse/5be2f9b1e89a4992bd83 to your computer and use it in GitHub Desktop.
#/bin/bash
set -o errexit
# Find whether the Vagrant machine was already created or not.
# It parses that kind of output:
#
# 1438619288,default,provider-name,vmware_fusion
# 1438619288,default,state,not_created
# 1438619288,default,state-human-short,not created
found=0
# Poor guy CSV parsing
while IFS=, read _ _ key value; do
if [ "$key" = "state" ]; then
found=1
if [ "$value" == "not_created" ]; then
printf "no"
else
printf "yes"
fi
exit 0
fi
done <<< "$(vagrant status --machine-readable)"
if [ "$found" -eq "0" ]; then
echo "Invalid output received from Vagrant"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment