You are not logged in.

#1 2016-01-16 22:22

Dai_trying
Member
From: UK
Registered: 2015-12-14
Posts: 2,989

Automatically upload Photo's from camera/sd card

I thought I would just give some tips on achieving this as there is currently a problem doing it although in about a month there should be a fix available, nevertheless here it is.

1. You need to create a udev rule that recognizes your camera/card specifically, Mine is shown below (make sure each rule is on ONE line only). There are many guides on using udev rules one good source is HERE.

ACTION=="add", KERNEL=="sd?1", ENV{ID_FS_UUID}=="41BC-8675", SYMLINK+="CamCard", RUN+="/usr/bin/sudo -u daa /home/dai/bin/Add_relay_script.sh"
ACTION=="remove", KERNEL=="sd?1", ENV{ID_FS_UUID}=="41BC-8675", RUN+="/usr/bin/sudo -u dai /home/dai/bin/Rem_relay_script.sh"

Save it to /etc/udev/rules.d/camcard.rules DO NOT COPY MINE EXACTLY! it will not work without changing user name and UUID of your camera/card at the very least.

You can name it something else if you want so long as it ends in .rules

Next create a directory in /media/dai/  I named mine the same as the symlink that the udev rule created, but this is up to you, and take ownership.

sudo mkdir /media/dai/CamCard
sudo chown dai:dai /media/dai/CamCard

Next edit your fstab and add the following line

/dev/CamCard    /media/dai/CamCard     auto    rw,user,noauto,sync     0       0

this will allow the user to mount the disk without root permissions.

Now onto the scripts...

Script 1
    Add_relay_script.sh

#!/bin/bash

echo "`date +%d/%m/%Y_%H:%M:%S` CamCard Inserted" >>/home/dai/CamCard.log
mount /dev/CamCard
echo /home/dai/bin/copy_card_to_Pictures | at now

You can remove the first echo statement if you wish, I just use it to keep a usage log.
You will probably need to install the "at" command, it is used to prevent blocking udev while uploads are carried out.

sudo apt-get install at

Script 2
    Rem_relay_script.sh
This script isn't really necessary I use it for logging purposes.

#!/bin/bash

echo "`date +%d/%m/%Y_%H:%M:%S` CamCard Removed" >>/home/dai/CamCard.log

Script 3
    This is the main copy script.

#!/bin/bash

export DISPLAY=:0
check_mount () {
	cat /etc/mtab | grep "CamCard" > /dev/null
	if [ $? == 0 ]; then
		return 0
	else
		return 1
	fi
}
if check_mount; then
	syncfiles=`rsync -navW /media/dai/CamCard/* /home/dai/Documents/Pictures/ | grep -i ".jpg"`
fi
if [ "${#syncfiles}" == 0 ]; then
	umount /dev/CamCard
	kdialog --title "No Files To Download" --passivepopup "You can remove the memory card now" 5
	exit 100
fi
echo "`date +%d/%m/%Y_%H:%M:%S` rsync activated" >>/home/dai/CamCard.log
rsync -avW /media/dai/CamCard/* /home/dai/Documents/Pictures/ ### Use this to keep photo's on card after uploading them
#rsync -avW --delete-source-files /media/dai/CamCard/* /home/dai/Documents/Pictures/ ### Use this to delete photo's from card after uploading them
echo "`date +%d/%m/%Y_%H:%M:%S` rsync completed" >>/home/dai/CamCard.log
umount /dev/CamCard
kdialog --title "Files Downloaded" --passivepopup "These files have been downloaded:-
$syncfiles

You can remove the memory card now" 5

All that remains now is to restart udev and make the scripts executable

sudo /etc/init.d/udev restart
chmod +x /home/dai/bin/Add_relay_script.sh /home/dai/bin/Rem_relay_script.sh /home/dai/bin/copy_card_to_Pictures

And insert your camera/card and watch it run.

This works for me, if you try it and have any problems let me know and I will try and help. Don't forget though, there is a fix in the pipeline if you have more patience than I.

Last edited by Dai_trying (2016-01-17 14:06)

Offline

#2 2016-01-17 12:53

q4osteam
Q4OS Team
Registered: 2015-12-06
Posts: 4,223
Website

Re: Automatically upload Photo's from camera/sd card

Great job Dai, thank you.

Offline

#3 2016-01-17 14:05

Dai_trying
Member
From: UK
Registered: 2015-12-14
Posts: 2,989

Re: Automatically upload Photo's from camera/sd card

You are welcome, I hope it helps someone. smile

Offline

#4 2016-01-17 15:34

CaptNoize
Member
From: Zombieland,Pa.
Registered: 2015-12-09
Posts: 264
Website

Re: Automatically upload Photo's from camera/sd card

Dai
Is this how I would set up my Logitech camera...? I have a Logitech Click smart 510 which doubles as a webcam.Would this work with it..?

Offline

#5 2016-01-17 16:25

Dai_trying
Member
From: UK
Registered: 2015-12-14
Posts: 2,989

Re: Automatically upload Photo's from camera/sd card

I think so, but a few things to check first would be how the camera is recognized by the os, If it sees it as a disc then i should. Bear in mind that what my scripts do is just copy (using rsync) the photographs found on the disc/usb stick/camera to your Pictures directory. If you need help identifying what you can do, type into a console (after connecting camera)

lsusb

to see what usb devices are attached and then if one is a disc type device type

sudo blkid

to get the UUID of the device to use with my scripts.
If you need any more help just ask smile

Dai

Offline

Board footer

Powered by FluxBB