<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>Weiqi Gao&#039;s Observations - cygwin tag</title>
  <link>http://www.weiqigao.com/blog/tags/cygwin/</link>
  <description>Sharing My Experience...</description>
  <language>en</language>
  <copyright>Weiqi Gao</copyright>
  <lastBuildDate>Fri, 11 May 2012 12:48:36 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  <image>
    <url>http://pebble.sourceforge.net/common/images/powered-by-pebble.gif</url>
    <title>Weiqi Gao&#039;s Observations</title>
    <link>http://www.weiqigao.com/blog/</link>
  </image>
  
  
  <item>
    <title>Your jirb, groovysh and clj Commands Doesn&#039;t Work In Cygwin</title>
    <link>http://www.weiqigao.com/blog/2008/04/08/your_jirb_groovysh_and_clj_commands_doesnt_work_in_cygwin.html</link>
    
      
        <description>
          &lt;p&gt;This is another one of those &lt;em&gt;making things work in Cygwin&lt;/em&gt; posts.  You can safely skip this post if you are not married to &lt;a href= &#034;http://cygwin.com/&#034; &gt;Cygwin&lt;/a&gt;, or have not followed my &lt;a href= &#034;http://www.weiqigao.com/blog/2006/08/14/ten_steps_to_higher_cygwin_productivity.html&#034; &gt;Ten Steps To Higher Cygwin Productivity&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The issue this time is with a little library called &lt;a href= &#034;http://jline.sourceforge.net/&#034; &gt;JLine&lt;/a&gt;, which is a BSD licensed library that brings GNU readline style command line editing to Java.  I first learned about it through the &lt;a href= &#034;http://clojure.org/reference/getting_started.html&#034; &gt;Clo&lt;i&gt;j&lt;/i&gt;ure&lt;/a&gt; programming language (a LISP with immutable variables and software transactional memory (STM)).&lt;/p&gt;

&lt;p&gt;And of course, it doesn&#039;t work in my Cygwin xterm window.  A little Googling landed me at &lt;a href= &#034;http://sourceforge.net/tracker/index.php?func=detail&amp;aid=1822900&amp;group_id=64033&amp;atid=506056&#034; &gt;JLine issue-1822900&lt;/a&gt;.  A little looking around in the JLine source and some experiments later, I had a partial workaround, which I added as a comment to the issue.&lt;/p&gt;

&lt;p&gt;While doing the Google search, I also noticed that both Groovy and JRuby use JLine to some extend (in jirb and groovysh).  Sure enough, the same issue showed up in the Groovy JIRA as &lt;a href= &#034;http://jira.codehaus.org/browse/GROOVY-2584&#034; &gt; 	 GROOVY-2584&lt;/a&gt;, to which I added the workaround.&lt;/p&gt;

&lt;p&gt;A fresh download of the just released JRuby 1.1 showed the same symptom.  The JLine workaround can be applied directly to the &lt;tt&gt;jruby&lt;/tt&gt; script, which, thankfully, does contain infrastructure for Cygwin support.&lt;/p&gt;

&lt;p&gt;There are other issues with JLine on a Cygwin xterm.  But the workaround at least makes the repls workable.&lt;/p&gt;

&lt;p&gt;The part that makes me uncomfortable is that I don&#039;t see how this workaround can be incorporated into a patch for JLine.  In that regard, I concede Cygwin is a somewhat hacky platform.  (Jonathan and Adam, if you are still reading...)&lt;/p&gt;
        </description>
      
      
    
    
    
    <comments>http://www.weiqigao.com/blog/2008/04/08/your_jirb_groovysh_and_clj_commands_doesnt_work_in_cygwin.html#comments</comments>
    <guid isPermaLink="true">http://www.weiqigao.com/blog/2008/04/08/your_jirb_groovysh_and_clj_commands_doesnt_work_in_cygwin.html</guid>
    <pubDate>Tue, 08 Apr 2008 13:28:08 GMT</pubDate>
  </item>
  
  <item>
    <title>Java, Bash, Cygwin, ...</title>
    <link>http://www.weiqigao.com/blog/2008/03/10/java_bash_cygwin.html</link>
    
      
        <description>
          &lt;p&gt;I haven&#039;t used the &lt;em&gt;A, B, C, ...&lt;/em&gt; style title for a while.  Today&#039;s post calls attention to all distributors of Java products that provides a Windows batch file and a Unix shell script to run their product:&lt;/p&gt;

