Skip to content

Instantly share code, notes, and snippets.

@tribut
Last active June 4, 2018 11:33
Show Gist options
  • Select an option

  • Save tribut/5285883 to your computer and use it in GitHub Desktop.

Select an option

Save tribut/5285883 to your computer and use it in GitHub Desktop.

Revisions

  1. tribut revised this gist Apr 10, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mosh_pc.sh
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ if [ -z "$REMOTEIP" ]; then
    exit 1
    fi
    # does the remote have a hostname listed in .ssh/config
    REMOTEHOST="`grep -E -C1 '^Host ([a-zA-Z0-9 ]+ )?porcus( [a-zA-Z0-9 ]+)?$' ~/.ssh/config | tail -n1 | sed -r 's/\W*Hostname\W+//'`"
    REMOTEHOST="`grep -E -C1 \"^Host ([a-zA-Z0-9 ]+ )?$REMOTE( [a-zA-Z0-9 ]+)?$\" ~/.ssh/config | tail -n1 | sed -r 's/\W*Hostname\W+//'`"
    if [ -z "$REMOTEHOST" ]; then REMOTEHOST="$REMOTE"; fi
    # try to resolve hostname
    REMOTEIP="`dig +short $REMOTEHOST`"
  2. tribut revised this gist Apr 10, 2013. 1 changed file with 18 additions and 11 deletions.
    29 changes: 18 additions & 11 deletions mosh_pc.sh
    Original file line number Diff line number Diff line change
    @@ -1,34 +1,41 @@
    #!/bin/sh

    # ########################################################## #
    # wrapper for mosh to work with ssh's proxycommand directive #
    # this only makes sense if the machine is directly reachable #
    # from the internet using udp. #
    # ########################################################## #

    THISSCRIPT="`basename \"$0\"`"
    REMOTE="$1"
    REMOTEIP="$2"

    debug() {
    echo "[$THISSCRIPT] $@" >&2
    }
    usage() {
    debug "use me like this: $THISSCRIPT host [ip]"
    }

    # some default values
    if [ -z "$REMOTEIP" ]; then
    if [ -z "$REMOTE" ]; then
    ## bail out:
    debug "please call me like this: $0 host [ip]"
    usage
    exit 1
    ## or:
    #REMOTE="PUT_DEFAULT_HOST_HERE"
    fi
    ## try to resolve hostname:
    REMOTEIP="`dig +short $REMOTE`"
    # does the remote have a hostname listed in .ssh/config
    REMOTEHOST="`grep -E -C1 '^Host ([a-zA-Z0-9 ]+ )?porcus( [a-zA-Z0-9 ]+)?$' ~/.ssh/config | tail -n1 | sed -r 's/\W*Hostname\W+//'`"
    if [ -z "$REMOTEHOST" ]; then REMOTEHOST="$REMOTE"; fi
    # try to resolve hostname
    REMOTEIP="`dig +short $REMOTEHOST`"
    if [ -z "$REMOTEIP" ]; then
    debug "could not resolve hostname"
    debug "could not resolve hostname $REMOTE"
    exit 1
    fi
    ## or:
    #REMOTEIP="PUT_DEFAULT_IP_HERE"
    fi

    debug "starting mosh-server on remote server $REMOTE"
    MOSHDATA="`ssh -t \"$REMOTE\" mosh-server new -s | grep '^MOSH' | tr -d \"\r\n\"`"
    MOSHDATA="`ssh -t \"$REMOTE\" mosh-server new | grep '^MOSH' | tr -d \"\r\n\"`"
    if [ -z "$MOSHDATA" ]; then
    debug "mosh-server could not be started"
    exit 1
    @@ -42,5 +49,5 @@ if [ -z "$PORT" -o -z "$MKEY" ]; then
    exit 1
    fi

    debug "starting local mosh-client"
    debug "starting local mosh-client to $REMOTEIP"
    MOSH_KEY="$MKEY" exec mosh-client "$REMOTEIP" "$PORT"
  3. tribut revised this gist Apr 1, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mosh_pc.sh
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ debug() {
    if [ -z "$REMOTEIP" ]; then
    if [ -z "$REMOTE" ]; then
    ## bail out:
    debug "please call me like this: ./$THISSCRIPT host [ip]"
    debug "please call me like this: $0 host [ip]"
    exit 1
    ## or:
    #REMOTE="PUT_DEFAULT_HOST_HERE"
  4. tribut revised this gist Apr 1, 2013. 1 changed file with 13 additions and 2 deletions.
    15 changes: 13 additions & 2 deletions mosh_pc.sh
    Original file line number Diff line number Diff line change
    @@ -10,10 +10,21 @@ debug() {

    # some default values
    if [ -z "$REMOTEIP" ]; then
    REMOTEIP="PUT_DEFAULT_IP_HERE"
    if [ -z "$REMOTE" ]; then
    REMOTE="PUT_DEFAULT_HOST_HERE"
    ## bail out:
    debug "please call me like this: ./$THISSCRIPT host [ip]"
    exit 1
    ## or:
    #REMOTE="PUT_DEFAULT_HOST_HERE"
    fi
    ## try to resolve hostname:
    REMOTEIP="`dig +short $REMOTE`"
    if [ -z "$REMOTEIP" ]; then
    debug "could not resolve hostname"
    exit 1
    fi
    ## or:
    #REMOTEIP="PUT_DEFAULT_IP_HERE"
    fi

    debug "starting mosh-server on remote server $REMOTE"
  5. tribut created this gist Apr 1, 2013.
    35 changes: 35 additions & 0 deletions mosh_pc.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    #!/bin/sh

    THISSCRIPT="`basename \"$0\"`"
    REMOTE="$1"
    REMOTEIP="$2"

    debug() {
    echo "[$THISSCRIPT] $@" >&2
    }

    # some default values
    if [ -z "$REMOTEIP" ]; then
    REMOTEIP="PUT_DEFAULT_IP_HERE"
    if [ -z "$REMOTE" ]; then
    REMOTE="PUT_DEFAULT_HOST_HERE"
    fi
    fi

    debug "starting mosh-server on remote server $REMOTE"
    MOSHDATA="`ssh -t \"$REMOTE\" mosh-server new -s | grep '^MOSH' | tr -d \"\r\n\"`"
    if [ -z "$MOSHDATA" ]; then
    debug "mosh-server could not be started"
    exit 1
    fi

    PORT="`echo -n \"$MOSHDATA\" | cut -s -d' ' -f3`"
    MKEY="`echo -n \"$MOSHDATA\" | cut -s -d' ' -f4`"

    if [ -z "$PORT" -o -z "$MKEY" ]; then
    debug "got no parseable answer"
    exit 1
    fi

    debug "starting local mosh-client"
    MOSH_KEY="$MKEY" exec mosh-client "$REMOTEIP" "$PORT"