13 July 2008

automounting

To be concise, automounting of removable media in Linux hurts.

SkinnyDebbie's first release has been held up by issues surrounding automounting. Getting automounting to sorta work is easy. Getting it to be reliable and usable is another story. I think I've finally gotten things figured out to the point where the system is sufficiently usable and reliable. But I would like to make sure that there are no gremlins hiding in the works. When mountpoints go bad, the results can be fairly ugly.

I also want to add a bit of UI sweetness to the automounting deal: I'd like the the appropriate folder to open in the file manager when the media is mounted to let the user know that the media has, in fact, been mounted. This shouldn't be too tough -- but then that's what I thought about automounting in general.

One annoying thing: Linux does not consider audio CDs and video DVDs mountable media. That means that you literally cannot mount either of these kinds of discs and browse their files on the command line or in your file manager. This doesn't mean you can't open discs in applications designed to read from them (e.g., VLC, Xine, Audacious); it just means that you can't ls, mv, cp, etc. the files on the discs. In theory, it's possible to set things up so that when you insert, say, an audio CD, an application that can read audio CDs will launch and open the CD in the application.

I'm dithering on whether this is a good idea or not. It's a good idea because it makes the life of the end user easier. But it's a bad idea because the application the system designer thinks is best for reading CDs or DVDs may not be the application the user prefers to use. In this case, the psuedo-automount is just a nuisance to the user. As near as I can tell, configuring what application is associated with CD/DVD media isn't that easy either.

Like I said, it hurts.

02 July 2008

An inadyn wrapper

Inadyn is a lightweight command-line tool for updating dynamic DNS addreses. Its use is supported by DynDNS, FreeDNS, and others. Binaries are available for Windows and Linux, and Debian and Ubuntu both have inadyn packages. Overall it seems like a good choice for a dynamic DNS update client.

In Linux, administrators usually set inadyn up to run as a daemon. But for regular desktop use this might present some problems. Most notably, if a network connection is not available when inadyn starts, it just exits. Another problem is that setting up a daemon can be a little scary for new users.

So I came up with a little script that can be run at login that launches inadyn not as a daemon but as a regular process. If the process is already running, it will warn the user. If the process didn't start, it will warn the user. If everything goes ok, it lets the process run and quietly retires.

You will have to hand-edit the 'inadynOptions' variable below to make it suit your needs. The whole thing looks like (you may need to copy/paste the text into a text editor if the left margins are cropped):
#! /bin/bash
# (c) 2008 Mithat Konar
# 2008-07-25

# Try to start an inadyn process. If it starts and doesn't quit right away
# (perhaps because the network isn't available) exit the script leaving the
# inadyn process running. Otherwise, prompt the user that it's not running
# and give the user the chance to try again or quit.

# Requires zenity

# =========
# constants
# =========
# use absolute paths only ... relative paths and env variables not tested! really!!
inadynOptions="--input_file /home/mithat/.inadyn/inadynAfraid.conf" # options to pass to inadyn

timeBetweenTries=20s   # time between attempts to restart the process

# ==========
# UI strings
# ==========

uiAlreadyRunningTitle="Inadyn already running?"
uiAlreadyRunning="It looks as though
inadyn $inadynOptions
is already running.

Shall I force it to start anyway?"

uiNotRunningTitle="Inadyn not running"
uiNotRunning="Inadyn isn't running, possibly becuase the network isn't up.

Try again?"

# =========
# functions
# =========

# tryToStart() will try to start the process "inadyn $inadynOptions"
# it does not check to see if the process is running
# requres global variables 'timeBetweenTries' and 'inadynOptions'.
# writes the PID of the process to global variable 'PID'.
# if startup was successful, sets global variable 'isRunning' to
# process information, otherwise isRunning will be blank.
function tryToStart()
{
/usr/sbin/inadyn $inadynOptions &   # try to start it
PID=$!     # capture the process ID
sleep $timeBetweenTries   # give it some time
isRunning=`ps aux | grep "inadyn $inadynOptions" | grep "$PID" | grep -v grep` # check
}

# ======
# "main"
# ======

isRunning=`ps aux | grep "inadyn $inadynOptions" | grep -v grep`
if [ -n "$isRunning" ] ; then
zenity --question --title "$uiAlreadyRunningTitle" --text "$uiAlreadyRunning"
if [ $? -eq 1 ] ; then
echo -e "$0: User cancelled"
exit 1
fi
fi

tryToStart    # try to start the process

while [ -z "$isRunning" ] ; do  # while the process isn't running ...
zenity --question --title "$uiNotRunningTitle" --text "$uiNotRunning"
if [ $? -eq 1 ] ; then
echo -e "$0: User cancelled"
exit 1
fi
tryToStart   # try to start the process
done

Be sure to set the file in which you save the script to be executable (using chmod or your file manager).

You will also need to make /usr/sbin/inadyn executable by regular users. In a terminal:
sudo chmod u+s /usr/sbin/inadyn

To start the script in Xfce, open "Autostarted apps" and add an entry for
bash -c "<path to the script>"

To start the script in IceWM, add
bash -c "<path to the script>" &
to your ~/.icewm/startup file (don't forget the & at the end of the line!). Adding just
<path to the script> &
seems to work as well.