Created
February 18, 2022 04:05
-
-
Save buzztiaan/3991ae8b31ae942304a054bfd6e88f9e to your computer and use it in GitHub Desktop.
script to copy files from a PTP or massstorage camera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# docamera.sh , 2004 | |
# [email protected] http://buzz.spacedout.nl/ | |
# quite easy script to mount yr camera , download all pictures , upload them to yr gallery and archive them locally | |
# also implements a 'cache' for offline times ;) | |
# wrote this for galleryadd.pl ( http://jpmullan.com/galleryupdates/other/galleryadd.pl ) | |
# - homedir , archivedir , cachedir are all hardcoded , you can easily change this | |
# ( not really anymore , but a little ) | |
# - you'll need a /mnt/camera mountpoint in yr fstab , and you probably want to be able to mount this as user :D | |
# ( gphoto2 support somewhere ;) ) | |
# - gallery 1.3.4+ afaik | |
# CONFIGURATION : | |
GALLERY="http://example.com/gallery" | |
GALLERYUSER="user" | |
GALLERYPASS="pass" | |
GALLERYALBUM="album" | |
# set this to "gphoto2" or "usb" | |
CAMERA="gphoto2" | |
CACHEDIR="/home/buzz/images_tmp" | |
ARCHIVEDIR="/home/buzz/images" | |
USBMOUNTPOINT="/mnt/camera" | |
# ############################################################## | |
# CONFIGABLE STUFF ENDS HERE , but you are welcome to continue | |
# ############################################################## | |
mkdir -p $CACHEDIR | |
mkdir -p $ARCHIVEDIR | |
case "$CAMERA" in | |
"usb") | |
echo "Searching mass storage drive camera on $USBMOUNTPOINT..." | |
mount $USBMOUNTPOINT &> /dev/null | |
if [ "$?" -eq "32" ]; then | |
echo "! Camera not connected , not grabbing new images" | |
else | |
echo "Camera mounted..." | |
echo "Copying pictures from camera..." | |
cd $USBMOUNTPOINT | |
find . -iregex .*jp.* -exec mv {} $CACHEDIR \; | |
cd - | |
echo "Unmounting camera... (you can remove the camera now)" | |
umount $USBMOUNTPOINT | |
fi | |
;; | |
"gphoto2") | |
# gphoto2 support? | |
echo "Searching gphoto2 camera..." | |
TMP=$( gphoto2 --auto-detect | grep usb | wc -l ) | |
if [ "$TMP" -gt "0" ]; then | |
mkdir -p $CACHEDIR/tmp | |
cd $CACHEDIR/tmp | |
echo "Copying pictures from camera..." | |
gphoto2 -P &> /dev/null | |
find . -iregex .*jp.* -exec mv {} $CACHEDIR \; | |
cd - | |
cd $CACHEDIR | |
rm -Rf tmp | |
cd - | |
echo "Done with camera... (you can remove the camera now)" | |
else | |
echo "! Camera not connected , not grabbing new images" | |
fi | |
;; | |
esac | |
DIRSIZE=$( ls -1 $CACHEDIR | wc -l ) | |
echo "$DIRSIZE image(s) in cache..." | |
# errr , you could make this faster by pinging a more local host that doesnt block ping ;) | |
ping -c1 -w1 spacedout.nl &> /dev/null | |
if [ $? -eq 0 ]; then | |
if [ "$DIRSIZE" -gt "0" ]; then | |
echo "Uploading pictures to gallery... (this could take a while)" | |
perl /home/buzz/galleryadd.pl -l $GALLERY -a $GALLERYALBUM -u $GALLERYUSER -p $GALLERYPASS -captions -quiet $CACHEDIR/* | |
echo "Moving pictures to archive..." | |
mv $CACHEDIR/* $ARCHIVEDIR &> /dev/null | |
else | |
echo "! No images in cache , nothing to do" | |
fi | |
else | |
echo "! Not connected to the internet , not able to upload cache" | |
fi | |
sleep 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment