Log <-

Archive for February, 2008

Disable Ubuntu command not found

Sunday, February 17th, 2008

Ubuntu 7.10 has this feature where, if you mistype a command on the shell, it'll bother you with useless information about how you can install that application:

tiagoboldt@Niath:~$ gedit
The program 'gedit' is currently not installed. You can install it by typing:
sudo apt-get install gedit
bash: gedit: command not found
tiagoboldt@Niath:~$

It's pretty annoying if you do a lot of work on the commandline and each time you mistype a command you have to wait for up to a full second before the command fails. I keep thinking I accidentally ran some command which is now wiping my disk. I'm sure it's handy for noobs, but not for commandline junkies.

To get rid of it, type:

sudo aptitude purge command-not-found

And it won't bother you anymore.

Transmission 1.x on Ubuntu 7.10

Sunday, February 17th, 2008

For some reason Ubuntu 7.10 has an ancient version of Transmission. Version 0.74 or somesuch. Unfortunately, that version of Transmission contained some bugs so it's blocked by certain bittorrent trackers. In order to install a more recent version:

You can download a more recent version from the gutsy backports package pool.

  • Uninstall transmission:
    sudo aptitude purge transmission transmission-gtk
  • Download transmission-common 1.04
  • Download transmission-gtk 1.04
  • Install the packages:
    sudo dpkg -i "transmission-common_1.04-0ubuntu1~gutsy1_all.deb"
    sudo dpkg -i "transmission-gtk_1.04-0ubuntu1~gutsy1_i386.deb"

And you'll have a more recent version of Transmission.

VeeDee-Eyes.com: VirtualBox VDI images for download

Saturday, February 16th, 2008

VirtualBox has been getting more and more attention as of late. It is vastly superior to other virtualization programs due to the simple fact that it actually runs on my system. All the others either don't install (VMWare), crash (QEMU), or are a real bitch to set up properly (Xen). VirtualBox is Open Source, easy to install, fast, runs on Linux and Windows and it has both a very nice GUI and a very decent commandline interface. VirtualBox is what VMWare (for Linux) could have been, but better.

Now, WMWare has pre-built images online at their Appliances site. Qemu has the Free OS Zoo. Now there's one for VirtualBox too:

veeDee-Eyes.com:

The VirtualBox "Virtual Disk Image" Index

VDI images of pre-installed "Open Source" Operating System distros.
It's a computer inside your computer.

-Instantly run another operation system on your desktop in a window, on almost any computer.
-Implement full Linux functionality on an existing Windows Desktop or server.

I've been looking for this for a while. All it's currently missing are OpenSolaris and various BSD images. I'm sure these will be added rather quickly.

PS: It appears Innotek, the creators of VirtualBox, have been acquired by Sun. I'm not sure yet whether Sun's acquiring of Open Source companies is a good or bad thing. Guess we'll have to see where it goes. Perhaps they should get the benefit of the doubt since they did free the source of StarOffice (Open Office), Java (in part) and Solaris (in part). I'm just not sure whether Sun understands the Open Source philosophy and community.

Run mobile Midlets on your PC

Thursday, February 14th, 2008

In anticipation of my new phone (a Sony Ericsson W910i), I decided to spend some time finding various Java Midlets which I need for the phone. I was looking for a decent calculator, translator, dictionary and a E-book reader. I wanted to try the applications, but since I don't have the new phone yet, I thought "Why not find an emulator on which to run them?". In this post I'll detail my journey into the crazy world of J2EE, Midlets, CLDC, MIDP, J2RE and various other weird mobile Java stuff, and show you how I got the emulator and Midlets to run on my Unix (Ubuntu) machine.

Prerequisites

To be able to emulate anything at all, you'll need to have the J2RE installed. That's the Java 2 Runtime Environment; the basic stuff you need to run Java programs. Under Ubuntu, it's as easy as:

sudo aptitude install sun-java6-jre

Get Sun Java Wireless Toolkit

Next you'll need to fetch and install the Sun Java Wireless Toolkit (S2WTK2, previously known as J2ME: Java Micro Edition). You can download it from:

http://java.sun.com/products/sjwtoolkit/download.html.

(Registration not required, amazingly enough). Scroll down on the page until you see the 'Download' button. That'll take you to the download page where you must accept the license and download the toolkit for your platform.

Automatic installation

To install it, you can try the installer:

sh ./sun_java_wireless_toolkit-2_5_2-linux.bin

-- LICENSE --
Do you agree to the above license terms? [yes or no] yes

Testing /usr/bin/X11/java...

A suitable Java interpreter was detected

0) Use /usr/bin/X11/
1) Specify a path to a Java interpreter directory.
2) Cancel this installation.
Select a choice [0-2]:

The installer detected the wrong path, so you'll have to find out where your actual JRE resides on your disk. Under Ubuntu, this is: /usr/lib/jvm/java-6-sun/jre/bin, so we enter that instead of the detected path:

0) Use /usr/bin/X11/
1) Specify a path to a Java interpreter directory.
2) Cancel this installation.
Select a choice [0-2]: 1

Enter a path to the Java 2 SDK: /usr/lib/jvm/java-6-sun/jre/bin/
/usr/lib/jvm/java-6-sun/jre/bin//java
Testing /usr/lib/jvm/java-6-sun/jre/bin//java...

Please enter a directory into which you would like to install the Sun Java(TM) Wireless Toolkit, 2.5.2 for CLDC.

-- Blah blah blah -- follow the instructions --
Please choose one of the following options:
0) Begin copying files if you are satisfied with the settings  .
1) Cancel the installation.
Select a choice [0-1]: 0
Checksumming...

Extracting the installation files...
./sun_java_wireless_toolkit-2_5_2-linux.bin: 466: /usr/lib/jvm/java-6-sun/jre/bin/jar: not found
Failed to extract files. Installation will stop now.
Please try to install Sun Java(TM) Wireless Toolkit again, or contact wtk-comments@sun.com for assistance.

Manual installation

Chances are, however, that it won't work because it can't find the jar binary:

./sun_java_wireless_toolkit-2_5_2-linux.bin: 466: /usr/lib/jvm/java-6-sun/jre/bin/jar: not found
Failed to extract files. Installation will stop now.

If this happens with you, there's another way to install it:

  • The .bin file is nothing more than a shell script (the automatic installer) with an .zip file attached to it. We'll have to remove the shell script header so we can unzip the file.
  • Open the sun_java_wireless_toolkit-2_5_2-linux.bin in a text-editor which can edit binary files without screwing things up. Vim works nicely.
  • Remove the shellscript in the beginning of the file. Keep all the binary stuff
  • Save the file
  • Create a new directory and cd into it: mkdir jwt; cd jwt;
  • Unpack the .bin file: unzip ../sun_java_wireless_toolkit-2_5_2-linux.bin
  • You can now run stuff from the Wiress Toolkit in the current dir or move it somewhere on your hard disk (i.e. /opt/j2me )

Now try the Wireless toolkit out to see if it works:

~$ /opt/j2me/bin/ktoolbar

You can try out an example Midlet game by running:

~$ /opt/j2me/bin/runmidlet /opt/j2me/apps/Games/bin/Games.jad

The Emulated Phone

foo.png

The Phone emulator should pop up with some options for games which can be run. You can control the emulator with the mouse, or with the keyboard: F1, F2 are the Left and Right soft keys. Normal arrow keys on your keyboard correspond to the arrows of the phone. Enter emulates the middle button.

You can configure the emulated phone by with the /opt/j2me/bin/prefs program. Here you can change things such as the type of phone emulated, etc.

Put files on the phone

Sometimes you'll want to put files on the phone. For instance, an mp3 or whatever. You can do this by copying files to the j2mewtk/2.5.2/appdb/DefaultColorPhone/filesystem/root1/ directory in your home directory. This directory is automatically created when you run the Phone emulator.

Running midlets

Running Midlets on the phone is harder then it should be. In order for the emulator to be able to run Midlets, it needs both a .jar and a .jad file. The Jar file contains the actual application and the Jad file contains a definition file so that the emulator knows how to run the Midlet. Most Midlets only come with a Jar file and not a Jad file however. Fortunately it's quite easy to create one yourself. Here's a script which you can use to automatically create a .jad file from a .jar file:

#!/bin/sh

while [ -n "$1" ]; do
        JAR=$1
        JAD="`basename \"$JAR\" .jar`.jad"
        JAR_SIZE=`du -b "$1" | cut -f1`

        echo -n "Generating \"$JAD\" from \"$JAR\".. "
        unzip -p -x "$1" META-INF/MANIFEST.MF > "$JAD"
        echo "" >> "$JAD"
        echo "MIDlet-Jar-URL: $1" >> "$JAD"
        echo "MIDlet-Jar-Size: $JAR_SIZE" >> "$JAD"
        echo "Done."

        shift
done

Copy-paste the file above into a file named jar2jad.sh and make it executable: chmod 755 ./jar2jad.sh. You can now run:

~$ ./jar2jad.sh foo.jar

In order to create a corresponding .jad file. Now you can run the Midlet by executing:

~$ /opt/j2me/bin/runmidlet ./foo.jad

You can now download .jar midlets and test them out on your PC before actually running them on your phone. Not all midlets will work on the emulator though, since some of them depend on phone specific Java libraries. Some phone manufacturers give out SDK's (System Development Kits) for their phones which you can download and install so you can test Midlets which are specific for certain phones. This will be left as an exercise for the reader though.

DVTM – dynamic virtual terminal manager

Monday, February 11th, 2008

I do a lot of remote UNIX administration on various servers and even some desktop machines. This usually means that I'm doing a lot of SSHing into machines, often opening multiple sessions to the same machine at the same time. It quickly becomes tedious to keep having to type 'ssh fboender@some.machine.com' four times in order to get four sessions.

Of course there is Screen, but Screen's split screen abilities are very limited and don't really work for me. While scanning Freshmeat.net, I found a tool called DVTM: dynamic virtual terminal manager.

DVTM
DVTM is a kind of window manager for the console (or xterm) which allows you to quite easily split your terminal into multiple split screens.

DVTM has some limitations though:

  • Configuration is done using C code. (Though you'll probably never need to change anything; the defaults are quite sane)
  • It doesn't seem to support ANSI colouring. I use a red background at my prompt when I'm root, which I now have to miss.
  • It also doesn't seem to support line-drawing. This probably has something to do with the terminal type.
  • DVTM has no internal support for detaching and reattaching to running DVTM instances like Screen can. (But see the Tips and tricks section on the homepage).
  • There are a couple of small bugs, one of which is a problem with repeating keys when switching between split windows with the mouse.

But make no mistake: despite these shortcomings, DVTM is an absolutely fantastic tool. Some of the neat stuff it supports is:

  • Mouse support for switching between split windows / maximizing and unmaximizing, etc.
  • Maximize/unmaximize the currently active window (Default: Ctrl-g m / Ctrl-g g)
  • Various window layouts (you can probably add your own by hacking the source code)
  • Almost no dependencies except for ncurses.

The only thing I'd really like to see changed about DVTM are custom run-time splitting (for instance, Ctrl-g-MINUS to split the current window horizontally and Ctrl-g-PIPE to split the window vertically) and detaching/reattaching.

All in all, DVTM is an awesome tool. Go download it if you do a lot of remote administration.

Update: There also appear to be two bugs:

  • On the latest Ubuntu: Sometimes when exiting DVTM, it will hang for a while, and the cursor will blink like mad. An strace shows that IO Errors are occuring on file descriptor 3. I've filed a bug report with the author. This bug doesn't appear on Debian stable.
  • When using DVTM in combination with dtach, reattaching doesn't redraw the screen. This appears to be a problem with DVTM, but it would probably be easier to solve in dtach (which could just signal a screen resize event without actually resizing the screen). This is also the workaround for this bug: just resize the window. I'll see if I can file a bug report with either DVTM's author or dtach's author.

Update II: Here's a little patch/workaround for the first bug (exiting DVTM hangs for a while):

--- dvtm.c      2008-02-06 17:30:25.000000000 +0100
+++ ../dvtm-0.4/dvtm.c  2008-02-11 23:33:45.000000000 +0100
@@ -896,6 +896,7 @@
                Client *c;
                int r, nfds = 0;
                fd_set rd;
+               struct timeval tv;

                if(need_screen_resize)
                        resize_screen();
@@ -996,6 +997,13 @@
                        wnoutrefresh(sel->window);
                }
                doupdate();
+
+               // One microsecond delay so this loop doesn't hang context-switching
+               // when the last child dies and the SIGCHLD signal is prevented from
+               // being caught on time.
+               tv.tv_sec = 0;
+               tv.tv_usec = 1;
+               select(0, NULL, NULL, NULL, &tv);
        }

        cleanup();

Save to ~/patch.diff and in the dvtm-0.4 directory run:

~/dvtm-0.4$ patch -p0 < ~/patch.diff

Update III:

I was incorrect in stating that dvtm doesn't support ANSI coloring. It's just the bash prompt which doesn't work. Perhaps because there is a Xterm-styled window title ANSI sequence in there. Will update when I know more.

Update IV:

Marginally better patch:

diff -Naur ./dvtm.c ../dvtm-0.4/dvtm.c
--- ./dvtm.c	2008-02-06 17:30:25.000000000 +0100
+++ ../dvtm-0.4/dvtm.c	2008-02-12 22:08:54.000000000 +0100
@@ -982,7 +982,10 @@

 		for(c = clients; c; c = c->next){
 			if(FD_ISSET(c->pty, &rd)){
-				madtty_process(c->term);
+				if (madtty_process(c->term) < 0 && errno == EIO) {
+					/* client probably terminated */
+					client_killed = c;
+				}
 				if(c != sel){
 					draw_content(c);
 					if(!isarrange(fullscreen))