github.com/ryanbennettvoid/go-swagger@v0.18.1-0.20190104015444-3854bbbe2392/hack/setup.sh (about)

     1  #!/bin/bash
     2  
     3  set -eu
     4  
     5  find_mgr() {
     6      if hash minishift 2>/dev/null; then
     7          echo "minishift"
     8      else
     9          if hash docker-machine 2>/dev/null; then
    10              echo "docker-machine"
    11          fi
    12      fi
    13  }
    14  
    15  get_vm_name() {
    16      case "$1" in
    17          minishift)
    18              echo "minishift"
    19              ;;
    20          docker-machine)
    21              echo "${DOCKER_MACHINE_NAME}"
    22              ;;
    23          *)
    24              ;;
    25      esac
    26  }
    27  
    28  is_vm_running() {
    29      local vm=$1
    30      declare -a running=($(VBoxManage list runningvms | awk '{ print $1 }'))
    31      local result='false'
    32  
    33      for rvm in "${running[@]}"; do
    34          if [[ "${rvm}" == *"${vm}"* ]]; then
    35              result='true'
    36          fi
    37      done
    38      echo "$result"
    39  }
    40  
    41  if hash cygpath 2>/dev/null; then
    42      PROJECT_DIR=$(cygpath -w -a "$(pwd)")
    43  else
    44      PROJECT_DIR=$(pwd)
    45  fi
    46  
    47  VM_MGR=$(find_mgr)
    48  if [[ -z $VM_MGR ]]; then
    49      echo "ERROR: No VM Manager found; expected one of ['minishift', 'docker-machine']"
    50      exit 1
    51  fi
    52  
    53  VM_NAME=$(get_vm_name "$VM_MGR")
    54  if [[ -z $VM_NAME ]]; then
    55      echo "ERROR: No VM found; try running 'eval $(docker-machine env)'"
    56      exit 1
    57  fi
    58  
    59  if ! hash VBoxManage 2>/dev/null; then
    60      echo "VirtualBox executable 'VBoxManage' not found in path"
    61      exit 1
    62  fi
    63  
    64  avail=$(is_vm_running "$VM_NAME")
    65  if [[ "$avail" == *"true"* ]]; then
    66      res=$(VBoxManage sharedfolder add "${VM_NAME}" --name "${PROJECT}" --hostpath "${PROJECT_DIR}" --transient 2>&1)
    67      if [[ -z $res || $res == *"already exists"* ]]; then
    68          # no need to show that it already exists
    69          :
    70      else
    71          echo "$res"
    72          exit 1
    73      fi
    74      echo "VM: [${VM_NAME}] -- Added Sharedfolder [${PROJECT}] @Path [${PROJECT_DIR}]"
    75  else
    76      echo "$VM_NAME is not currently running; please start your VM and try again."
    77      exit 1
    78  fi
    79  
    80  SSH_CMD="sudo mkdir -p /${PROJECT} ; sudo mount -t vboxsf ${PROJECT} /${PROJECT}"
    81  case "${VM_MGR}" in
    82      minishift)
    83          minishift ssh "${SSH_CMD}"
    84          echo "VM: [${VM_NAME}] -- Mounted Sharedfolder [${PROJECT}] @VM Path [/${PROJECT}]"
    85          ;;
    86      docker-machine)
    87          docker-machine ssh "${VM_NAME}" "${SSH_CMD}"
    88          echo "VM: [${VM_NAME}] -- Mounted Sharedfolder [${PROJECT}] @VM Path [/${PROJECT}]"
    89          ;;
    90      *)
    91          ;;
    92  esac