#!/bin/bash # imalib is a php program to present pictures in a web interface. # Copyright (C) 2002 Sébastien MICHEL # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # permet d'archiver et faire un backup au format d'archive de Casio (QV3500EX au moins) # ce script doit être placé dans /etc/hotplug/usb # This script make archives plus backup with the tree format from Casio (QV3500EX at least) # This script must be put in /etc/hotplug/usb ############################################################ # Config # vous devez mettre la variable $ACTIVE a TRUE pour faire marcher ce script. # You must put TRUE in $ACTIVE to make this script work # ACTIVE="TRUE" ACTIVE="false" # MOUNT="FALSE" # On monte l'apn ? # APN="/mnt/rack/Image Library/apn/" # chemin ou se trouve l'appareil photo après le montage. # APNPATH="" # chemin ou se trouve les repertoires de photo dans l'appareil. MOUNT="TRUE" # On monte l'apn ? APN="/mnt/apn/" # chemin ou se trouve l'appareil photo après le montage. APNPATH="dcim/" # chemin ou se trouve les repertoires de photo dans l'appareil. RECUP="/mnt/rack/Image Library/" # chemin primaire de recuperation des photo BACKUP="/mnt/videorip/Image Library/" # chemin du backup des photos qui seront recopiés en double. DEV="/dev/sdc1" # device de l'appareil photo FS="vfat" # fs de l'appareil photo mount="/bin/mount -t $FS $DEV $APN" # commande de montage de l'appareil photo. umount="/bin/umount $APN" # commande de démontage de l'appareil photo. ############################################################ # Script Side cd /etc/hotplug . hotplug.functions if [ "`echo $ACTIVE |tr \"[:lower:]\" \"[:upper:]\"`" = "FALSE" ]; then mesg "Rapatriement des photos inactif !" exit; fi if [ ! -d "$APN" ];then mesg "Probleme avec le chemin du l'appareil photo: $APN" exit; else mesg "chemin du l'appareil photo: $APN" if [ "`echo $MOUNT |tr \"[:lower:]\" \"[:upper:]\"`" = "TRUE" ]; then mesg "montage de l'appareil photo: $APN -> $mount" $mount fi fi if [ ! -d "${APN}${APNPATH}" ];then mesg "Probleme avec le chemin des photo dans l'appareil: ${APN$APNPATH}" exit; fi if [ ! -d "$RECUP" ];then mesg "Probleme avec le chemin de destination: $RECUP" exit; else mesg "chemin de destination: $RECUP" fi if [ ! -d "$BACKUP" ];then mesg "Probleme avec le chemin du backup: $BACKUP" exit; else mesg "chemin du backup: $BACKUP" fi mesg "detection des repertoires a recuperer:" LIST=`find "${APN}${APNPATH}" -type d|grep "[0-9]\{3\}_[0-9]\{4\}$" |sed "y/ /µ/"` find "/mnt/apn/dcim/" -type d|grep "[0-9]\{3\}_[0-9]\{4\}$" |sed "y/ /µ/">>/toto YEAR=`date +%Y`; mesg "Liste des repertoires a rapatrier: $LIST" for REP in $LIST do # repertoire ou sont les photos dans l'appareil. ORG="${REP/µ/ }" # Repertoire final d'archivage. REP=${REP/\/[0-9][0-9][0-9]_/\/$YEAR}; REP=${REP/µ/ }; REP=${REP/*\//}; DEST="${RECUP}$REP" DEST2="${BACKUP}$REP" # # creation de la destination. # if [ ! -d "${DEST}" ];then # mesg "Creation de ${DEST}" # mkdir ${DEST} # fi # if [ ! -d "${DEST2}" ];then # mesg "Creation de ${DEST2}" # mkdir ${DEST2} # fi # si la destination existe on la renomme. if [ -d "${DEST}" ];then DESTOLD="${DEST}" while [ -d "${DESTOLD}" ] do DESTOLD="${DESTOLD}.old" done mesg "Déplacement de $DEST vers $DESTOLD" mv "${DEST}" "${DESTOLD}" fi if [ -d "${DEST2}" ];then DESTOLD="${DEST2}" while [ -d "${DESTOLD}" ] do DESTOLD="${DESTOLD}.old" done mesg "Déplacement de $DEST2 vers $DESTOLD" mv "${DEST2}" "${DESTOLD}" fi mesg "Déplacement de $ORG vers $DEST" mesg "Sauvegarde de $DEST vers $DEST2" IMGS=`find "${ORG}" -name "*.jpg"|grep -v "\\(preview\\|PREVIEW\\)"` #y a t il des images dans le repertoire a sauvegarder ? if [ "$IMGS" ];then # mise en archivage des photos. mv "$ORG" "$DEST" # cp -r "$ORG" "$DEST" mesg "Repertoire $DEST:" mesg `ls "$DEST"` # verification de l'orientation des images IMGS=`find "${DEST}" -name "*.jpg"|grep -v "\\(preview\\|PREVIEW\\)" |sed "y/ /µ/"` for IMG in $IMGS do IMG="${IMG/µ/ }" ORIENTATION=`identify -format "%[EXIF:Orientation]" "$IMG"` mesg "$IMG:$ORIENTATION" if [ "$ORIENTATION" ];then if [ "`identify -format "%[EXIF:ExifImageWidth]" "$IMG"`" -eq "`identify -format "%w" "$IMG"`" -a "`identify -format "%[EXIF:ExifImageLength]" "$IMG"`" -eq "`identify -format "%h" "$IMG"`" ];then if [ "$ORIENTATION" -eq "6" ];then convert -rotate "90" "$IMG" "${IMG}tmp.jpg" mv "${IMG}tmp.jpg" "$IMG" elif [ "$ORIENTATION" -eq "8" ];then convert -rotate "270" "$IMG" "${IMG}tmp.jpg" mv "${IMG}tmp.jpg" "$IMG" fi else mesg "Image déjà retournée." fi fi done # sauvegarde du repertoire d'archivage. cp -r "$DEST" "$DEST2" mesg "Repertoire de sauvegarde $DEST2:" mesg `ls "$DEST2"` else mesg "REPERTOIRE sans image: $ORG" rm -r "$ORG" fi done if [ "`echo $MOUNT |tr \"[:lower:]\" \"[:upper:]\"`" = "TRUE" ]; then mesg "démontage de l'appareil photo: $APN" $umount fi