Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Creates ssh ControlMaster file and reuses it for
- # subsequent connections.
- # TODO: because the ControlMaster is specific for a single
- # ssh user, adding '-l otheruser' will not log you in
- # as 'otheruser'. Parse out any '-l' option and use that
- # to create a user-specific ControlPath.
- # navigate up directory tree until .vagrant directory is found
- # or we hit /.
- while : ; do
- [[ "$PWD" == '/' ]] && {
- echo .vagrant directory not found
- exit 1
- }
- control_dir=$PWD/.vagrant
- [[ -d $control_dir ]] && break
- cd ..
- done
- vagrant_args=()
- ssh_args=()
- sep=' -- '
- args="$@"
- case $args in
- (*"$sep"*)
- vagrant_args=(${args%%"$sep"*})
- ssh_args=(${args#*"$sep"})
- ;;
- (*)
- vagrant_args=($args)
- ssh_args=()
- ;;
- esac
- name=${vagrant_args:-default}
- control_path=."vagrant/machines/${name}/sshcontrolmaster"
- #echo ssh_args ${ssh_args[@]}; echo name "'$name'";exit
- if [[ -S "$control_path" ]]; then
- if ! echo | nc -U "$control_path"; then
- echo "removing stale controlmaster socket"
- rm -f "$control_path"
- fi
- fi
- if [[ ! -S $control_path ]]; then
- vagrant ssh-config $name | ssh -t -t -fN \
- -F /dev/stdin \
- -o 'ControlPersist=4h' \
- -o 'ControlMaster auto' \
- -o "ControlPath $control_path" $name
- fi
- ssh -o ControlPath=${control_path} ${name} ${ssh_args[@]}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement