[ILUG] mounting a camera to the desktop

Kae Verens kae at verens.com
Sat Sep 18 08:57:17 IST 2004


Here's an adaptation of Kevin's camera mounting script, which creates a 
unique (ish) directory on your desktop and dumps the files there.

Blogged here: 
http://verens.com/archives/2004/09/17/automatically-dumping-your-camera-contents-to-the-desktop/

Assumes you use KDE, and have a /mnt/sda1 directory. Adapt as needed.

#!/bin/sh

logger -t usb-storage "Starting"

case x"$ACTION" in

     xadd)
         # from usb/usbcam
         # new code, using GNU style parameters
         if [ -f /var/run/console.lock ]; then
             CONSOLEOWNER=`cat /var/run/console.lock`
         elif [ -f /var/lock/console.lock ]; then
             CONSOLEOWNER=`cat /var/lock/console.lock`
         else
             logger -t usb-storage No console owner found
             exit
         fi

         logger -t usb-storage "Mounting camera"
         mount -t vfat /dev/sda1 /mnt/sda1
         logger -t usb-storage "Camera mounted, copying files"

         # generate a unique-ish directory
         suffix=$(date +%Y.%m.%d-%H.%M)
         prefix="camera_"
         NEWDIR=$prefix$suffix

         mkdir /home/$CONSOLEOWNER/Desktop/$NEWDIR -p
         find /mnt/sda1/dcim -type f -print0 | xargs -0i mv '{}' 
/home/$CONSOLEOWNER/Desktop/$NEWDIR
         chown $CONSOLEOWNER.$CONSOLEOWNER 
/home/$CONSOLEOWNER/Desktop/$NEWDIR -R
         umount /mnt/sda1

         echo -e '\007' > /dev/console; sleep 1
         echo -e '\007' > /dev/console; sleep 1
         echo -e '\007' > /dev/console

         test -d /var/run/usb || mkdir /var/run/usb
         ( echo '#!/bin/sh' ; echo rmmod usb-storage ) > $REMOVER
         chmod 755 $REMOVER
         ;;

esac

logger -t usb-storage "Finishing"



More information about the ILUG mailing list