Wednesday, August 24, 2011

Debian/LXDE running on Acer Iconia A500 tab

I got a chance to have this tablet for sometime, and since then I have been hacking it. The first thing to do is most obvious, to root the device. I have reloaded the tablet with Taboonay's ROM (1.1) based on the Android Honeycomb 3.1 stock ROM. It has it's cool features, about which you can read here.

And thanks to lanrat for an article about this.

*** Do this if you fully understand what you are doing***

Now over to getting Debian on to the tablet. 

Your device should be rooted. You need some free space on the SD card, about 1 GB is sufficient for this. Secondly you have to prepare a base installer image of Debian, I did this on Ubuntu 11.04. If you do not have a Linux box don't sweat it, get Linux on a pen drive and boot from that. And you need the Android terminal, also set it up such that your $PATH variable has /system/xbin in the beginning. For installing/configuring LXDE you need to have a mouse and keyboard connected to your tablet (I used an old bluetooth keyboard and mouse from Logitech EX100).

Once you are in Ubuntu open a terminal and do the following to create the base image -
sudo -s
apt-get install debootstrap
dd if=/dev/zero of=debian.img seek=1073741824 bs=1 count=1 # I use 1 GB image size **
mke2fs -F debian.img
mkdir debian
mount -o loop debian.img debian/
debootstrap --verbose --arch armel --foreign lenny debian http://ftp.us.debian.org/debian
umount debian/
rm -r debian/

** you can use lesser image size (800 MB) if you do not want to install LXDE.

With that you have a Debian base installer image. Now download this chroot script, which will be used to set up environment to run Debian (save this file as bootdebian). Copy this image and the chroot script to the SD card, such that it lays in 
/mnt/external_sd

Now put back the SD card into the tablet and power on. Following commands will make the chroot script
executable in Android terminal and turn it into a command, open Android terminal on the tablet and type -
su
mount -o remount,rw -t yaffs2 /dev/block/mmcblk0p3 /system
cat /mnt/external_sd/bootdebian > /system/xbin/bootdebian
dos2unix /system/xbin/bootdebian
rm /mnt/external_sd/bootdebian
chmod 777 /system/xbin/bootdebian

With that done, you have a command 'bootdebian' which can be run to set up to run Debian. 

After this you need to complete the Debian install, for that run the following commands on the Android terminal - 
bootdebian
/debootstrap/debootstrap --second-stage
echo 'deb http://ftp.us.debian.org/debian lenny main' >/etc/apt/sources.list
apt-get autoclean
apt-get update
exit

This completes the Debian install. From now on if you want to work on a real Linux box, you just have to ope n the Android terminal and run 'bootdebian'.

Now, commands for installing LXDE -
bootdebian
apt-get install xdm # this downloads ~30 MB
apt-get install lxde # this downloads ~100 MB, so you can 'take wakelock' the terminal & go for a walk

Once the apt-get completes the installations, it starts configuring the LXDE. This is the time you need your hardware keyboard (if not mouse) when it asks for some settings. Look for the place where it asks for which display manager and select 'xdm'.

Next you need to install the tightvncserver so as to create vnc session. For that, run 
apt-get install tightvncserver

Once done with that, you can start the session with these commands -
export USER=root
vncserver -geometry 1280x736 -depth 16

Above command will ask you for setting up passwords. This creates a session on localhost:1, which is a basic desktop. To start LXDE in the session, you have to instruct the vncserver using the xstartup script. For doing this, run the following commands -
vncserver -kill :1  # first kill the running session
vi /root/.vnc/xstartup

This opens the vi editor loaded with the vncserver's start up script. Edit this script such that it looks something like this -
#!/bin/sh
xrdb $HOME/.Xresources
xsetroot -solid grey
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
#/etc/X11/Xsession
startlxde

Save the file and close. Start the VNC session.

To view the session, you can either use the AndroidVNC application on your tablet or any VNC viewer on your PC.

This ends!

Sunday, March 20, 2011

Script to set the compatibility mode of executable files on Windows 7

I wanted to install the portable Ubuntu on my Windows machine, and so I downloaded the executable from the sourceforge project site and installed it.

It did not work, I initially thought I have to change the compatibility mode of the executables and set it to Windows XP SP2. There were too many files for which I had to change, so I came up with a script.

This script takes these options:
-p /--path for which you pass the path (all executable files under this path will be considered)
-m /--mode for which you pass the compatibility mode (list of valid modes given at the end of the post)
-a /--runasadmin which is a toggle option which enables/disables the "Run as Administrator" option (default: disabled)
-v /--verbose which is a toggle option which print more information (default: disabled)

The script did work :) ... but the portable Ubuntu did not :(

You can download the script from here

Don't worry to run this script on the same directory multiple times, the Windows registry takes care of duplicates by adding a file as a single entry.

List of compatibility modes (that go with --mode/ -m option):

"WIN95": "Windows 95 compatibilty mode",
"WIN98": "Windows Millennium or 98 compatibility mode",
"NT4SP5": "NT 4.0 Service Pack 5 compatibility mode",
"WIN2000": "Windows 2K compatibility mode",
"WINXPSP2": "Windows XP Service Pack 2 compatibility mode",
"WINSRV03SP1": "Windows Server 2003 SP 1 compatibility mode"

EDIT:
How to run this script on Windows... ?
Firstly, install python on your Windows machine. For installation you should download an appropriate
setup file for your Windows machine from this link, then double click the setup file and follow the on screen instructions.
Secondly, download the script from here. And here is how to run it:
Open a command terminal in Windows by hitting Windows+R keys and entering "cmd" (no quotes)
Then, navigate to the directory to which you downloaded the script (using 'cd'), when you are there
type these commands:
        python compatibility_change.py --path "c:\\path\\to\\executables" --mode WINXPSP2

Thursday, March 3, 2011

IMDB API

[UPDATE: links are update]

Here I present the module which provides APIs to get information about movies from IMDB.

This is about a Python implementation of IMDB API.

You don't have to download the IMDB's databases locally to use these APIs.

I have used Peteris Krumins' xgoogle library along with the BeautifulSoup to develop this in Python.

You may have to install the BeautifulSoup module (download from here) and xgoogle library (from here)

And here is the link for IMDB API

Here is a little bit of description about the usage:

    from pIMDB import pIMDB
    if len(sys.argv) < 2:
        print "Usage: %s " % sys.argv[0]
        sys.exit(1)
    movie = re.sub(r'[^a-zA-Z0-9\']+', ' ', sys.argv[1])
    imdb = pIMDB(movie)
    imdb.parse_imdb_page()
    print "imdb link:\n\t", imdb.imdb_link
    print "\nmovie name:\n\t", imdb.movie
    print "\nmovie rating:\n\t%s/%s" % (imdb.rating, imdb.outof)
    print "\nmovie details:\n\t%s" % '\n\t'.join(imdb.details)
    print "\nmovie storyline:\n\t%s" % imdb.storyline


It also has an API to download the poster from the IMDB website, you can use it as here:
    imdb.download_poster('/tmp/destination.jpg')

That's the end of the story :)

PS: Write a comment on how you used this module