Archive for March, 2008

Use Windows In the Spirit of Linux (3)

March 24, 2008

OK, Let’s get to the exciting things we can do with Windows and free/open source software.

Emacs

The gnu emacs official site has a pre built binary of nt emacs, I downloaded it, but it will hang when I start it. The reason is I put cygwin into my PATH environment variable, and emacs will try to load the libjpeg6, libpng12 etc in the cygwin installation. But these .dll files are of wrong "format" — so to speak — for emacs, so it hung.

To solve this issue, I downloaded the libraries from the gnuw32 project on sourceforge.net, and put them into the bin dir with emacs.exe

I got no idea why emacs will hang for quite some long time, but then I came across the image support in emacs and tried to make it work, and realized that this is the reason why emacs hung.

Emacs also comes with cygwin, but it requires X server, and when I last used it, it was not very stable, so I let go this version of emacs.

SSH Tools

I have been using ssh since a long long time ago, but I never knew that ssh includes a family of tools such as ssh-keygen, ssh-agent, and ssh-add.

With these tools, you can avoid inputting your password every time you open a new ssh connection to a sshd server. Which is quite boring (if you know that there’s another way). Also, you can avoid inputting password by writing it into a file, and use expect(1) to automate login, but that should be considered a security leak.

  1. Use ssh-keygen to generate a key, transfer and rename the public key to the server ~/.sshd/authorized_keys
  2. Run ssh-agent and ssh-add when I login. (It was written in a .bat file in ~/Start Menu/Programs/Startup, so it will automatically start and wait for my once and only once password input)
  3. the ssh-agent output is redirected to a file, and I source it in my ~/.bashrc.
Tramp

Tramp allow you to open files on remote hosts using ssh/scp etc. programs, but the cygwin version of ssh won’t work easily (actually, it’s very difficult, IMHO). Luckily, we have another free software:

Putty Tools

Putty is also a family of tools, including putty (the terminal?), pageant (ssh-agent counterpart), plink (ssh parallel) and pscp (scp counterpart).

I also had a problem using these tools with tramp, that is, when used with tramp, my plink/pscp will require me to input password every time even I have pageant started. I downloaded the source and debugged it, and found out that it’s because pageant considers itself to be of different user/permission with the requesting plink/pscp, because they are started differently: pageant is started by the windows explorer, while plink/pscp is started by cygwin (I set shell-file-name to cygwin bash in my .emacs). Obviously cygwin did some screwing with the user permission thing. The solution is to start pageant with cygwin too.

To be Continued
Advertisements

Some Tips on Using Windows Like It’s a Linux (2)

March 23, 2008
For firefox, the automation proxy script will be like the following (I failed to make both IE and FF use the same script, but as long as they each has a working script, it won’t be a problem):


$cat ~/.proxy.html
function FindProxyForURL(url, host)
{
    if (myIpAddress()=="192.168.1.3") {
        return "DIRECT";
    }
    else if (
        isPlainHostName(host) ||
        (host =="127.0.0.1") ||
        dnsDomainIs(host, ".mycomp.com")
        ) {
        return "DIRECT";
    }
    else {
        return "PROXY gateway.mycomp.com:1080";
    }
}

## Local Variables: ***
## mode: tcl ***
## End: ***

And in firefox, we configure it like the following:

You should note the difference in the way the auto config URL is written, the path separator is / in firefox, but ie uses \. It probably won’t work if you misused. But I have no interest to find it out…

To be continued…

Some Tips on Using EVIL Windows Like It’s a Linux (1)

March 22, 2008

With the help of CYGWIN and other GNU or opensource posix aligning softwares, we can get a Windows box very close to a Linux one. What we want is freedom, and there’s no way that our freedom can be deprived of by Bill Gates and his EVIL Windows system.

Say, we use the company network at office, which uses DHCP, and then we go back from work taking the laptop home, where I use ADSL, and the network should be reconfigured. Also, at company, we used proxy for http visiting. Thus every separate software will require reconfiguration! The IP address of the network card, the IE proxy setting, the Windows Live Writer proxy setting, and the Firefox, and so on.

It’ll be pain like hell if you must do it step by step manually every time. So here’s how I liberate myself and obtain freedom from that pain.

I do this at home:

$cat ~/bin/nethome.sh
#!/bin/bash
netsh interface ip set address name=eth0 source=static addr=192.168.1.3 mask=255.255.255.0 gateway=192.168.1.1 gwmetric=1
netsh interface ip set dns name=eth0 source=static addr=202.109.122.14 register=primary
netsh interface ip add dns name=eth0 addr=210.52.149.2 index=2
#cygstart ~/bin/ieProxyDisable.reg
cd ~/doc
regedit /s MsnBlogProxyDisable.reg 

And here’s how we do it at office:

$cat ~/bin/netoffice.sh
#!/bin/bash
netsh interface ip set address name=eth0 source=dhcp
netsh interface ip set dns name=eth0 source=dhcp
ipconfig /renew
#cygstart ~/bin/ieProxyEnable.reg
cd ~/doc
regedit /s MsnBlogProxyEnable.reg

For the IE and Firefox proxy issue, I used the proxy automatic configuration script feature:


$cat ~/.proxy.pac
function FindClientProxy(url, host) {
    return "DIRECT";
}

function FindServerProxy(url, host) {
    if (shExpMatch(host, "*.mycomp.com") || 
        shExpMatch(host, "127.0.0.1") || 
        shExpMatch(host, "localhost") || 
        shExpMatch(host, "192.168.*") ||
        shExpMatch(host, "10.*") ||
        isPlainHostName(host))
    return "DIRECT";
    else 
    return "PROXY gateway.mycomp.com:1080";
}

function FindProxyForURL(url, host) {
    if (myIpAddress()=="192.168.1.3") {
        return "DIRECT";
    } else if (shExpMatch(host, "vpn.mycomp.com")) {
        return "DIRECT";
    }
    else {
        return FindServerProxy(url, host);
    }
}

## Local Variables: ***
## mode: tcl ***
## End: ***

Here, I have changed my true company name to a make-up mycomp.com. Also, for the last three lines, it tells my editor emacs to consider it as tcl code, which of course is not, but it give me a satisfying indentation. So whatever. Lastly, make sure in your ieoptions dialog for choosing the script file:

 

 

To be continued…