[CORD-1929]
Make cord-bootstrap.sh more idempotent

Change-Id: I5ddd949b5fda8249cff4ba9717b2c0c8cc2969be
diff --git a/scripts/cord-bootstrap.sh b/scripts/cord-bootstrap.sh
index 9ddc21c..8ea82e4 100755
--- a/scripts/cord-bootstrap.sh
+++ b/scripts/cord-bootstrap.sh
@@ -66,7 +66,7 @@
     sudo chmod a+x /usr/local/bin/repo
   fi
 
-  if [ ! -d "$CORDDIR" ]
+  if [ ! -d "$CORDDIR/build" ]
   then
     # make sure we can find gerrit.opencord.org as DNS failures will fail the build
     dig +short gerrit.opencord.org || (echo "ERROR: gerrit.opencord.org can't be looked up in DNS" && exit 1)
@@ -81,7 +81,7 @@
       git config --global color.ui false
     fi
 
-    mkdir $CORDDIR && cd $CORDDIR
+    mkdir -p $CORDDIR && cd $CORDDIR
     repo init -u https://gerrit.opencord.org/manifest -b $REPO_BRANCH
     repo sync
 
@@ -102,20 +102,24 @@
   if [ ! -x "/usr/bin/vagrant" ]
   then
     echo "Installing vagrant and associated tools..."
+    sudo apt-get -y install qemu-kvm libvirt-bin libvirt-dev nfs-kernel-server
+    sudo adduser $USER libvirtd
+
     VAGRANT_SHA256SUM="faff6befacc7eed3978b4b71f0dbb9c135c01d8a4d13236bda2f9ed53482d2c4"  # version 1.9.3
     curl -o /tmp/vagrant.deb https://releases.hashicorp.com/vagrant/1.9.3/vagrant_1.9.3_x86_64.deb
     echo "$VAGRANT_SHA256SUM  /tmp/vagrant.deb" | sha256sum -c -
     sudo dpkg -i /tmp/vagrant.deb
-    sudo apt-get -y install qemu-kvm libvirt-bin libvirt-dev nfs-kernel-server
-    sudo adduser $USER libvirtd
+  fi
 
-    run_stage cloudlab_setup
+  run_stage cloudlab_setup
 
-    echo "Installing vagrant plugins..."
-    vagrant plugin list | grep vagrant-libvirt || vagrant plugin install vagrant-libvirt --plugin-version 0.0.35
-    vagrant plugin list | grep vagrant-mutate || vagrant plugin install vagrant-mutate
-    vagrant plugin list | grep vagrant-hosts || vagrant plugin install vagrant-hosts
+  echo "Installing vagrant plugins if needed..."
+  vagrant plugin list | grep -q vagrant-libvirt || vagrant plugin install vagrant-libvirt --plugin-version 0.0.35
+  vagrant plugin list | grep -q vagrant-mutate || vagrant plugin install vagrant-mutate
+  vagrant plugin list | grep -q vagrant-hosts || vagrant plugin install vagrant-hosts
 
+  if ! vagrant box list | grep -q ubuntu/trusty64.*libvirt
+  then
     add_box ubuntu/trusty64
   fi
 }