April 2008 Archives

Apr 19 2008

check if a directory is empty in bash

Posted in programming; by Miek Gieben; comments: 0

I had this small problem, how to you check if a directory is empty in the shell? Suppose I want to do

cmd po/*

this fails, if the po directory is empty, which in turn makes my compile barf, but that is another story. I needed something to would check the emptiness of the directory, and if it is not empty perform the command, otherwise it skip it.

The trick here is to remember that if a shell wildcard can not be expanded it will be left alone. So an unexpanded * will stay a *.

Thus

if [ po/* = "po/*" ]; then 
    echo empty
else
    echo loaded
fi

will check if a directory is empty. This can also be folded into one line

[ po/* = "po/*" ] || cmd po/*

UPDATE Jaap Akkerhuis reminded me that this (ofcourse) fails with hidden files as those are not expanded by *. This could be fixes by also checking for .*


Apr 18 2008

Playing music on the EeePC with a SD disk and mpd and gmpc/mpc

Posted in eeepc; by Miek Gieben; comments: 0

I've installed DebianEeepc as per this howto. And then did a apt-get install mpd gmpc mpc for my music.

suspend script

I want my suspend to work, but every time I suspended xfdesktop crashed. Turns out this is due to the stopping of dbus. I've modified the suspend script to not meddle with dbus. This seemed to have fixed this particular issue. I've also added an:

fuser -k /media/disk    # kill all users of /media/disk
umount /dev/sdb1        # now it can be umounted

to the script. This unmounts the disk on suspend. I'm now letting xfdesktop (re)mount /dev/sdb1 on resume. This works fine.

mpd

Install mpd, and make a symlink from /var/lib/mpd/music to /media/disk/music. /media/disk is the spot where the SD disk is mounted by xfdesktop.

The problem with mpd is that is will not start if it cannot find its music directory. With this symlink trick, this directory is always there even if the mounting of /dev/sdb1 went wrong.

Also modify /etc/mpd.conf to comment out bind_to_address by putting a # in front of that line. Next restart mpd: /etc/init.d/mpd restart

mpc

mpc rocks. Actually I only need gmpc to load the playlist in mpd. From then on I use mpc: mpc next, mpc play, etc. Real easy from the cmdline; mpc update also rocks.

Now I just plugin my headset, start the music and start compiling and writing software in the train.

The EeePC really rocks!


Apr 17 2008

I can talk Dutch now!

Posted in rdup, news; by Miek Gieben; comments: 0

Finally I figured it out! I've added i18n to rdup. I'm using GNU's gettext for this, but I'm slowly understanding how things work.

In English: (duh)

% LANGUAGE=en_EN ./bin/rdup blaat ~/bin
...
** rdup: Could not write filelist `blaat': Permission denied

In Dutch:

% LANGUAGE=nl_NL ./bin/rdup blaat ~/bin         
...
** rdup: Kan bestandenlijst niet schrijven `blaat`: Toegang geweigerd

Yes! :-)

I also need to tweak the Perl utilities to talk other languages and to tweak the configure.ac to still make it compile on systems without GNU's gettext.


Apr 12 2008

battery shell script for the EeePC

Posted in eeepc, linux; by Miek Gieben; comments: 0

The battery applet from xfce is a bit flaky, so I've written a shell scriptlet that will calculate the remaining capacity in the battery.

I'm using zsh here, but this script will work in any shell. I'm putting the output of the script on the right side of my prompt in a subdewed grey color. It adds a + on the right when it is charging.

script

#!/bin/zsh
dc=$(cat /proc/acpi/battery/BAT0/info | grep 'last full' | awk ' { print $4 }')
rc=$(cat /proc/acpi/battery/BAT0/state | grep 'remaining' | awk ' { print $3 } ')

p=$(echo 3k $rc $dc / 100 \* p | dc ) 
if grep -q discharging /proc/acpi/battery/BAT0/state; then
    printf "%02d" "$p"
else
    printf "%02d+" "$p"
fi

xbattbar-acpi

xbattbar-acpi is Anothor tool you will need. It will display a small bar at the bottom of your (X) screen, showing the remaining capacity. It keeps out of your way, uses only 3 pixels and works just like the script above.


Apr 11 2008

EeePC there!

Posted in news, linux; by Miek Gieben; comments: 0

I'm finally the owner of a Asus EeePC! It looks great, its light and it runs Linux.

I'm currently installing DebianEeePC to see how that works. I messed up the Xandros by renaming the defaullt username user to miekg, this sorta made X fail to start. Ahh well, this was only after 3 hours after I got it :-)

I think XFCE is the best interface for this machine. With Terminal and zsh I'm as happy as I can be.


Apr 06 2008

Buran Passage

Posted in news, life; by Miek Gieben; comments: 0

The Buran Spaceshuttle is passing by Nijmegen today. I was at the river side and made a few pictures.

The Buran on its transport vessel:

It is actually docking here!


Apr 02 2008

Playing a nice game of chess

Posted in life, linux; by Miek Gieben; comments: 0

I was just fiddling a bit with glchess under Ubuntu. I was playing against the computer. Something caught my eye, so I pressed help.

Next thing I know - the other player dies!

GLChess shot


Apr 01 2008

Ubuntu 8.04 (beta)

Posted in linux; by Miek Gieben; comments: 0

Hmmpf, those Ubuntu guys are good. If just finished a painless upgrade to the new Ubuntu: Hardy Heron.

Some subtile differences; better Gnome (new metacity with composer). And some other stuff that I'm discovering right now. :-)