Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. trap '[ "$?" -eq 0 ] || read -p "Looks like something went wrong in step ´$STEP´... Press any key to continue..."' EXIT
  4.  
  5. # TODO: I'm sure this is not very robust. But, it is needed for now to ensure
  6. # that binaries provided by Docker Toolbox over-ride binaries provided by
  7. # Docker for Windows when launching using the Quickstart.
  8. export PATH="/c/Program Files/Docker Toolbox:$PATH"
  9. VM=${DOCKER_MACHINE_NAME-default}
  10. DOCKER_MACHINE=./docker-machine.exe
  11.  
  12. STEP="Looking for vboxmanage.exe"
  13. if [ ! -z "$VBOX_MSI_INSTALL_PATH" ]; then
  14. VBOXMANAGE="${VBOX_MSI_INSTALL_PATH}VBoxManage.exe"
  15. else
  16. VBOXMANAGE="${VBOX_INSTALL_PATH}VBoxManage.exe"
  17. fi
  18.  
  19. BLUE='\033[1;34m'
  20. GREEN='\033[0;32m'
  21. NC='\033[0m'
  22.  
  23. #clear all_proxy if not socks address
  24. if [[ $ALL_PROXY != socks* ]]; then
  25. unset ALL_PROXY
  26. fi
  27. if [[ $all_proxy != socks* ]]; then
  28. unset all_proxy
  29. fi
  30.  
  31. if [ ! -f "${DOCKER_MACHINE}" ]; then
  32. echo "Docker Machine is not installed. Please re-run the Toolbox Installer and try again."
  33. exit 1
  34. fi
  35.  
  36. if [ ! -f "${VBOXMANAGE}" ]; then
  37. echo "VirtualBox is not installed. Please re-run the Toolbox Installer and try again."
  38. exit 1
  39. fi
  40.  
  41. "${VBOXMANAGE}" list vms | grep \""${VM}"\" &> /dev/null
  42. VM_EXISTS_CODE=$?
  43.  
  44. set -e
  45.  
  46. STEP="Checking if machine $VM exists"
  47. if [ $VM_EXISTS_CODE -eq 1 ]; then
  48. "${DOCKER_MACHINE}" rm -f "${VM}" &> /dev/null || :
  49. rm -rf ~/.docker/machine/machines/"${VM}"
  50. #set proxy variables if they exists
  51. if [ "${HTTP_PROXY}" ]; then
  52. PROXY_ENV="$PROXY_ENV --engine-env HTTP_PROXY=$HTTP_PROXY"
  53. fi
  54. if [ "${HTTPS_PROXY}" ]; then
  55. PROXY_ENV="$PROXY_ENV --engine-env HTTPS_PROXY=$HTTPS_PROXY"
  56. fi
  57. if [ "${NO_PROXY}" ]; then
  58. PROXY_ENV="$PROXY_ENV --engine-env NO_PROXY=$NO_PROXY"
  59. fi
  60. "${DOCKER_MACHINE}" create -d virtualbox $PROXY_ENV "${VM}"
  61. fi
  62.  
  63. STEP="Checking status on $VM"
  64. VM_STATUS="$(${DOCKER_MACHINE} status ${VM} 2>&1)"
  65. if [ "${VM_STATUS}" != "Running" ]; then
  66. "${DOCKER_MACHINE}" start "${VM}"
  67. yes | "${DOCKER_MACHINE}" regenerate-certs "${VM}"
  68. fi
  69.  
  70. STEP="Setting env"
  71. eval "$(${DOCKER_MACHINE} env --shell=bash --no-proxy ${VM})"
  72.  
  73. STEP="Finalize"
  74. clear
  75. cat << EOF
  76.  
  77.  
  78. ## .
  79. ## ## ## ==
  80. ## ## ## ## ## ===
  81. /"""""""""""""""""\___/ ===
  82. ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~
  83. \______ o __/
  84. \ \ __/
  85. \____\_______/
  86.  
  87. EOF
  88. echo -e "${BLUE}docker${NC} is configured to use the ${GREEN}${VM}${NC} machine with IP ${GREEN}$(${DOCKER_MACHINE} ip ${VM})${NC}"
  89. echo "For help getting started, check out the docs at https://docs.docker.com"
  90. echo
  91. cd
  92.  
  93. docker () {
  94. MSYS_NO_PATHCONV=1 docker.exe "$@"
  95. }
  96. export -f docker
  97.  
  98. if [ $# -eq 0 ]; then
  99. echo "Start interactive shell"
  100. exec "$BASH" --login -i
  101. else
  102. echo "Start shell with command"
  103. exec "$BASH" -c "$*"
  104. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement