Last active
March 2, 2021 15:53
-
-
Save Jun-Dai/5720688 to your computer and use it in GitHub Desktop.
Script to import my photos from the SD card to my USB stick
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
echo | |
echo "source dir: ${PHOTO_SRC_DIR:=/Volumes/EOS_DIGITAL}" | |
echo "target base dir: ${PHOTO_TARG_BASE_DIR:=/Volumes/Ellington/Raw Imports}" | |
echo "date: ${FOLDER_DATE:=`date "+%Y-%m-%d"`}" | |
PHOTO_TARG_DIR="$PHOTO_TARG_BASE_DIR/$FOLDER_DATE" | |
PHOTO_TMP_DIR="$PHOTO_TARG_BASE_DIR/tmp_`date +%s`" | |
echo "target folder will be: ${PHOTO_TARG_DIR}" | |
echo | |
read -p "Do you want to proceed? " | |
if [[ ! $REPLY =~ ^[Yy]$ ]] | |
then | |
echo "Okay, figure out what the bloody hell you actually want, and let me know when you're ready..." | |
exit 1 | |
fi | |
if [ ! -d "$PHOTO_SRC_DIR" ] | |
then | |
echo "Source folder does not exist! I cannot proceed..." | |
exit 1 | |
fi | |
if [ -d "$PHOTO_TARG_DIR" ] | |
then | |
echo "Folder $PHOTO_TARG_DIR already exists! I can't support two imports for the same date. Quitting..." | |
exit 1 | |
fi | |
if test ! -n "$(find "$PHOTO_SRC_DIR" -maxdepth 1 -name '*.CR2' -print -quit)" | |
then | |
echo "No CR2 files to copy! Did you set up the source directory correctly?" | |
exit 1 | |
fi | |
if mkdir -p "$PHOTO_TMP_DIR" | |
then | |
echo "Created temp folder $PHOTO_TMP_DIR" | |
else | |
echo "Failed to create temp folder $PHOTO_TMP_DIR" | |
exit 1 | |
fi | |
# Now we have a temp folder that we should probably delete when done. | |
#careful! | |
del_tmp_dir() { rm -rf "$PHOTO_TMP_DIR" ; } | |
copy_files() { | |
local format=$1 | |
if test ! -n "$(find "$PHOTO_SRC_DIR" -maxdepth 1 -name *.$format -print -quit)" | |
then | |
echo "No $format files to copy. Skipping" | |
return 1 | |
fi | |
if mkdir -p "$PHOTO_TMP_DIR/$format" | |
then | |
echo "Created temp folder $PHOTO_TMP_DIR/$format" | |
else | |
echo "Failed to create temp folder $PHOTO_TMP_DIR/$format" | |
return 1 | |
fi | |
if cp "$PHOTO_SRC_DIR/"*.$format "$PHOTO_TMP_DIR/$format/" | |
then | |
echo "Copied all $format files to temp dir" | |
else | |
echo "Failed to copy $format files to temp dir" | |
return 1 | |
fi | |
} | |
if ! copy_files CR2 | |
then | |
del_tmp_dir | |
exit 1 | |
fi | |
copy_files JPG | |
copy_files MOV | |
if mv "$PHOTO_TMP_DIR" "$PHOTO_TARG_DIR" | |
then | |
echo "Moved $PHOTO_TMP_DIR to $PHOTO_TARG_DIR" | |
else | |
echo "Failed to move $PHOTO_TMP_DIR" | |
del_tmp_dir | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment