I'm not quite sure if this problem lies in gphoto2, canon firmware,
linux-usb, or my misconfig....  I am completely stumped and I hope
someone can shed some light on this.

I have a Canon A530.  I've written some udev rules to automagically
download the camera on plug in.

The rules are:

# udev rules file for my_cameras

ACTION!="add", GOTO="cameras_rules_end"
SUBSYSTEM=="usb_device", GOTO="cameras_rules_real"
SUBSYSTEM=="usb", GOTO="cameras_rules_real"
BUS=="scsi", GOTO="cameras_rules_mass"

LABEL="cameras_rules_real"

#Nikon D50 USB mass storage device

SYSFS{product}=="Canon Digital Camera", SYSFS{manufacturer}=="Canon
Inc.", MODE="0660", GROUP="plugdev", ENV{camera}="Canon_A530",
ENV{type}="ptp", SYMLINK+="camera/Canon_A530",
RUN+="/usr/local/bin/download_camera", OPTIONS+="last_rule"

GOTO="cameras_rules_end"

LABEL="cameras_rules_mass"

SYSFS{model}=="D50             ", SYSFS{vendor}=="NIKON   ",
MODE="0660", GROUP="plugdev", ENV{camera}="Nikon_D50",
ENV{type}="mass_storage", SYMLINK+="camera/Nikon_D50",
RUN+="/usr/local/bin/download_camera", OPTIONS+="last_rule"

LABEL="cameras_rules_end"

Now those work; the camera is detected and the download script is executed.

The problem is that it is executed 4 times, then a pause, then one more
time, and all fail.

Now, if, after that, I run gphoto2 --list-files from the command line,
the script is executed again in the same 4 and one pattern, and the
download goes through.

My script is twofold:

The rules invoke the download_camera script, which in turns calls the
following script:

#!/bin/sh

logger $$ downloading $type camera $camera

sleep 15

logger $$ done sleeping

case $type in
"mass_storage" )
        dest_dir=/home/nfs/pictures/$camera/`date +%Y-%m-%d_%H.%M`
        mkdir -p $dest_dir
    mkdir -p /mnt/${camera}
    mount /dev/camera/${camera} /mnt/$camera
        files=`find /mnt/${camera} -name "*.[Jj][Pp][Gg]"`
        for file in $files ; do mv $file $dest_dir ; done
        ;;
"ptp" ) #we can only do this in chunks of 20
    logger $$ getting files off ptp camera $camera
        dest_dir=/home/nfs/pictures/$camera/`date +%Y-%m-%d_%H.%M`
        mkdir -p $dest_dir
    cd $dest_dir
    logger $$ iter
    iter=$(( `gphoto2 --debug --list-files | grep -c ^# ` / 10))
    if [[ $? != 0 ]] ; then exit 1 ; fi
    logger $$ rem
    rem=$(( `gphoto2 --list-files | grep -c ^# ` % 10))
    if [[ $? != 0 ]] ; then exit 1 ; fi
    logger $$ for
    for (( idx=1 ; $? == 0 && idx <= $(($iter*10)); idx+=10 )) ; do
        echo getting files $idx-$(($idx+9))
        gphoto2 --get-file $idx-$(($idx+9)) --force-overwrite \
        && gphoto2 --delete-file $idx-$(($idx+9)) --recurse \


#        || exit 1
    done
    gphoto2 --get-file $idx-$(($idx+$rem-1)) --force-overwrite \
    && gphoto2 --delete-file $idx-$(($idx+$rem-1)) --recurse
    ;;
esac

Here's a typical run:

Jan 28 18:27:32 dionysus kernel: usb 5-8: new high speed USB device
using ehci_
cd and address 39
Jan 28 18:27:32 dionysus kernel: usb 5-8: configuration #1 chosen from 1
choice
Jan 28 18:27:32 dionysus logger: 30808 got ptp camera Canon_A530
Jan 28 18:27:32 dionysus logger: 30811 downloading ptp camera Canon_A530
Jan 28 18:27:32 dionysus logger: 30819 got ptp camera Canon_A530
Jan 28 18:27:32 dionysus logger: 30821 downloading ptp camera Canon_A530
Jan 28 18:27:32 dionysus logger: 30818 got ptp camera Canon_A530
Jan 28 18:27:32 dionysus logger: 30825 downloading ptp camera Canon_A530
Jan 28 18:27:32 dionysus logger: 30817 got ptp camera Canon_A530
Jan 28 18:27:32 dionysus logger: 30829 downloading ptp camera Canon_A530
Jan 28 18:27:47 dionysus logger: 30811 done sleeping
Jan 28 18:27:47 dionysus logger: 30811 getting files off ptp camera
Canon_A530
Jan 28 18:27:47 dionysus logger: 30811 iter
Jan 28 18:27:47 dionysus logger: 30821 done sleeping
Jan 28 18:27:47 dionysus logger: 30821 getting files off ptp camera
Canon_A530
Jan 28 18:27:47 dionysus logger: 30821 iter
Jan 28 18:27:47 dionysus logger: 30825 done sleeping
Jan 28 18:27:47 dionysus logger: 30829 done sleeping
Jan 28 18:27:47 dionysus logger: 30829 getting files off ptp camera
Canon_A530
Jan 28 18:27:47 dionysus logger: 30829 iter
Jan 28 18:27:48 dionysus logger: 30808 exit status 1
Jan 28 18:27:48 dionysus logger: 30825 getting files off ptp camera
Canon_A530
Jan 28 18:27:48 dionysus logger: 30825 iter
Jan 28 18:27:48 dionysus logger: 30819 exit status 1
Jan 28 18:27:48 dionysus logger: 30817 exit status 1



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Linux-usb-users@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-users

Reply via email to