Bronwyn has recently become interested in computers – in particular, using them to communicate her interests to others with her hobbies.
In order to help her, I am trying to make things as simple as possible on this computer. That’s a damned pain, sometimes.
I am currently running Mandrake 10 on this machine, with a custom kernel. Mandrake comes with a patch to the kernel which makes automatic mounting for cameras a cinch, but the kernel I built does not.
So, I needed to build an automatic script for getting photos from the camera to the computer.
The following script is a modified version of Kevin Lyda’s mounting script. It loads your camera and dumps the contents to a directory on your KDE desktop. The directory is named with the date and time, so is unique, assuming you don’t mount and remount within seconds.
To use, create a /mnt/sda1 directory and place the following code in your /etc/hotplug/usb/usb-storage file:
#!/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 '07' > /dev/console; sleep 1
echo -e '07' > /dev/console; sleep 1
echo -e '07' > /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"
Comments