Monday, December 22, 2008

Change Netbeans UI Language

Before Netbeans 6.0, change ${Netbeans_HOME}/etc/netbeans.conf, add:
--locale language=en
in netbeans_default_options, and restart is OK.

For Netbeans 6.0+, this will lead to error message:
"An attempt was made to look up a localized manifest attribute named: openide-module-deprecation-message_nb_language=en

This name is in an invalid format. If you are running the Macintosh MRJ on MacOS X, make sure that your locale settings are valid. Currently: language=en

The new way now is to add:
-J-Duser.language=en -J-Duser.region=US
in netbeans_default_options


Convert Subversion Repositories to Mercurial

Finally found some time to migrate some projects from SVN to Hg. The enterprise SVN became so cumbersome and slow as people keep throwing all junks into it, which you have no control of.
  • The 1st recipe was trying to convert directly using Hg in Working With Subversion Repositories
    hg convert --config convert.hg.tagsbranch=0
    But there seemed a bug in Hg when the SVN requires HTTP authorization - even the user and password were correct it still could not pass through:

    initializing destination project1 repository
    http authorization required
    realm: crowd
    user: marshal
    real URL is
    http authorization required
    realm: crowd
    user: marshal
    http authorization required
    realm: crowd
    user: marshal
    abort: HTTP Error 401: Authorization Required

  • Now veer to the Python tool for Hg, which requires Python 2.5+ (already included on Ubuntu 8.1+) & SVN.Do the following:
    # svn not installed by default
    sudo apt-get install subversion
    # easy_install not included in Python package by default
    sudo apt-get install python-setuptools
    # download & install hgsvn
    sudo easy_install hgsvn
    Best match: hgsvn 0.1.6
    Processing hgsvn-0.1.6-py2.5.egg
    Moving hgsvn-0.1.6-py2.5.egg to /usr/lib/python2.5/site-packages
    Adding hgsvn 0.1.6 to easy-install.pth file
    Installing hgimportsvn script to /usr/bin
    Installing hgpullsvn script to /usr/bin

    Installed /usr/lib/python2.5/site-packages/hgsvn-0.1.6-py2.5.egg
    Processing dependencies for hgsvn
    Finished processing dependencies for hgsvn

  • The real staff:
    * svn 'info' '--xml' ''
    Password for 'marshal':

    Then the program froze after you typed the password. (Well, it happened to me).
    So I have to manually run:
    svn info
    And key in the user name/password there, it passed.
  • Import SVN project again:
    This will import SVN's project1 into current directory and no authorization required any more.
    cd project1
    pulls all SVN history. Then the daily use of mercurial starts...

Saturday, December 6, 2008

Ubuntu SSH How-to

Scenario: generate SSH key pairs and use PuTTY to logon to Ubuntu without inputing user & password each time.
  • Create the Cryptographic Keys:
    $ ssh-keygen -t rsa
    Assign the pass phrase (press [enter] key twice if you don't want a passphrase). It will create 2 files in ~/.ssh directory as follows:
    ~/.ssh/id_rsa : identification (private) key
    ~/.ssh/ : public key
  • Use WinSCP to copy the id_rsa (private key) to desktop, use PuTTYgen.exe to load this key and save private key to PuTTY's format.
  • Add in ~/.ssh/authorized_keys (or authorized_keys2), just in 1 line. Or simply
    mv authorized_keys
  • Be sure both the home directory and the .ssh directory be owned and writable only by the owner (700 recommended for .ssh)
  • Any error see /var/log/auth.log
  • sshd protocol 1 is insecure, so vi /etc/ssh/sshd_config:
    Protocol 2
    PasswordAuthentication no # if want to disable interactive logon
  • Restart sshd:
    $ sudo /etc/init.d/ssh restart
  • Use the saved private key in PuTTY:
    PuTTY Configuration -> Connection -> SSH -> Auth -> Private key file for authentication,
    then load the private key. Or use PAGEANT to load this automatically.
  • Change passphrase:
    If it's already converted to PuTTY format, use PuTTYgen.exe to convert it back to OpenSSH format, then
    $ ssh-keygen -p
    Enter file in which the key is (id_rsa):...


Friday, December 5, 2008

'tree' script under Linux/Unix/Cygwin

A simple script to traverse all the directories and do whatever you want. The byproduct is a MS-DOS tree command.

listAll() {
    local f
    local i=$1

    for f in `ls -1`; do    # 1 file per line
        if [ -f "$f" ]; then
            indent $i
            echo "|- $f"
            if [ "$COMMAND" != "" ]; then
                $COMMAND "$f"
        elif [ -d "$f" ]; then
            indent $i
            echo "+- $f"
            let i+=$INDENTS
            cd "$f"
            listAll $i
            cd ..
            let i-=$INDENTS

indent() {
    local i=0
    while (( i < $1 )) # or: while [ i -lt $1 ]
        echo -n " "
        let i+=1

echo "Usage: shred-tree [-u]"
echo "-u: shred; otherwise just list"

if [ "$1" = "-u" ]; then
    COMMAND="" # put your command here, eg. ls -l

# space delimitered:

# \n delimitered:

IFS=$nIFS   # For file names containing spaces
listAll 0