public inbox for cygwin-xfree@sourceware.org
help / color / mirror / Atom feed
From: Marko Myllynen <myllynen@redhat.com>
To: cygwin-xfree@cygwin.com
Subject: x-app-open - open remote X app windows on Windows desktop with Cygwin
Date: Mon, 11 Nov 2013 13:12:00 -0000	[thread overview]
Message-ID: <5280D7CD.4040102@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1757 bytes --]

Hi,

FWIW, I've written the attached script to facilitate launching remote X
applications on Windows desktop with Cygwin. I presume for most people
on this list it does not provide anything new but its target audience is
rather people who are not very familiar with Cygwin, Linux, X, or SSH
and prefer using Windows, allowing them easily to run remote X
applications just by clicking a desktop icon. In short, the script will
start XWin and setup SSH keys with minimal user intervention allowing
easy but secure use of remote X applications on Windows desktop.

The complete installation instructions are as follows, this is a
copy/paste from the script, after that one just needs to click on the
newly created icon:

# Installation instructions for Cygwin and this script:
#
# 1) Install from http://www.cygwin.com/ using 32 or 64-bit setup*.exe
# 2) During installation, select at least these additional packages:
#
# keychain openssh psmisc xorg-server xterm
#
# 3) Place this script in C:\cygwin\bin
# 4) Create a shortcut on Windows desktop with
#    a) "Start in" being the bin path 3) above
#    b) "Target" being
#
# C:\cygwin\bin\run.exe -p /bin /bin/sh -c "/bin/x-app-open host
application"
#
# In case a user name needs to be specified use the form user@host.
#

I'm not a Cygwin packager and not planning to become one but if someone
sees this valuable, creating an x-app-open Cygwin package with proper
dependencies would allow making the second step above a bit more
straightforward. But even by itself the script, now available in the
list archives, has been helpful.

Wrt to technical details, there might be a corner case or two when XWin
is left behind but otherwise I'm not aware of any major issues with it.

Thanks,

-- 
Marko Myllynen

[-- Attachment #2: x-app-open --]
[-- Type: text/plain, Size: 2728 bytes --]

#!/bin/sh
#
# x-app-open - open remote X app windows on Windows desktop with Cygwin
#
# Copyright (C) 2013 Marko Myllynen <myllynen@redhat.com>
# This program is free software; it is released under the GPLv3.
#
# Installation instructions for Cygwin and this script:
#
# 1) Install from http://www.cygwin.com/ using 32 or 64-bit setup*.exe
# 2) During installation, select at least these additional packages:
#
# keychain openssh psmisc xorg-server xterm
#
# 3) Place this script in C:\cygwin\bin
# 4) Create a shortcut on Windows desktop with
#    a) "Start in" being the bin path 3) above
#    b) "Target" being
#
# C:\cygwin\bin\run.exe -p /bin /bin/sh -c "/bin/x-app-open host application"
#
# In case a user name needs to be specified use the form user@host.
#

SSH_OPTS="-oBatchMode=yes -oConnectTimeout=20 -oStrictHostKeyChecking=no"

# Launch XWin if not there already
XPID=$(ps -ef | grep /bin/XWin | grep -v grep | awk '{print $2}')
if [ "$XPID" = "" ]; then
  run cygstart --hide /bin/XWin :0 -clipboard -multiwindow
  XPID=$(ps -ef | grep /bin/XWin | grep -v grep | awk '{print $2}')
fi
export DISPLAY=$HOSTNAME:0

# Setup SSH keys if needed
while [ ! -f "$HOME/.ssh/id_rsa" ]; do
  xterm +tb -T "Setting up SSH keys..." -e \
    "echo Generating SSH keys, enter a new passphrase, at least 5 characters.;\
      ssh-keygen -f \"$HOME/.ssh/id_rsa\" > /dev/null; \
        echo Copying SSH public key to the remote host...; \
          ssh-copy-id -i \"$HOME/.ssh/id_rsa.pub\" \
            -oStrictHostKeyChecking=no $1 2>&1 | grep -v INFO"
done

# Add SSH keys to ssh-agent with keychain if needed
[[ -f "$HOME/.keychain/$HOSTNAME-sh" ]] && \
  . "$HOME/.keychain/$HOSTNAME-sh" > /dev/null 2>&1
ssh-add -l 2>/dev/null | grep -q "$HOME/.ssh/id_rsa"
if [ $? -ne 0 ]; then
  cygstart --hide xterm +tb -T '"Loading SSH keys..."' -e "keychain -q \"$HOME/.ssh/id_rsa\""
  sleep 3
  while true; do
    sleep 1
    pstree -aA | grep -q -- "[-]xterm +tb -T Loading SSH keys..." || break
  done
  [[ -f "$HOME/.keychain/$HOSTNAME-sh" ]] && \
    . "$HOME/.keychain/$HOSTNAME-sh" > /dev/null 2>&1
fi

# Do the actual work
ssh $SSH_OPTS -X $1 "${@:2}" > /dev/null 2>&1
if [ $? -eq 255 ]; then
  # Connection failed, perhaps a new host, try to copy the key
  xterm +tb -T "Setting up SSH keys..." -e \
    "echo Copying SSH public key to the remote host...; \
      ssh-copy-id -i \"$HOME/.ssh/id_rsa.pub\" \
        -oStrictHostKeyChecking=no $1 2>&1 | grep -v INFO"
  ssh $SSH_OPTS -X $1 "${@:2}" > /dev/null 2>&1
fi

# Terminate XWin if no active connections left
sleep 1
sessions=$(pstree -aA | grep "[s]h $0" | wc -l)
if [ $sessions -le 2 ]; then
  /bin/kill $XPID > /dev/null 2>&1 ; /bin/kill -f $XPID > /dev/null 2>&1
fi


[-- Attachment #3: Type: text/plain, Size: 223 bytes --]

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/

                 reply	other threads:[~2013-11-11 13:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5280D7CD.4040102@redhat.com \
    --to=myllynen@redhat.com \
    --cc=cygwin-xfree@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).