&lt;center&gt;
&lt;p style=&#034;color:red;font-size:large&#034;&gt;YOUR SHELL SCRIPT DOESN&#039;T WORK FOR CYGWIN&lt;/p&gt;
&lt;/center&gt;

&lt;p&gt;The problems usually stem from the assumption that a shell script works in the Unix like environment where paths are separated by a &#034;:&#034;.  Well, for Java under Cygwin, this assumption is no longer valid because the Windows version of the JDK commands such as &lt;tt&gt;java&lt;/tt&gt; or &lt;tt&gt;javac&lt;/tt&gt; expect the &lt;tt&gt;CLASSPATH&lt;/tt&gt; environment variable and the arguments to the &lt;tt&gt;-classpath&lt;/tt&gt; and &lt;tt&gt;-bootclassapth&lt;/tt&gt; command line options to be in the Windows format&amp;mdash;with a &#034;;&#034;-separator.&lt;/p&gt;

&lt;p&gt;As an example, here is the &lt;tt&gt;java&lt;/tt&gt; shell script shipped with the &lt;a href= &#034;http://slm888.com/javac/&#034; &gt;CICE/ARM closures prototype&lt;/a&gt;:&lt;/p&gt;

&lt;pre style=&#034;margin-left:3em&#034;&gt;#!/bin/sh
CICEARM_HOME=`dirname $0`/..
java -Xbootclasspath/p:$CICEARM_HOME/lib/rt.jar &#034;$@&#034;&lt;/pre&gt;

&lt;p&gt;There are two problems with this script.  First, it&#039;s self recursive, so you cannot put the directory that contains this script into your PATH, or it will call itself in an infinite loop.  That&#039;s easily fixed by resolving the &lt;tt&gt;java&lt;/tt&gt; call not through the &lt;tt&gt;PATH&lt;/tt&gt; but through &lt;tt&gt;JAVA_HOME&lt;/tt&gt;:&lt;/p&gt;

&lt;pre style=&#034;margin-left:3em&#034;&gt;#!/bin/sh
CICEARM_HOME=`dirname $0`/..
&lt;span style=&#034;color:red&#034;&gt;&#034;${JAVA_HOME}/bin/java&#034;&lt;/span&gt; -Xbootclasspath/p:$CICEARM_HOME/lib/rt.jar &#034;$@&#034;&lt;/pre&gt;

&lt;p&gt;That brings us to the second problem: the mis-interaction between the Unix style directory names and path separators that bash uses and the JDK commands.  If I install the CICE/ARM prototype in the &lt;tt&gt;/opt/cicearm-b05&lt;/tt&gt; directory, and add &lt;tt&gt;/opt/cicearm-b05/bin&lt;/tt&gt; to my &lt;tt&gt;PATH&lt;/tt&gt;, the above script will expand a simple &lt;b&gt;&lt;tt&gt;java Foo&lt;/tt&gt;&lt;/b&gt; command into:&lt;/p&gt;

&lt;pre style=&#034;margin-left:3em&#034;&gt;C:\Program Files\Java\jdk1.6.0_10/bin/java -Xbootclasspath/p:&lt;span style=&#034;color:red&#034;&gt;/opt/cicearm-b05/bin/../lib/rt.jar&lt;/span&gt; Foo&lt;/pre&gt;

&lt;p&gt;Notice here that we are passing a Cygwin style path &lt;tt&gt;/opt/cicearm-b05/bin/../lib/rt.jar&lt;/tt&gt; to the &lt;tt&gt;java&lt;/tt&gt; command, which will interpret the path as a Windows style path.  Most of the time, this will lead to the wrong result.&lt;/p&gt;

&lt;p&gt;Fortunately, Cygwin provides a command &lt;tt&gt;cygpath&lt;/tt&gt; that can be used to convert the Cygwin style path into a Windows style path.  With the help of this command, and a little bit of &lt;tt&gt;uname&lt;/tt&gt; magic to detect if the bash script is running in Cygwin, we can make the script run properly in Cygwin:&lt;/p&gt;

