Skip to main content

Fri Apr 23, 2004 10:15 PM

Poked around with Linux Hotplug both last night and some today. It doesn't seem to be very easy to debug and you would think that it could be setup by default to handle many of the common things you would want to do with it. For example, I wanted to have it so I could attach my new camera via USB cable, press the USB button on the cradle and have it copy all the pictures off it, optionally delete them, and disconnect. By default hotplug will see the camera, load the scsi disk driver and say that it's /dev/sda1, and thats it.

In order to get it all working as I wanted, I had to setup 2 scripts. First of all I made a /etc/hotplug/usb/usb-storage script. This script (which didn't exist before I made it) is called by the /etc/hotplug/usb.agent when a "usb storage" device connects. The /etc/hotplug/usb/usb-storage script gets passed a number of things in env variables. If the $ACTION variable is "add" then the device is connecting. I have the script look for that and then mount the camera on /mnt/camera and run the second script. Also, and this took me a while to figure out, I had to run a link from the file refered to in $REMOVER back to the /etc/hotplug/usb/usb-storage script. $REMOVER is run when the device disconnects. The usb-storage script then catches a $ACTION of "remove" and umounts the /mnt/camera.

The second script is just a simple script that copies the files off the camera device and runs a program called jhead which can manipulate the EXIF headers that most digital cameras put in images. In this case I have jhead rewrite the filename of the image to YYYYMMDDHHMMSS.jpg. Then the script deletes all the files from the camera (since they have now been copied over to the laptop drive).

Using this setup I have been able to have a pretty quick turnaround on pictures, which is nice. Here's some sample ones from yesterday and today: Yet more dog pictures.