date hack

The computers at our institute don’t have NTP installed, and the time
is rarely synchronized. The date on the computer I am writing this post
on is about half an hour behind. So here’s how you can get the correct
date from the terminal using wget, sed and the good ol’ date:

# Prints the date.

x="$(wget -q -O - | grep UTC | cut -c 5- | sed s/\,//g)"
date -d "${x}"

Put this file somewhere in your $PATH, make it executable and run it. It’ll print the
date in the local timezone. Here’s how it works:

  1. It gets the date from and dumps it on the
  2. It gets the first line in UTC using grep
  3. It cuts out the
  4. and removes the comma which causes date to choke
  5. Finally date -d converts the date into the local timezone and displays it.

I’ve this script running with watch -n 5 to give the date every five seconds in the terminal.


multimedia keys

In Linux, multimedia keys have always been a bit difficult to configure. Sure,
there are third party programs which help, but there’s an easier, more
fundamental way, using xmodmap. What xmodmap does it remap the
keys and give them corresponding X identifiers. For example, this is
how my ~/.xmodmap file looks like:

! This works with Trust Silverline Direct Access keyboard
! Use ! for comments

keycode 222 = XF86PowerOff
keycode 223 = XF86Sleep
keycode 236 = XF86Mail
keycode 229 = XF86Search
keycode 230 = XF86Favorites
keycode 178 = XF86WWW

keycode 162 = XF86AudioPlay
keycode 164 = XF86AudioStop
keycode 160 = XF86AudioMute
keycode 144 = XF86AudioPrev
keycode 153 = XF86AudioNext
keycode 176 = XF86AudioRaiseVolume
keycode 174 = XF86AudioLowerVolume

As you can see, the various keycodes have been assigned to the X key
symbols; this enables whichever window manager you use to understand
the keysym. Now you can associate the keysyms with commands, etc. In
Arch a list of keysyms is at /usr/share/X11/XKeysymDB. To apply
these settings simply run xmodmap ~/.xmodmap

multimedia keys control whichever application is active

There are many programs which do not natively support the multimedia
keys, for example the Totem media player. Also you can bind only one
command to be the keybinding for the keysym. So I have made a small
script in bash which detects the active window, and depending on what
window it is, gives the appropriate commands. For example, the script
for the play key is:

# Program to start playing in whichever application
# is the focussed one.

# Abhishek Dasgupta 
# get focussed window id
focus=`xdpyinfo | grep focus | cut -c 16-24`
# grab WM_CLASS
info=`xprop -id $focus | grep WM_CLASS | cut -c 20-`

if [[ "$info" =~ .*Audacious.* ]]
  audacious --play
elif [[ "$info" =~ .*Totem.* ]]
  totem --play
  mpc play

You can grab the full set of scripts:

Currently, as you see the scripts support audacious, totem and mpc.

Arch setup II

So onto part II.

There are a few important things that one needs to remember when configuring Arch – one is that most of the configuration is done through plain old text files; no clumsy or hand-holding GUIs here to help you out. Secondly, most of the configuration files in Arch are in exactly the same place where you would expect them to, i.e. Arch interferes very little with /etc allowing programs to place the files there, without moving them to a special place. Most distributions keep a special system for managing configuration files, Debian has debconf, Gentoo has etc-update, Arch has none, and it needs none. When a configuration file is to be overwritten, Arch will give you a warning; if it does not you can be sure that it’ll not overwrite and instead the new config will be placed with a .pacnew extension.

I am a bit of a console freak, so first off I installed gpm. GPM is this really cool
program which allows you to use the mouse in the console. I did need to a do a bit of tweaking in /etc/conf.d/gpm and I added this line:
GPM_ARGS="-m /dev/input/mice -t imps2"

(other great console apps: irssi, centericq, and of course mutt!)

Another good thing that I like about Arch is its bleeding edge packages. The magic command
to sync up on the newest stuff is pacman -Syu. Also I made sure to install the latest version of pacman (version 3.0.4 as of writing). It seems a bit faster, the progressbar for installing also looks neater; of course there are lot of changes underhood too. The other good news for those wanting to try out Arch for the first time – they’ll release a 2007-05 version (codename Duke) soon with the new kernel 2.6.21. So wait a few days and download that instead of 0.8!

