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.

Revisions

  1. mdarse created this gist Aug 4, 2015.
    29 changes: 29 additions & 0 deletions vagrant_created.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #/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