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
1 changed files with 105 additions and 76 deletions

View File

@ -37,7 +37,7 @@ MODES[1]="Drone"
# SD card mount point
declare -a SD_MOUNT_POINT
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
declare -a SD_SRC_PATH
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[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
######################################################################################
@ -65,7 +69,7 @@ set_mode() {
MAC_INGEST_PATH="${MAC_INGEST_FOLDER[$INGEST_MODE]}/$CURRENT_DATE"
# Where to ingest to on the NAS
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
@ -103,7 +107,7 @@ mode_prompt() {
exit
;;
*)
clear
# clear
echo "!! Invalid Option !!"
exit 1
;;
@ -113,38 +117,19 @@ mode_prompt() {
# Create and open Mac folders.
create_folders_mac() {
# Check if the parent ingest directory doesn't exist
if [[ ! -d "$MAC_INGEST_PATH" ]]; then
echo "Creating ingest directories at $MAC_INGEST_PATH/{ARW,JPG,MP4}..."
if [[ ! -d "$MAC_INGEST_PATH}" ]]; then
echo "Creating ingest folder at $MAC_INGEST_PATH}"
# 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
if [[ $? -eq 0 ]]; then
echo "Success!"
else
echo "Failed to create directories at $MAC_INGEST_PATH"
echo "Failed to create directory at $MAC_INGEST_PATH}"
exit 1
fi
else
# The parent directory exists, but do the children?
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
echo "Ingest folder already exists: $MAC_INGEST_PATH}"
fi
}
@ -215,56 +200,84 @@ clean_sd() {
fi
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
# TODO: Add file type arrays, this won't work for the drone right now
ingest_mac() {
local src="${SD_MOUNT_POINT[$INGEST_MODE]}/${SD_SRC_PATH[$INGEST_MODE]}"
create_folders_mac
echo "Beginning copy..."
# Copy JPG files
jpg_files=("$SD_MOUNT_POINT/$SD_SRC_PATH/"*.JPG)
if [[ -f "${jpg_files[0]}" ]]; then
echo "Copying JPGs..."
rsync -avzc --progress "$SD_MOUNT_POINT/$SD_SRC_PATH/"*.JPG "$MAC_INGEST_PATH/JPG/"
else
echo "No JPGs, skipping."
fi
# Copy ARW files
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
echo "No ARWs, skipping."
fi
# Copy MP4 files
mp4_files=("$SD_MOUNT_POINT/$SD_SRC_PATH/"*.MP4)
if [[ -f "${mp4_files[0]}" ]]; then
echo "Copying MP4s..."
rsync -avzc --progress "$SD_MOUNT_POINT/$SD_SRC_PATH/"*.MP4 "$MAC_INGEST_PATH/MP4/"
else
echo "No MP4s, skipping."
if [[ $INGEST_MODE -eq 0 ]]; then
# Iterate over FILE_EXTS0 and copy
for ext in "${FILE_EXTS0[@]}"; do
# Check for and enumerate files
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
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
elif [[ $INGEST_MODE -eq 1 ]]; then
# Iterate over FILE_EXTS1 and copy
for ext in "${FILE_EXTS1[@]}"; do
# Check for and enumerate files
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
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
echo "Ingest complete!"
open "$MAC_INGEST_PATH"
echo "Press any key to return to the menu..."
read -n 1 -s
}
# Mac->NAS Ingest
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 "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/
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
# jpg_files=("$MAC_INGEST_PATH/JPG/"*.JPG)
# if [[ -f "${jpg_files[0]}" ]]; then
# 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
# echo "No JPGs, skipping."
# fi
@ -273,7 +286,7 @@ ingest_nas() {
# arw_files=("$MAC_INGEST_PATH/ARW/"*.ARW)
# if [[ -f "${arw_files[0]}" ]]; then
# 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
# echo "No ARWs, skipping."
# fi
@ -282,12 +295,13 @@ ingest_nas() {
# mp4_files=("$MAC_INGEST_PATH/MP4/"*.MP4)
# if [[ -f "${mp4_files[0]}" ]]; then
# 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
# echo "No MP4s, skipping."
# fi
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
if mount | grep -q "${SD_MOUNT_POINT[$INGEST_MODE]}"; then
echo "SD Card Mounted at $SD_MOUNT_POINT."
touch /tmp/mounted
else
echo "ERR: SD Card Not mounted!"
exit 1
@ -306,7 +320,6 @@ fi
if mount | grep -q "$NAS_ADDRESS"; then
# Get the NAS mount point since it can vary
NAS_MOUNT_POINT=$(mount | grep "$NAS_ADDRESS" | awk '{print $3}' | grep -E '^/Volumes/media(-1)?$')
echo "NAS Mounted at $NAS_MOUNT_POINT."
else
echo "ERR: NAS Not mounted!"
exit 1
@ -328,22 +341,24 @@ mode_prompt
# break lines accordingly in the shell
while true; do
# Empty the screen
clear
# clear
# Print the prompt
echo "[ ${MODES[$INGEST_MODE]} Ingest Script ]"
echo ""
echo "Ingest Source Path: ${SD_MOUNT_POINT[$INGEST_MODE]}${SD_SRC_PATH[$INGEST_MODE]}"
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 "Please enter an option from below:"
echo ""
echo "[1] SD->Mac Ingest"
echo "[2] Mac->NAS Ingest"
echo "[3] !! Delete ALL images on SD card!!"
echo "[4] Change ingest mode"
echo "[2] Sync to NAS"
echo "[3] Dry Run Sync to NAS"
echo "[4] !! Delete ALL images on SD card!!"
echo "[5] !! Delete ALL ingested images on Mac!!"
echo "[6] Open folders"
echo ""
echo "[0] Exit"
echo "[0] Change Mode / Exit"
# Wait for input
read -p "Option: " opt
@ -359,25 +374,39 @@ while true; do
# Mac->NAS Ingest
clear
ingest_nas
# echo "Untested and not working yet!"
;;
3)
# !! Delete ALL images on SD card!!
# Dry Run Mac->NAS Ingest
clear
clean_sd
ingest_nas 1
# echo "Untested and not working yet!"
;;
4)
# Change ingest mode
# !! Delete ALL media on SD card!!
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)
# Exit the script
echo "!! Quitting !!"
sleep 0.8s
# Back out to mode prompt
clear
exit
mode_prompt
;;
*)
clear
# clear
echo "!! Invalid Option !!"
;;
esac