Then I installed slim (the simple login manager) and beryl, compositor-king. In Arch if you know the name of a package, then you can install it with pacman -S package. If you don’t sync frequently you can also tag a -y to it like pacman -Sy package. That’ll make sure you get the repositories refreshed with the changes (-y stands for refresh). You can also search for a package by this package -Ss whatever.

Arch has a few repositories. To put simply, a repository is a collection of binary packages maintained by Arch developers, or other members of the community. The official repositories are current, extra, unstable, testing, community. Out of these current and extra contain stable packages. testing contains the absolutely new stuff, and one that could (but never has, in my case) break your system (like say, a new kernel version or a new video graphics driver). unstable contains, well unstable code. I don’t use it and it doesn’t contain many packages anyway. community is a repo of software that users wrote PKGBUILDs for (I’ll be coming to what PKGBUILDs are, soon) and they have been voted or are important enough, that binary packages are provided for a few of them. (Did you know, that
anyone can upload packages to the Archlinux User Repository?)

If you want to enable some of those repositories, go to /etc/pacman.conf and uncomment out the repos you need, you can also add other repos if you want.

Installing stuff is a no-brainer as I told before. I quickly installed openoffice-base, pidgin, seahorse (manages GPG keys), muttng (grabbed a few configs from codemac, thanks codemac!), screen (the wonderful terminal multiplexer), nitrogen (a wallpaper setter), alunn (excellent notifier for new packages, quietly sits in systray), totem movie player, VLC, etc….

Now onto configuring NetworkManager. First I had to install the required packages (networkamanger and gnome-network-manager if you use GTK+/GNOME or knetworkmanager if you use KDE). Then you have to go to rc.conf and disable the interfaces which we want to use. You must also remember that your wireless card uses a different interface than your ethernet port. That you have to find out by trial-and-error. In my case it was eth2. So in my rc.conf, I now have:

  eth0="dhcp" #if you don't want dhcp put something like this:
  #eth0="eth0 netmask" where the first address is the IP you want
  INTERFACES=(lo !eth0 !eth2)
  # Routes to start at boot-up (in this order)
  # Declare each route then list in ROUTES
  #   - prefix an entry in ROUTES with a ! to disable it
  gateway="default gw"

Then you need to install the appropriate drivers for your wireless card (if you haven’t done so already). My card is a Intel IPW3945ABG so I installed the ipw3945 package. For this driver, I also need to startup the ipw9345 daemon, so I added to the DAEMONS array. While using networkmanager, we have to disable the network script, so put a ! before it and also add dhcdbd and networkmanager to the DAEMONS array. Next time you reboot, NetworkManager will take over your network settings from rc.conf. So now my DAEMONS array looks like this:

  DAEMONS=(syslog-ng ipw3945d !network alsa dbus hal @powersaved @mpd dhcdbd netwo
  rkmanager @lastfmsubmitd @lastmp @netfs vsftpd crond slim)

(the @ before some daemons means that daemon will be started in the background)

To use the GNOME applet, you can put nm-applet --sm-disable in your .xinitrc or whatever system your DE uses to autostart apps on login. The reason --sm-disable is required is that otherwise nm-applet gets confused and multiple instances of it startup 😦

Lastly I configured mpd. For anyone who does not know, mpd is a daemon which plays your music in the background. So even if you kill X, your music goes on. There are many good frontends for it; I prefer Sonata which supports editing tags too.

Next time, I will write about how drop dead simple it is to make your own packages in Archlinux. Have a look at the wiki; and till next time happy pacman -Syu’ing!

Arch setup I

It’s been a long time in the coming, true. Due to a lot of stuff in real life, I haven’t been to blog properly. In some ways this is better, as it’s now a month with Arch, and I have a better understanding of it.

So after I booted off the CD (Version 0.8), I got few screenfuls of text, with the livecd checking for binary packages in every removable medium it could find. It seems that arch will allow you to install any package that’s in the /packages directory of some removable media. Then /arch/setup brought me to the installation screen.
That gave me the choices like Partition, Set Mountpoints, Install packages, Install Kernel, Configure System Install Bootloader and Reboot. My hard disk was already partitioned, so there was no problem. I went straightway to set the mountpoints (in my cases just / and /home).

