diff --git a/modules/ssh.func b/modules/ssh.func index b42b19c..98b74fb 100644 --- a/modules/ssh.func +++ b/modules/ssh.func @@ -23,9 +23,31 @@ module_load ssh-config ssh() { - local pw;local cfg;local opts;local mp; local sshpass; local dr; local sshcmd; local term + local pw;local cfg;local opts;local mp; local sshpass; local list; local sshcmd; local term local host; local user; local script; local ret ; local key; local efile; local tfile + help() { + + cat < host +put any additional SSH (man ssh) options after the host, aborting +hH:tu:dF:p:ro:k: +-h +-H +-t +-u +-l +-F +-p +-r +-o +-k +EOF + + } + + if [[ $SSH_CONFIG ]]; then [[ ! -f "$SSH_CONFIG" ]] && ssh_config "$SSH_CONFIG" cfg="-F $SSH_CONFIG" @@ -34,17 +56,21 @@ ssh() { # echo passed: $* local OPTION; local OPTARG; local OPTIND - while getopts 'th:u:mdF:p:ro:k:' OPTION; do + while getopts 'hH:th:u:lF:p:ro:k:' OPTION; do # echo processing: option:$OPTION argument:$OPTARG index:$OPTIND remaining:${@:$OPTIND} case "$OPTION" in - h) + h) + help + return 3 + ;; + H) host=$OPTARG ;; t) term=" -t " ;; - d) - dr=true + l) + list=true ;; r) ret=true @@ -83,13 +109,12 @@ ssh() { echo "using SSH Config file at: $OPTARG" [[ -f $OPTARG ]] && cfg="-F $OPTARG" || echo no config file at $OPTARG, ignored ;; - m) - # echo setting multipass - mp=true - ;; + # m) + # # echo setting multipass + # mp=true + # ;; *) echo unknown run option -$OPTARG - echo "USAGE: ssh host " - echo "put any additional SSH (man ssh) options after the host, aborting" + help return 3 # opts="$opts ${@:$OPTIND:1}" # ((OPTIND+=1)) @@ -104,37 +129,24 @@ ssh() { debug extra ssh options and the remote commands: $@ - [[ ! $host ]] && echo host/ip required, aborting && return 2 + [[ ! $host && ! $list ]] && echo host/ip required, aborting && return 2 + if [[ $host ]]; then [[ ! $user ]] && user=$(get_user_host $host) - - if [[ $mp ]]; then - user=${user:-ubuntu} - [[ ! $host ]] && echo multipass host/ip required, aborting && return 2 - # echo multipass host:$host user:$user - module_load multipass - ip="$(multipass_get_ip $(get_hostname_host $host))" - [[ ! $ip ]] && echo could not resolve ip for multipass instance $1 && return 5 - [[ ! $pw && ! $key ]] && opts+=" $(multipass_ssh_options)" - host="$user@$ip" - else # not an mp vm - [[ $user && (! $host =~ "@") ]] && host=$user@$host - if [[ $user && $host =~ "@" ]]; then - host=$(sed 's/.*@\(.*\)/\1/' <<<"$host") - # option takes precedence - host=$user@$host - fi - opts+=" $cfg" + [[ $user && (! $host =~ "@") ]] && host=$user@$host + if [[ $user && $host =~ "@" ]]; then + host=$(sed 's/.*@\(.*\)/\1/' <<<"$host") + # option takes precedence + host=$user@$host + fi fi - + opts+=" $cfg" + if [[ $ret ]]; then # return arguments so a command can be composed elsewhere { echo "$host,$opts $* ,$sshpass"; return 0; } else - # run remote commands right here sshcmd="$sshpass $(which ssh) $term $opts $host" - # echo extra args: "$@" - # echo running command: "$sshcmd" - if [[ $dr ]]; then + if [[ $list ]]; then echo $sshcmd else $sshcmd "$@" || echo SSH Command Failed: $sshcmd "$@" @@ -143,3 +155,13 @@ fi } # end ssh + + #TODO make this a function for multipass module + # user=${user:-ubuntu} + # [[ ! $host && ! $list ]] && echo multipass host/ip required, aborting && return 2 + # # echo multipass host:$host user:$user + # module_load multipass + # ip="$(multipass_get_ip $(get_hostname_host $host))" + # [[ ! $ip && ! $list ]] && echo could not resolve ip for multipass instance $1 && return 5 + # [[ ! $pw && ! $key ]] && opts+=" $(multipass_ssh_options)" + # host="$user@$ip" \ No newline at end of file diff --git a/modules/sshfs.mod b/modules/sshfs.mod index 6e79e92..170930f 100755 --- a/modules/sshfs.mod +++ b/modules/sshfs.mod @@ -69,6 +69,8 @@ function smount() { # opts+=" $scmd" # remove_end_spaces "$scmd" # return + + # must remote spaces or sshfs fails opts+=" -o ssh_command=$(remove_end_spaces "'$sshpass /usr/bin/ssh $sshopts'")" # [[ ! $(host_reachable $host $(parse_option $sshopts -p)) ]] \