Tentatively working SD to mac and mac to nas

This commit is contained in:
Skylar Grant 2024-06-23 15:23:09 -04:00
parent 40ecd0b4f2
commit 3f97971e3e

View File

@ -37,7 +37,7 @@ MODES[1]="Drone"
# SD card mount point # SD card mount point
declare -a SD_MOUNT_POINT declare -a SD_MOUNT_POINT
SD_MOUNT_POINT[0]="/Volumes/NO NAME" # Camera SD_MOUNT_POINT[0]="/Volumes/NO NAME" # Camera
SD_MOUNT_POINT[1]="Volumes/Untitled" # Drone SD_MOUNT_POINT[1]="/Volumes/Untitled" # Drone
# Camera's path to images # Camera's path to images
declare -a SD_SRC_PATH declare -a SD_SRC_PATH
SD_SRC_PATH[0]="/DCIM/100MSDCF" # Camera SD_SRC_PATH[0]="/DCIM/100MSDCF" # Camera
@ -54,6 +54,10 @@ declare -a NAS_INGEST_FOLDER
NAS_INGEST_FOLDER[0]="/Camera Ingest" NAS_INGEST_FOLDER[0]="/Camera Ingest"
NAS_INGEST_FOLDER[1]="/Drone Ingest" NAS_INGEST_FOLDER[1]="/Drone Ingest"
# File extensions to be imported
FILE_EXTS0=("JPG" "ARW" "MP4") # Camera TODO: the camera doesn't save to MP4, figure it out.
FILE_EXTS1=("JPG" "DNG" "MP4") # Drone
###################################################################################### ######################################################################################
# Functions # Functions
###################################################################################### ######################################################################################
@ -65,7 +69,7 @@ set_mode() {
MAC_INGEST_PATH="${MAC_INGEST_FOLDER[$INGEST_MODE]}/$CURRENT_DATE" MAC_INGEST_PATH="${MAC_INGEST_FOLDER[$INGEST_MODE]}/$CURRENT_DATE"
# Where to ingest to on the NAS # Where to ingest to on the NAS
NAS_INGEST_PATH="${NAS_INGEST_FOLDER[$INGEST_MODE]}/$CURRENT_DATE" NAS_INGEST_PATH="${NAS_INGEST_FOLDER[$INGEST_MODE]}/$CURRENT_DATE"
echo "Ingest mode set to ${MODES[$INGEST_MODE]} [$INGEST_MODE]" # echo "Ingest mode set to ${MODES[$INGEST_MODE]} [$INGEST_MODE]"
} }
# Mode Prompt # Mode Prompt
@ -103,7 +107,7 @@ mode_prompt() {
exit exit
;; ;;
*) *)
clear # clear
echo "!! Invalid Option !!" echo "!! Invalid Option !!"
exit 1 exit 1
;; ;;
@ -113,38 +117,19 @@ mode_prompt() {
# Create and open Mac folders. # Create and open Mac folders.
create_folders_mac() { create_folders_mac() {
# Check if the parent ingest directory doesn't exist # Check if the parent ingest directory doesn't exist
if [[ ! -d "$MAC_INGEST_PATH" ]]; then if [[ ! -d "$MAC_INGEST_PATH}" ]]; then
echo "Creating ingest directories at $MAC_INGEST_PATH/{ARW,JPG,MP4}..." echo "Creating ingest folder at $MAC_INGEST_PATH}"
# Since the parent doesn't exist, we create it and all children at once # Since the parent doesn't exist, we create it and all children at once
mkdir -p "$MAC_INGEST_PATH"/{ARW,JPG,MP4} mkdir -p "$MAC_INGEST_PATH}"
# $? is the exit status of the last commmand, with 0 being success # $? is the exit status of the last commmand, with 0 being success
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
echo "Success!" echo "Success!"
else else
echo "Failed to create directories at $MAC_INGEST_PATH" echo "Failed to create directory at $MAC_INGEST_PATH}"
exit 1 exit 1
fi fi
else else
# The parent directory exists, but do the children? echo "Ingest folder already exists: $MAC_INGEST_PATH}"
echo "Parent ingest directory already exists. Checking for subdirectories..."
# Iterate over each folder name
for folder in ARW JPG MP4; do
# If the subdir doesn't exist
if [[ ! -d "$MAC_INGEST_PATH/$folder" ]]; then
echo "Subdirectory $folder is missing, creating..."
# Create the missing subdir
mkdir -p "$MAC_INGEST_PATH/$folder"
# $? is the exit status of the last commmand, with 0 being success
if [[ $? -eq 0 ]]; then
echo "Successfully created $MAC_INGEST_PATH/$folder"
else
echo "Failed to create $MAC_INGEST_PATH/$folder"
exit 1
fi
else
echo "$MAC_INGEST_PATH/$folder already exists."
fi
done
fi fi
} }
@ -215,56 +200,84 @@ clean_sd() {
fi fi
cd - || { echo "Failed to return to the previous directory."; return 1; } cd - || { echo "Failed to return to the previous directory."; return 1; }
echo "Press any key to return to the menu..."
read -n 1 -s
} }
# Camera->Mac Ingest # Camera->Mac Ingest
# TODO: Add file type arrays, this won't work for the drone right now
ingest_mac() { ingest_mac() {
local src="${SD_MOUNT_POINT[$INGEST_MODE]}/${SD_SRC_PATH[$INGEST_MODE]}"
create_folders_mac create_folders_mac
echo "Beginning copy..." echo "Beginning copy..."
# Copy JPG files if [[ $INGEST_MODE -eq 0 ]]; then
jpg_files=("$SD_MOUNT_POINT/$SD_SRC_PATH/"*.JPG) # Iterate over FILE_EXTS0 and copy
if [[ -f "${jpg_files[0]}" ]]; then for ext in "${FILE_EXTS0[@]}"; do
echo "Copying JPGs..." # Check for and enumerate files
rsync -avzc --progress "$SD_MOUNT_POINT/$SD_SRC_PATH/"*.JPG "$MAC_INGEST_PATH/JPG/" files=("$src/"*."$ext")
if [[ -f "${files[0]}" ]]; then
mkdir -p "$MAC_INGEST_PATH/$ext/"
# $? is the exit status of the last commmand, with 0 being success
if [[ $? -eq 0 ]]; then
echo "Created ${ext}s folder."
else else
echo "No JPGs, skipping." echo "Failed to create ${ext}s folder."
exit 1
fi fi
echo "Copying ${ext}s..."
# Copy ARW files rsync -avz --progress "$src/"*."$ext" "$MAC_INGEST_PATH/$ext/"
arw_files=("$SD_MOUNT_POINT/$SD_SRC_PATH/"*.ARW)
if [[ -f "${arw_files[0]}" ]]; then
echo "Copying ARWs..."
rsync -avzc --progress "$SD_MOUNT_POINT/$SD_SRC_PATH/"*.ARW "$MAC_INGEST_PATH/ARW/"
else else
echo "No ARWs, skipping." echo "No ${ext}s, skipping."
fi fi
done
# Copy MP4 files elif [[ $INGEST_MODE -eq 1 ]]; then
mp4_files=("$SD_MOUNT_POINT/$SD_SRC_PATH/"*.MP4) # Iterate over FILE_EXTS1 and copy
if [[ -f "${mp4_files[0]}" ]]; then for ext in "${FILE_EXTS1[@]}"; do
echo "Copying MP4s..." # Check for and enumerate files
rsync -avzc --progress "$SD_MOUNT_POINT/$SD_SRC_PATH/"*.MP4 "$MAC_INGEST_PATH/MP4/" files=("$src/"*."$ext")
if [[ -f "${files[0]}" ]]; then
mkdir -p "$MAC_INGEST_PATH/$ext/"
# $? is the exit status of the last commmand, with 0 being success
if [[ $? -eq 0 ]]; then
echo "Created ${ext}s folder."
else else
echo "No MP4s, skipping." echo "Failed to create ${ext}s folder."
exit 1
fi
echo "Copying ${ext}s..."
rsync -avz --progress "$src/"*."$ext" "$MAC_INGEST_PATH/$ext/"
else
echo "No ${ext}s, skipping."
fi
done
fi fi
echo "Ingest complete!" echo "Ingest complete!"
open "$MAC_INGEST_PATH" echo "Press any key to return to the menu..."
read -n 1 -s
} }
# Mac->NAS Ingest # Mac->NAS Ingest
ingest_nas() { ingest_nas() {
create_folders_nas local dry_run=""
# Detect if dry run
if [[ $1 -eq 1 ]]; then
dry_run=" --dry-run"
fi
echo "Beginning copy..." echo "Beginning copy..."
echo "Syncing ingested images with NAS..." echo "Syncing ingested images with NAS..."
echo "Source: ${MAC_INGEST_FOLDER[$INGEST_MODE]}/"
echo "Destination: $NAS_MOUNT_POINT${NAS_INGEST_FOLDER[$INGEST_MODE]}/"
echo "Press any key to continue..."
read -n 1 -s
# Sync /Volumes/voidf1sh/Pictures/Camera Ingest/ with NAS/media/Camera Ingest/ # Sync /Volumes/voidf1sh/Pictures/Camera Ingest/ with NAS/media/Camera Ingest/
rsync -azv --progress "$MAC_INGEST_FOLDER/" rsync -azv --progress "$MAC_INGEST_FOLDER/" "$NAS_MOUNT_POINT${NAS_INGEST_FOLDER[$INGEST_MODE]}/" $dry_run
# Copy JPG files # Copy JPG files
# jpg_files=("$MAC_INGEST_PATH/JPG/"*.JPG) # jpg_files=("$MAC_INGEST_PATH/JPG/"*.JPG)
# if [[ -f "${jpg_files[0]}" ]]; then # if [[ -f "${jpg_files[0]}" ]]; then
# echo "Copying JPGs..." # echo "Copying JPGs..."
# rsync -avzc --progress "$MAC_INGEST_PATH/JPG/"*.JPG "$NAS_MOUNT_POINT/$NAS_INGEST_PATH/JPG/" # rsync -avz --progress "$MAC_INGEST_PATH/JPG/"*.JPG "$NAS_MOUNT_POINT/$NAS_INGEST_PATH/JPG/"
# else # else
# echo "No JPGs, skipping." # echo "No JPGs, skipping."
# fi # fi
@ -273,7 +286,7 @@ ingest_nas() {
# arw_files=("$MAC_INGEST_PATH/ARW/"*.ARW) # arw_files=("$MAC_INGEST_PATH/ARW/"*.ARW)
# if [[ -f "${arw_files[0]}" ]]; then # if [[ -f "${arw_files[0]}" ]]; then
# echo "Copying ARWs..." # echo "Copying ARWs..."
# rsync -avzc --progress "$MAC_INGEST_PATH/ARW/"*.ARW "$NAS_MOUNT_POINT/$NAS_INGEST_PATH/ARW/" # rsync -avz --progress "$MAC_INGEST_PATH/ARW/"*.ARW "$NAS_MOUNT_POINT/$NAS_INGEST_PATH/ARW/"
# else # else
# echo "No ARWs, skipping." # echo "No ARWs, skipping."
# fi # fi
@ -282,12 +295,13 @@ ingest_nas() {
# mp4_files=("$MAC_INGEST_PATH/MP4/"*.MP4) # mp4_files=("$MAC_INGEST_PATH/MP4/"*.MP4)
# if [[ -f "${mp4_files[0]}" ]]; then # if [[ -f "${mp4_files[0]}" ]]; then
# echo "Copying MP4s..." # echo "Copying MP4s..."
# rsync -avzc --progress "$MAC_INGEST_PATH/MP4/"*.MP4 "$NAS_MOUNT_POINT/$NAS_INGEST_PATH/MP4/" # rsync -avz --progress "$MAC_INGEST_PATH/MP4/"*.MP4 "$NAS_MOUNT_POINT/$NAS_INGEST_PATH/MP4/"
# else # else
# echo "No MP4s, skipping." # echo "No MP4s, skipping."
# fi # fi
echo "Ingest complete!" echo "Ingest complete!"
open "$NAS_MOUNT_POINT/$NAS_INGEST_PATH" echo "Press any key to return to the menu..."
read -n 1 -s
} }
###################################################################################### ######################################################################################
@ -296,7 +310,7 @@ ingest_nas() {
# Check if the SD card is mounted # Check if the SD card is mounted
if mount | grep -q "${SD_MOUNT_POINT[$INGEST_MODE]}"; then if mount | grep -q "${SD_MOUNT_POINT[$INGEST_MODE]}"; then
echo "SD Card Mounted at $SD_MOUNT_POINT." touch /tmp/mounted
else else
echo "ERR: SD Card Not mounted!" echo "ERR: SD Card Not mounted!"
exit 1 exit 1
@ -306,7 +320,6 @@ fi
if mount | grep -q "$NAS_ADDRESS"; then if mount | grep -q "$NAS_ADDRESS"; then
# Get the NAS mount point since it can vary # Get the NAS mount point since it can vary
NAS_MOUNT_POINT=$(mount | grep "$NAS_ADDRESS" | awk '{print $3}' | grep -E '^/Volumes/media(-1)?$') NAS_MOUNT_POINT=$(mount | grep "$NAS_ADDRESS" | awk '{print $3}' | grep -E '^/Volumes/media(-1)?$')
echo "NAS Mounted at $NAS_MOUNT_POINT."
else else
echo "ERR: NAS Not mounted!" echo "ERR: NAS Not mounted!"
exit 1 exit 1
@ -328,22 +341,24 @@ mode_prompt
# break lines accordingly in the shell # break lines accordingly in the shell
while true; do while true; do
# Empty the screen # Empty the screen
clear # clear
# Print the prompt # Print the prompt
echo "[ ${MODES[$INGEST_MODE]} Ingest Script ]" echo "[ ${MODES[$INGEST_MODE]} Ingest Script ]"
echo "" echo ""
echo "Ingest Source Path: ${SD_MOUNT_POINT[$INGEST_MODE]}${SD_SRC_PATH[$INGEST_MODE]}" echo "Ingest Source Path: ${SD_MOUNT_POINT[$INGEST_MODE]}${SD_SRC_PATH[$INGEST_MODE]}"
echo "Mac Ingest Path: $MAC_INGEST_PATH" echo "Mac Ingest Path: $MAC_INGEST_PATH"
echo "NAS Ingest Path: $NAS_INGEST_PATH" echo "NAS Ingest Path: $NAS_MOUNT_POINT$NAS_INGEST_PATH"
echo "" echo ""
echo "Please enter an option from below:" echo "Please enter an option from below:"
echo "" echo ""
echo "[1] SD->Mac Ingest" echo "[1] SD->Mac Ingest"
echo "[2] Mac->NAS Ingest" echo "[2] Sync to NAS"
echo "[3] !! Delete ALL images on SD card!!" echo "[3] Dry Run Sync to NAS"
echo "[4] Change ingest mode" echo "[4] !! Delete ALL images on SD card!!"
echo "[5] !! Delete ALL ingested images on Mac!!"
echo "[6] Open folders"
echo "" echo ""
echo "[0] Exit" echo "[0] Change Mode / Exit"
# Wait for input # Wait for input
read -p "Option: " opt read -p "Option: " opt
@ -359,25 +374,39 @@ while true; do
# Mac->NAS Ingest # Mac->NAS Ingest
clear clear
ingest_nas ingest_nas
# echo "Untested and not working yet!"
;; ;;
3) 3)
# !! Delete ALL images on SD card!! # Dry Run Mac->NAS Ingest
clear clear
clean_sd ingest_nas 1
# echo "Untested and not working yet!"
;; ;;
4) 4)
# Change ingest mode # !! Delete ALL media on SD card!!
clear clear
mode_prompt;; # clean_sd
echo "Untested and not working yet!"
;;
5)
# !! Delete ALL ingested media on Mac!!
clear
# clean_mac
echo "Untested and not working yet!"
;;
6)
# Open folders
clear
# open_folders
echo "Untested and not working yet!"
;;
0) 0)
# Exit the script # Back out to mode prompt
echo "!! Quitting !!"
sleep 0.8s
clear clear
exit mode_prompt
;; ;;
*) *)
clear # clear
echo "!! Invalid Option !!" echo "!! Invalid Option !!"
;; ;;
esac esac