Since I had downloaded the full version of the CD, I had to wade through a lot of packages to finally settle for what I liked. Installing was finished in a jiffy, and then I had to configure the system. I did not touch /etc/modprobe.conf and /etc/modules.conf. /etc/rc.conf is the master configuration file in Arch, having settings for everything from timezone, to what modules are loaded at startup, what daemons are started, etc. The comments are self-explanatory.

Installing the kernel and the bootloader was straightforward. I installed GRUB to the MBR (master boot record) and rebooted.

Then I copied my xorg.conf from my Gentoo install to here. I installed openbox, trayer and a few other applications (like gaim – now pidgin), put them in my .xinitrc
and startx’d.

Since I installed XFCE, which is nowadays heavily dependent on HAL, I remembered to
add hal and dbus to the DAEMONS array in /etc/rc.conf. Also be sure to
add yourself to the storage, optical, video, audio and power groups, otherwise you won’t get a wholesome experience.

I’ll put some more details on how I configured NetworkManager, and how I started
building packages for arch in a later post. What I like about Arch, is its beautiful simplicity. That kind of simplicity really opens your mind up to new possibilities, that’s probably why we have a lot of cool things discussed in the forums; nice and
simple, the kind of tools that make you feel warm and cozy.

Till next time – enjoy the beautiful world of open source!

Arch lands

… on my laptop. Well Arch Linux 0.8 (Voodoo) came out on March 31, and I have been itching to try it out. So one fine morning, I booted with my new Arch install CD (full version) and wiped out my beloved Gentoo. Now after a day of using it, I’m definitely impressed.
Soon, I’ll write a detailed post on how I set up my Arch box, but the main points I liked about this new Arch release, is the installer, which has gotten a lot better, and now includes dynamically loading packages from removable media you have attached while the installation CD is in the drive, and of course Arch’s simplicity.
Long live Arch and keep it simple stupid! 🙂

i915 problems.

Well, this week I tried to install Gentoo on a friend’s Lenovo laptop, replacing his Ubuntu. All went well (Recompiled with glibc 2.5-r1, etc.). Xorg compiled fine too. But while starting, it gives this cryptic error and cops out:
(EE) I810: unknown type(0xffffffff)=0xff

I searched high and low on googlespace for the answer. The only satisfactory solution (sort of) was the one I got from Greg’s page here. He talks of enabling VM86 in the kernel. Unfortunately in the latest kernel, there’s no option that I can find for VM86. Does anyone know why VM86 was dropped in 2.6.19? Next time, I catch hold of his laptop, I’ll install 2.6.18 and see what comes of it.

Wheee! Huawei CDMA works in Gentoo!

Thanks to trichotillomania for the configuration settings 🙂

Well according to that blog, I should have got wvdial and configured it. Unfortunately wvstreams (on which wvdial depends) bombed out on me during the compilation :-(. Also, I didn’t use his method of modprobing everytime. I just went into the kernel configuration -> Device Drivers -> USB Support -> USB Serial Convertor Support, and ticked off USB Serial Console Device Support, USB Generic Serial Driver, and of course USB driver for GSM and CDMA modems 🙂 to be compiled into the kernel. So whenever I plug the modem in, auto-detection magic 🙂 No fuss. No scripts.

Then since wvdial didn’t work (didn’t compile) so I set off to use Gentoo’s recommended way: /etc/conf.d/net
I edited that file, put in a few settings (after reading their excellent documentation) and this is what I ended up with:

#[snippet only]
"modem crtscts"
# you can add more here: just look at /etc/conf.d/net.example!
'ABORT' 'Invalid Login'
'ABORT' 'Login incorrect'
'' 'ATZ'
'OK' 'AT' # Put your modem initialization string here
'TIMEOUT' '60'
'~--' ''
# ^ blatantly copied from /etc/conf.d/net.example!

Thanks to all the people that have made GNU/Linux such a smashing success! Nowadays, linux support is so great, I really wonder why people use Windows at all. And Gentoo docs are of course unparalleled and unrivalled 🙂