&lt;pre style=&#034;margin-left:3em&#034;&gt;#!/bin/sh
CICEARM_HOME=`dirname $0`/..

&lt;span style=&#034;color:green&#034;&gt;# detect Cygwin
cygwin=false;
case &#034;`uname`&#034; in
  CYGWIN*) cygwin=true;
esac&lt;/span&gt;

&lt;span style=&#034;color:red&#034;&gt;BCP&lt;/span&gt;=${CICEARM_HOME}/lib/rt.jar

&lt;span style=&#034;color:green&#034;&gt;if $cygwin; then
  &lt;span style=&#034;color:red&#034;&gt;BCP&lt;/span&gt;=`cygpath --path --windows &lt;span style=&#034;color:red&#034;&gt;$BCP&lt;/span&gt;`
fi&lt;/span&gt;

&#034;${JAVA_HOME}/bin/java&#034; -Xbootclasspath/p:&lt;span style=&#034;color:red&#034;&gt;${BCP}&lt;/span&gt; &#034;$@&#034;&lt;/pre&gt;

&lt;p&gt;I know there are not a whole lot &lt;span style=&#034;color:purple&#034;&gt;vocal&lt;/span&gt; Cygwin users out there.  Most users would just fix their bash scripts for Cygwin quietly and move on.  But for projects still in development, doing the same modification for every snapshot release becomes tiresome very quickly.  That&#039;s why I usually send my  modifications back to the project.  And sometimes &lt;a href= &#034;http://openjfx.java.sun.com/jira/browse/JFXC-440&#034; &gt;they even took it&lt;/a&gt;.
        </description>
      
      
    
    
    
    <comments>http://www.weiqigao.com/blog/2008/03/10/java_bash_cygwin.html#comments</comments>
    <guid isPermaLink="true">http://www.weiqigao.com/blog/2008/03/10/java_bash_cygwin.html</guid>
    <pubDate>Mon, 10 Mar 2008 23:29:21 GMT</pubDate>
  </item>
  
  <item>
    <title>Using OpenSSH With Cygwin</title>
    <link>http://www.weiqigao.com/blog/2006/08/28/using_openssh_with_cygwin.html</link>
    
      
        <description>
          &lt;p&gt;I have learned a few more things about Cygwin since I posted &lt;a href= &#034;http://www.weiqigao.com/blog/2006/08/14/ten_steps_to_higher_cygwin_productivity.html&#034; &gt;Ten Steps To Higher Cygwin Productivity&lt;/a&gt; 14 days ago:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I need to add another word &lt;tt&gt;smbntsec&lt;/tt&gt; to my &lt;tt&gt;CYGWIN&lt;/tt&gt; environment variable in order for it to pick up the file permissions from Samba.  This fixed a problem I have at work where my home directory is on a Samba share and no matter what I do (&lt;tt&gt;chmod 600&lt;/tt&gt; from within Cygwin, or change the security settings using Windows properties box) all files on that share are readable by the world.  OpenSSH didn&#039;t like it because my private key is world readable.  The &lt;tt&gt;smbntsec&lt;/tt&gt; word cured that.  And now I don&#039;t have to fall back to using my passwords to log in to remote systems.&lt;/li&gt;

&lt;li&gt;I read up a bit about the OpenSSH &lt;tt&gt;ssh-agent&lt;/tt&gt;, &lt;tt&gt;ssh-add&lt;/tt&gt; commands and the way the OpenSSH &lt;tt&gt;ssh&lt;/tt&gt; and &lt;tt&gt;scp&lt;/tt&gt; commands interact with them.  Here&#039;s what it boils down to:

&lt;ul&gt;
&lt;li&gt;I can just use &lt;tt&gt;ssh&lt;/tt&gt; without ever bothering with &lt;tt&gt;ssh-agent&lt;/tt&gt;.  In this mode I have to type in my key store pass phrase on every invocation of the &lt;tt&gt;ssh&lt;/tt&gt; command.&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;ssh-agent&lt;/tt&gt; creates an in-memory cache of private keys and &lt;tt&gt;ssh-add&lt;/tt&gt; add private keys to the cache managed by &lt;tt&gt;ssh-agent&lt;/tt&gt;.  If &lt;tt&gt;ssh&lt;/tt&gt; knows where to look, it will try to look up the private key it needs from &lt;tt&gt;ssh-agent&lt;/tt&gt;&#039;s cache.  If the key is already there, it won&#039;t prompt me for the pass phrase.&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;ssh-agent&lt;/tt&gt; tells the world how to get hold of it through a pair of environment variables: &lt;tt&gt;SSH_AUTH_SOCK&lt;/tt&gt; and &lt;tt&gt;SSH_AGENT_PID&lt;/tt&gt;.  If &lt;tt&gt;ssh-agent&lt;/tt&gt; is invoked with an optional command, e.g., &lt;tt&gt;ssh-agent xterm&lt;/tt&gt;, that command (in this case &lt;tt&gt;xterm&lt;/tt&gt;) will be run in an environment where &lt;tt&gt;SSH_AUTH_SOCK&lt;/tt&gt; and &lt;tt&gt;SSH_AGENT_PID&lt;/tt&gt; are set to the correct values.  Otherwise, it just prints out the settings in bash script format:

&lt;pre style=&#034;margin-left:3em&#034;&gt;[weiqi@gao] $ &lt;b&gt;ssh-agent&lt;/b&gt;
SSH_AUTH_SOCK=/tmp/ssh-euTnCkoNOS/agent.3336; export SSH_AUTH_SOCK;
SSH_AGENT_PID=3328; export SSH_AGENT_PID;
echo Agent pid 3328;&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;

&lt;li&gt;To make it all work in my setup, I added a line to my &lt;tt&gt;startxwin.bat&lt;/tt&gt; batch file

&lt;pre style=&#034;margin-left:3em&#034;&gt;%RUN% ssh-agent &gt; /etc/profile.d/ssh-agent.sh&lt;/pre&gt;

right before the xterms are run.  This way, by the time the xterms are started, the file &lt;tt&gt;/etc/profile.d/ssh-agent.sh&lt;/tt&gt; is already written and contains the correct environment variables.  The bash shell running inside each xterm will source this file as part of the start up process.  Consequently they will have the correct environment for &lt;tt&gt;ssh&lt;/tt&gt;, &lt;tt&gt;scp&lt;/tt&gt; and &lt;tt&gt;ssh-add&lt;/tt&gt; to talk with the agent.  I still need to run &lt;tt&gt;ssh-add&lt;/tt&gt; (and be prompted for the private key store pass phrase) in one of the xterms to populate the agent&#039;s key cache.  Subsequent &lt;tt&gt;ssh&lt;/tt&gt; and &lt;tt&gt;scp&lt;/tt&gt; invocations will find the key in the cache and won&#039;t prompt me for the key store pass phrase.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;[&lt;b&gt;Update&lt;/b&gt; &lt;tt&gt;Thu Aug 31 19:57:10 CST 2006&lt;/tt&gt;] &lt;em&gt;(It helps if I tested my script before I posted it.)&lt;/em&gt;  The above script has two flows: 1) it doesn&#039;t kill the old ssh-agent, 2) it should have used Windows file names since &lt;tt&gt;startxwin.bat&lt;/tt&gt; is a Windows batch file.  The correct script is

&lt;pre style=&#034;margin-left:3em&#034;&gt;c:\cygwin\bin\pkill ssh-agent
del c:\cygwin\etc\profile.d\ssh-agent.sh
c:\cygwin\bin\ssh-agent &gt; c:\cygwin\etc\profile.d\ssh-agent.sh&lt;/pre&gt;
&lt;/p&gt;
        </description>
      
      
    
    
    
    <comments>http://www.weiqigao.com/blog/2006/08/28/using_openssh_with_cygwin.html#comments</comments>
    <guid isPermaLink="true">http://www.weiqigao.com/blog/2006/08/28/using_openssh_with_cygwin.html</guid>
    <pubDate>Tue, 29 Aug 2006 02:14:02 GMT</pubDate>
  </item>
  
  </channel>
</rss>

