2024-06-10 01:01:08 +00:00
|
|
|
#!/bin/bash
|
2024-06-10 02:30:58 +00:00
|
|
|
|
|
|
|
######################################################################################
|
2024-06-23 17:50:40 +00:00
|
|
|
# Name: Photo/Video Ingest Script for Camera and Drone
|
2024-06-10 01:01:08 +00:00
|
|
|
# Author: voidf1sh (Skylar Grant)
|
2024-06-23 17:50:40 +00:00
|
|
|
# Environment: M1 MacBook Pro, Sony a5100, DJI Mini 2
|
2024-06-10 01:01:08 +00:00
|
|
|
#
|
2024-06-23 17:50:40 +00:00
|
|
|
# Mounts: (Device Mount -- Volume Mount)
|
2024-06-10 02:30:58 +00:00
|
|
|
# Camera SD: /dev/diskXsY (varies) -- /Volumes/NO NAME
|
2024-06-23 17:50:40 +00:00
|
|
|
# Drone SD: /dev/diskXsY (varies) -- /Volumes/Untitled
|
2024-06-10 02:30:58 +00:00
|
|
|
# NAS: //GUEST:@192.168.0.2/media -- /Volumes/media or /Volumes/media-1 (varies)
|
2024-06-10 01:01:08 +00:00
|
|
|
#
|
2024-06-23 17:50:40 +00:00
|
|
|
# Ingest Source Paths:
|
|
|
|
# Camera SD: /DCIM/100MSDCF
|
|
|
|
# Drone SD: /DCIM/100MEDIA
|
|
|
|
#
|
2024-06-10 01:01:08 +00:00
|
|
|
# Git: https://git.vfsh.dev/voidf1sh/custom-scripts
|
2024-06-23 17:50:40 +00:00
|
|
|
# File: ingest-mac.sh
|
|
|
|
# Version: 0.1.1
|
2024-06-10 02:30:58 +00:00
|
|
|
######################################################################################
|
2024-06-10 01:01:08 +00:00
|
|
|
|
|
|
|
# Some initial variables to work with
|
|
|
|
# Set the date for folder creation
|
|
|
|
CURRENT_DATE=$(date +%F)
|
2024-06-23 17:50:40 +00:00
|
|
|
|
2024-06-10 02:30:58 +00:00
|
|
|
# Paths
|
|
|
|
# IMPORTANT: Paths should NEVER have trailing slashes, and ALWAYS have leading slashes
|
2024-06-23 16:52:26 +00:00
|
|
|
|
2024-06-23 17:50:40 +00:00
|
|
|
# Moving mount points to indices, 0=Camera Mode 1=Drone Mode
|
|
|
|
INGEST_MODE=9 # Default to an invalid mode.
|
|
|
|
|
2024-06-23 17:54:09 +00:00
|
|
|
# Mode names to be used in the script later.
|
2024-06-23 17:50:40 +00:00
|
|
|
declare -a MODES
|
|
|
|
MODES[0]="Camera"
|
|
|
|
MODES[1]="Drone"
|
2024-06-23 17:54:09 +00:00
|
|
|
|
2024-06-23 16:52:26 +00:00
|
|
|
# SD card mount point
|
2024-06-23 17:50:40 +00:00
|
|
|
declare -a SD_MOUNT_POINT
|
|
|
|
SD_MOUNT_POINT[0]="/Volumes/NO NAME" # Camera
|
2024-06-23 19:23:09 +00:00
|
|
|
SD_MOUNT_POINT[1]="/Volumes/Untitled" # Drone
|
2024-06-10 02:30:58 +00:00
|
|
|
# Camera's path to images
|
2024-06-23 17:50:40 +00:00
|
|
|
declare -a SD_SRC_PATH
|
|
|
|
SD_SRC_PATH[0]="/DCIM/100MSDCF" # Camera
|
|
|
|
SD_SRC_PATH[1]="/DCIM/100MEDIA" # Drone
|
2024-06-10 02:30:58 +00:00
|
|
|
# NAS Network Address
|
|
|
|
NAS_ADDRESS="//GUEST:@192.168.0.2/media"
|
|
|
|
|
2024-06-23 16:52:26 +00:00
|
|
|
# Folder where ingests are stored on the Mac
|
2024-06-23 17:50:40 +00:00
|
|
|
declare -a MAC_INGEST_FOLDER
|
|
|
|
MAC_INGEST_FOLDER[0]="$HOME/Pictures/Camera Ingest" # Camera
|
|
|
|
MAC_INGEST_FOLDER[1]="$HOME/Pictures/Drone Ingest" # Drone
|
2024-06-23 16:52:26 +00:00
|
|
|
# Folder where ingests are stored on the NAS
|
2024-06-23 17:50:40 +00:00
|
|
|
declare -a NAS_INGEST_FOLDER
|
|
|
|
NAS_INGEST_FOLDER[0]="/Camera Ingest"
|
|
|
|
NAS_INGEST_FOLDER[1]="/Drone Ingest"
|
2024-06-23 16:52:26 +00:00
|
|
|
|
2024-06-23 19:23:09 +00:00
|
|
|
# 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
|
|
|
|
|
2024-06-10 02:30:58 +00:00
|
|
|
######################################################################################
|
|
|
|
# Functions
|
|
|
|
######################################################################################
|
|
|
|
|
2024-06-23 17:50:40 +00:00
|
|
|
# Set mode configuration
|
|
|
|
set_mode() {
|
|
|
|
INGEST_MODE=$1
|
|
|
|
# Where to ingest to on the Mac
|
|
|
|
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"
|
2024-06-23 19:23:09 +00:00
|
|
|
# echo "Ingest mode set to ${MODES[$INGEST_MODE]} [$INGEST_MODE]"
|
2024-06-23 17:50:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Mode Prompt
|
|
|
|
mode_prompt() {
|
|
|
|
# Print the selection prompt
|
2024-06-23 17:54:09 +00:00
|
|
|
echo "[ voidf1sh's Ingest Script ]"
|
2024-06-23 17:50:40 +00:00
|
|
|
echo ""
|
|
|
|
echo "Please select an ingest mode:"
|
|
|
|
echo ""
|
2024-06-23 17:54:09 +00:00
|
|
|
echo "[1] ${MODES[0]}"
|
|
|
|
echo "[2] ${MODES[1]}"
|
2024-06-23 17:50:40 +00:00
|
|
|
echo ""
|
|
|
|
echo "[0] Exit"
|
|
|
|
|
|
|
|
# Wait for input
|
|
|
|
read -p "Mode: " mode
|
|
|
|
|
|
|
|
# Execute the correct commands based on input.
|
|
|
|
case "$mode" in
|
|
|
|
1)
|
|
|
|
# Camera Mode
|
|
|
|
clear
|
|
|
|
set_mode 0
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
# Drone Mode
|
|
|
|
clear
|
|
|
|
set_mode 1
|
|
|
|
;;
|
|
|
|
0)
|
|
|
|
# Exit the script
|
|
|
|
echo "!! Quitting !!"
|
|
|
|
sleep 0.8s
|
|
|
|
clear
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
*)
|
2024-06-23 19:23:09 +00:00
|
|
|
# clear
|
2024-06-23 17:50:40 +00:00
|
|
|
echo "!! Invalid Option !!"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-06-10 02:30:58 +00:00
|
|
|
# Create and open Mac folders.
|
|
|
|
create_folders_mac() {
|
|
|
|
# Check if the parent ingest directory doesn't exist
|
2024-06-23 19:43:38 +00:00
|
|
|
if [[ ! -d "$MAC_INGEST_PATH" ]]; then
|
|
|
|
echo "Creating ingest folder at $MAC_INGEST_PATH"
|
2024-06-10 02:30:58 +00:00
|
|
|
# Since the parent doesn't exist, we create it and all children at once
|
2024-06-23 19:43:38 +00:00
|
|
|
mkdir -p "$MAC_INGEST_PATH"
|
2024-06-10 02:30:58 +00:00
|
|
|
# $? is the exit status of the last commmand, with 0 being success
|
|
|
|
if [[ $? -eq 0 ]]; then
|
|
|
|
echo "Success!"
|
|
|
|
else
|
2024-06-23 19:43:38 +00:00
|
|
|
echo "Failed to create directory at $MAC_INGEST_PATH"
|
2024-06-10 02:30:58 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
2024-06-23 19:43:38 +00:00
|
|
|
echo "Ingest folder already exists: $MAC_INGEST_PATH"
|
2024-06-10 02:30:58 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-06-22 21:18:23 +00:00
|
|
|
# Cleanup images on camera SD.
|
2024-06-23 20:14:55 +00:00
|
|
|
# TODO: Update this for the new combined script
|
2024-06-10 02:30:58 +00:00
|
|
|
clean_sd() {
|
2024-06-22 21:18:23 +00:00
|
|
|
# Check if the SD card is mounted
|
|
|
|
if mount | grep -q "/Volumes/NO NAME"; then
|
|
|
|
echo "SD Card Mounted at $SD_MOUNT_POINT."
|
|
|
|
else
|
|
|
|
echo "ERR: SD Card Not mounted!"
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-06-10 02:30:58 +00:00
|
|
|
echo "Traversing to Camera..."
|
2024-06-22 21:18:23 +00:00
|
|
|
cd "$SD_MOUNT_POINT$SD_SRC_PATH" || { echo "Failed to navigate to SD card path."; return 1; }
|
|
|
|
echo "Current Directory: $(pwd)"
|
|
|
|
echo "Are you sure you want to delete all JPG, ARW, and MP4 files in $SD_MOUNT_POINT$SD_SRC_PATH? (y/N)"
|
|
|
|
read -r confirmation
|
|
|
|
|
|
|
|
if [[ "$confirmation" =~ ^[Yy]$ ]]; then
|
|
|
|
echo "Removing JPG files..."
|
|
|
|
rm *.JPG
|
|
|
|
|
|
|
|
echo "Removing ARW files..."
|
|
|
|
rm *.ARW
|
|
|
|
|
|
|
|
echo "Removing MP4 files..."
|
|
|
|
rm *.MP4
|
|
|
|
|
|
|
|
echo "Cleanup completed!"
|
|
|
|
else
|
|
|
|
echo "Cleanup aborted."
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd - || { echo "Failed to return to the previous directory."; return 1; }
|
2024-06-23 19:23:09 +00:00
|
|
|
echo "Press any key to return to the menu..."
|
|
|
|
read -n 1 -s
|
2024-06-10 02:30:58 +00:00
|
|
|
}
|
|
|
|
|
2024-06-23 20:14:55 +00:00
|
|
|
# SD->Mac Ingest
|
2024-06-10 02:30:58 +00:00
|
|
|
ingest_mac() {
|
2024-06-23 19:23:09 +00:00
|
|
|
local src="${SD_MOUNT_POINT[$INGEST_MODE]}/${SD_SRC_PATH[$INGEST_MODE]}"
|
2024-06-10 02:30:58 +00:00
|
|
|
create_folders_mac
|
|
|
|
echo "Beginning copy..."
|
|
|
|
|
2024-06-23 19:23:09 +00:00
|
|
|
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
|
2024-06-10 02:30:58 +00:00
|
|
|
fi
|
|
|
|
echo "Ingest complete!"
|
2024-06-23 19:23:09 +00:00
|
|
|
echo "Press any key to return to the menu..."
|
|
|
|
read -n 1 -s
|
2024-06-10 02:30:58 +00:00
|
|
|
}
|
|
|
|
|
2024-06-23 20:14:55 +00:00
|
|
|
# Mac->NAS Sync
|
2024-06-10 02:30:58 +00:00
|
|
|
ingest_nas() {
|
2024-06-23 19:23:09 +00:00
|
|
|
local dry_run=""
|
|
|
|
# Detect if dry run
|
|
|
|
if [[ $1 -eq 1 ]]; then
|
|
|
|
dry_run=" --dry-run"
|
|
|
|
fi
|
2024-06-10 02:30:58 +00:00
|
|
|
echo "Beginning copy..."
|
2024-06-23 16:52:26 +00:00
|
|
|
echo "Syncing ingested images with NAS..."
|
2024-06-23 19:23:09 +00:00
|
|
|
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
|
2024-06-23 16:52:26 +00:00
|
|
|
# Sync /Volumes/voidf1sh/Pictures/Camera Ingest/ with NAS/media/Camera Ingest/
|
2024-06-23 19:43:38 +00:00
|
|
|
rsync -azv --progress "${MAC_INGEST_FOLDER[$INGEST_MODE]}/" "$NAS_MOUNT_POINT${NAS_INGEST_FOLDER[$INGEST_MODE]}/" $dry_run
|
2024-06-10 02:30:58 +00:00
|
|
|
echo "Ingest complete!"
|
2024-06-23 19:23:09 +00:00
|
|
|
echo "Press any key to return to the menu..."
|
|
|
|
read -n 1 -s
|
2024-06-10 02:30:58 +00:00
|
|
|
}
|
|
|
|
|
2024-06-23 17:50:40 +00:00
|
|
|
######################################################################################
|
|
|
|
# Check for Connections
|
|
|
|
######################################################################################
|
|
|
|
|
|
|
|
# Check if the SD card is mounted
|
|
|
|
if mount | grep -q "${SD_MOUNT_POINT[$INGEST_MODE]}"; then
|
2024-06-23 19:23:09 +00:00
|
|
|
touch /tmp/mounted
|
2024-06-23 17:50:40 +00:00
|
|
|
else
|
|
|
|
echo "ERR: SD Card Not mounted!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if the NAS is mounted
|
|
|
|
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)?$')
|
|
|
|
else
|
|
|
|
echo "ERR: NAS Not mounted!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
######################################################################################
|
|
|
|
# Mode Prompt
|
|
|
|
######################################################################################
|
|
|
|
|
|
|
|
# Empty the screen
|
|
|
|
clear
|
|
|
|
mode_prompt
|
|
|
|
|
2024-06-10 02:30:58 +00:00
|
|
|
######################################################################################
|
|
|
|
# Prompt Loop
|
|
|
|
######################################################################################
|
|
|
|
|
|
|
|
# Bash allows for linebreaks in string literals and will
|
|
|
|
# break lines accordingly in the shell
|
|
|
|
while true; do
|
2024-06-23 17:50:40 +00:00
|
|
|
# Empty the screen
|
2024-06-23 19:23:09 +00:00
|
|
|
# clear
|
2024-06-23 17:50:40 +00:00
|
|
|
# Print the prompt
|
2024-06-23 17:54:09 +00:00
|
|
|
echo "[ ${MODES[$INGEST_MODE]} Ingest Script ]"
|
|
|
|
echo ""
|
2024-06-23 17:50:40 +00:00
|
|
|
echo "Ingest Source Path: ${SD_MOUNT_POINT[$INGEST_MODE]}${SD_SRC_PATH[$INGEST_MODE]}"
|
|
|
|
echo "Mac Ingest Path: $MAC_INGEST_PATH"
|
2024-06-23 19:23:09 +00:00
|
|
|
echo "NAS Ingest Path: $NAS_MOUNT_POINT$NAS_INGEST_PATH"
|
2024-06-10 02:30:58 +00:00
|
|
|
echo ""
|
|
|
|
echo "Please enter an option from below:"
|
|
|
|
echo ""
|
2024-06-23 17:50:40 +00:00
|
|
|
echo "[1] SD->Mac Ingest"
|
2024-06-23 19:23:09 +00:00
|
|
|
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"
|
2024-06-10 02:30:58 +00:00
|
|
|
echo ""
|
2024-06-23 19:23:09 +00:00
|
|
|
echo "[0] Change Mode / Exit"
|
2024-06-10 02:30:58 +00:00
|
|
|
|
|
|
|
# Wait for input
|
|
|
|
read -p "Option: " opt
|
|
|
|
|
|
|
|
# Execute the correct commands based on input.
|
|
|
|
case "$opt" in
|
|
|
|
1)
|
2024-06-23 17:50:40 +00:00
|
|
|
# SD->Mac Ingest
|
2024-06-10 02:30:58 +00:00
|
|
|
clear
|
|
|
|
ingest_mac
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
# Mac->NAS Ingest
|
|
|
|
clear
|
|
|
|
ingest_nas
|
2024-06-23 19:23:09 +00:00
|
|
|
# echo "Untested and not working yet!"
|
2024-06-10 02:30:58 +00:00
|
|
|
;;
|
|
|
|
3)
|
2024-06-23 19:23:09 +00:00
|
|
|
# Dry Run Mac->NAS Ingest
|
2024-06-10 02:30:58 +00:00
|
|
|
clear
|
2024-06-23 19:23:09 +00:00
|
|
|
ingest_nas 1
|
|
|
|
# echo "Untested and not working yet!"
|
2024-06-10 02:30:58 +00:00
|
|
|
;;
|
2024-06-23 17:50:40 +00:00
|
|
|
4)
|
2024-06-23 19:23:09 +00:00
|
|
|
# !! Delete ALL media on SD card!!
|
|
|
|
clear
|
|
|
|
# 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
|
2024-06-23 17:50:40 +00:00
|
|
|
clear
|
2024-06-23 19:23:09 +00:00
|
|
|
# open_folders
|
|
|
|
echo "Untested and not working yet!"
|
|
|
|
;;
|
2024-06-10 02:30:58 +00:00
|
|
|
0)
|
2024-06-23 19:23:09 +00:00
|
|
|
# Back out to mode prompt
|
2024-06-10 02:30:58 +00:00
|
|
|
clear
|
2024-06-23 19:23:09 +00:00
|
|
|
mode_prompt
|
2024-06-10 02:30:58 +00:00
|
|
|
;;
|
|
|
|
*)
|
2024-06-23 19:23:09 +00:00
|
|
|
# clear
|
2024-06-10 02:30:58 +00:00
|
|
|
echo "!! Invalid Option !!"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|