#!/bin/bash # Have less pain with your digital camera or similar usb device ! # This script will mount it, move or copy ('k' argument) files it # contains to current directory and unmount it. # Version 1.0, 17 March 2004. Version 1.1 09 January 2005. # Originally written by Barbara Post, under the terms of GPL. (http://www.gnu.org). # configuration DEVICE=/dev/sda1 MOUNTPOINT=/sony FILES=/dcim/101msdcf LOG=~/digicam.log export DEVICE MOUNTPOINT FILES LOG # usage and error messages function usage { case $1 in 1) echo "Mount point $MOUNTPOINT doesn't exist !" exit 1 ;; 2) echo "No corresponding line found in /etc/fstab, you must add it to be able to mount as non-root\ and this should look like :" echo "$DEVICE $MOUNTPOINT auto user,noauto 0 0" exit 2 ;; 3) echo "Current directory is not writable !" exit 3 ;; 4) echo "Problem when copying files" umountit showlog exit 4 ;; 5) echo "Problem encountered when deleting files from device $DEVICE" umountit showlog exit 5 ;; 6) echo "$DEVICE not found, not plugged in ?" showlog exit 6 ;; 7) echo "No files found in $MOUNTPOINT$FILES/" umountit showlog exit 7 ;; 8) echo "Problem unmounting $DEVICE" showlog exit 8 ;; 9) echo "Cannot write log file to ~/digicam.log" ;; 10) echo "No corresponding line found in /etc/fstab, you must add it \ and this should look like :" echo "$DEVICE $MOUNTPOINT auto user,noauto 0 0" showlog exit 10 ;; esac echo "Moves the content of your digital camera to current directory" echo "Current configuration: device is $DEVICE, mount point is $MOUNTPOINT and path \ to pictures in camera is $FILES" echo "Pass 'k' argument to keep files on device" exit 0 } function showlog { echo " ** Log details ** " echo "`cat $LOG`" rmlog } function umountit { echo "unmouting $DEVICE" umount $MOUNTPOINT 2>>$LOG } function rmlog { if [ -s $LOG ]; then # echo "deleting log" rm -f $LOG fi; } # let's do the fun part if [ -z '$1' ]; then usage $1 fi echo `date` >$LOG if [ $? -ne '0' ]; then usage 9 fi if [ ! -w . ]; then usage 3 fi if [ ! -d "$MOUNTPOINT" ]; then usage 1 fi echo "Mounting $MOUNTPOINT" mount $MOUNTPOINT 2>>$LOG case $? in 1) usage 10 ;; 32) usage 6 ;; 0) echo "Successfully mounted device $DEVICE" ;; esac ls "$MOUNTPOINT$FILES"/* 2>>$LOG if [ $? -eq '1' ]; then usage 7 fi echo "Copying files to current directory..." cp -p "$MOUNTPOINT$FILES"/* . 2>>$LOG if [ $? -ne '0' ]; then usage 4 fi if [ -z '$1' ]; then if [ "$1" != "k" ]; then echo "Deleting files from device" rm -f "$MOUNTPOINT$FILES"/* 2>>$LOG if [ $? -ne '0' ]; then usage 5 fi fi else echo "Deleting files from device" rm -f "$MOUNTPOINT$FILES"/* 2>>$LOG if [ $? -ne '0' ]; then usage 5 fi fi umountit rmlog echo "Done"