Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Creates ssh ControlMaster file and reuses it for
  4. # subsequent connections.
  5. # TODO: because the ControlMaster is specific for a single
  6. # ssh user, adding '-l otheruser' will not log you in
  7. # as 'otheruser'. Parse out any '-l' option and use that
  8. # to create a user-specific ControlPath.
  9.  
  10. # navigate up directory tree until .vagrant directory is found
  11. # or we hit /.
  12. while : ; do
  13. [[ "$PWD" == '/' ]] && {
  14. echo .vagrant directory not found
  15. exit 1
  16. }
  17. control_dir=$PWD/.vagrant
  18. [[ -d $control_dir ]] && break
  19. cd ..
  20. done
  21.  
  22. vagrant_args=()
  23. ssh_args=()
  24. sep=' -- '
  25. args="$@"
  26. case $args in
  27. (*"$sep"*)
  28. vagrant_args=(${args%%"$sep"*})
  29. ssh_args=(${args#*"$sep"})
  30. ;;
  31. (*)
  32. vagrant_args=($args)
  33. ssh_args=()
  34. ;;
  35. esac
  36.  
  37. name=${vagrant_args:-default}
  38. control_path=."vagrant/machines/${name}/sshcontrolmaster"
  39.  
  40. #echo ssh_args ${ssh_args[@]}; echo name "'$name'";exit
  41.  
  42. if [[ -S "$control_path" ]]; then
  43. if ! echo | nc -U "$control_path"; then
  44. echo "removing stale controlmaster socket"
  45. rm -f "$control_path"
  46. fi
  47. fi
  48.  
  49. if [[ ! -S $control_path ]]; then
  50. vagrant ssh-config $name | ssh -t -t -fN \
  51. -F /dev/stdin \
  52. -o 'ControlPersist=4h' \
  53. -o 'ControlMaster auto' \
  54. -o "ControlPath $control_path" $name
  55. fi
  56.  
  57. ssh -o ControlPath=${control_path} ${name} ${ssh_args[@]}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement