v0.0.28 Functions, needs safeties and error handling for v0.1.0
This commit is contained in:
parent
82ea2f7b36
commit
e9afba5675
@ -1,112 +1,259 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
###########################################################
|
|
||||||
|
######################################################################################
|
||||||
# Name: Camera Ingest Script
|
# Name: Camera Ingest Script
|
||||||
# Author: voidf1sh (Skylar Grant)
|
# Author: voidf1sh (Skylar Grant)
|
||||||
# Environment: M1 MacBook Pro
|
# Environment: M1 MacBook Pro
|
||||||
#
|
#
|
||||||
# Mounts:
|
# Mounts:
|
||||||
# Camera SD: /Volumes/NO NAME
|
# Camera SD: /dev/diskXsY (varies) -- /Volumes/NO NAME
|
||||||
# NAS: //GUEST:@192.168.0.2/media -- /Volumes/media or /Volumes/media-1
|
# NAS: //GUEST:@192.168.0.2/media -- /Volumes/media or /Volumes/media-1 (varies)
|
||||||
#
|
#
|
||||||
# Git: https://git.vfsh.dev/voidf1sh/custom-scripts
|
# Git: https://git.vfsh.dev/voidf1sh/custom-scripts
|
||||||
# File: cam-ingest-mac.sh
|
# File: cam-ingest-mac.sh
|
||||||
# Version: 0.0.1
|
# Version: 0.0.28
|
||||||
###########################################################
|
######################################################################################
|
||||||
|
|
||||||
# Some initial variables to work with
|
# Some initial variables to work with
|
||||||
# Set the date for folder creation
|
# Set the date for folder creation
|
||||||
CURRENT_DATE=$(date +%F)
|
CURRENT_DATE=$(date +%F)
|
||||||
|
|
||||||
|
# Paths
|
||||||
|
# IMPORTANT: Paths should NEVER have trailing slashes, and ALWAYS have leading slashes
|
||||||
|
# Camera's path to images
|
||||||
SD_SRC_PATH="/DCIM/100MSDCF"
|
SD_SRC_PATH="/DCIM/100MSDCF"
|
||||||
MAC_INGEST_PATH="/Users/voidf1sh/Pictures/Camera Ingest"
|
# Where to ingest to on the Mac
|
||||||
NAS_INGEST_PATH="/Camera Ingest"
|
MAC_INGEST_PATH="$HOME/Pictures/Camera Ingest/$CURRENT_DATE"
|
||||||
|
# Where to ingest to on the NAS
|
||||||
|
NAS_INGEST_PATH="/Camera Ingest/$CURRENT_DATE"
|
||||||
|
# NAS Network Address
|
||||||
|
NAS_ADDRESS="//GUEST:@192.168.0.2/media"
|
||||||
|
|
||||||
# TODO: Move this to after initiating Mac->NAS Ingest
|
######################################################################################
|
||||||
# Check if the NAS is mounted
|
# Functions
|
||||||
if mount | grep -q "//GUEST:@192.168.0.2/media"; then
|
######################################################################################
|
||||||
# Get the NAS mount point since it can vary
|
|
||||||
NAS_MOUNT_POINT=$(mount | grep "media" | awk '{print $3}' | grep -E '^/Volumes/media(-1)?$')
|
|
||||||
echo "NAS Mounted at $NAS_MOUNT_POINT."
|
|
||||||
else
|
|
||||||
echo "ERR: NAS Not mounted!"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
# TODO: Maybe move this to after initiating SD->Mac Ingest
|
# Create and open Mac folders.
|
||||||
# Check if the SD card is mounted
|
create_folders_mac() {
|
||||||
if mount | grep -q "/Volumes/NO NAME"; then
|
# Check if the parent ingest directory doesn't exist
|
||||||
# Get the SD Card mount point, this is static though
|
if [[ ! -d "$MAC_INGEST_PATH" ]]; then
|
||||||
SD_MOUNT_POINT="/Volumes/NO NAME"
|
echo "Creating ingest directories at $MAC_INGEST_PATH/{ARW,JPG,MP4}..."
|
||||||
echo "SD Card Mounted at $SD_MOUNT_POINT."
|
# Since the parent doesn't exist, we create it and all children at once
|
||||||
else
|
mkdir -p "$MAC_INGEST_PATH"/{ARW,JPG,MP4}
|
||||||
echo "ERR: SD Card Not mounted!"
|
# $? is the exit status of the last commmand, with 0 being success
|
||||||
exit
|
if [[ $? -eq 0 ]]; then
|
||||||
fi
|
echo "Success!"
|
||||||
|
else
|
||||||
|
echo "Failed to create directories 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
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create and open NAS folders.
|
||||||
|
create_folders_nas() {
|
||||||
|
# Check if the parent ingest directory doesn't exist
|
||||||
|
if [[ ! -d "$NAS_MOUNT_POINT/$NAS_INGEST_PATH" ]]; then
|
||||||
|
echo "Creating ingest directories at $NAS_INGEST_PATH/{ARW,JPG,MP4}..."
|
||||||
|
# Since the parent doesn't exist, we create it and all children at once
|
||||||
|
mkdir -p "$NAS_MOUNT_POINT/$NAS_INGEST_PATH"/{ARW,JPG,MP4}
|
||||||
|
# $? 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 $NAS_MOUNT_POINT/$NAS_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 "$NAS_MOUNT_POINT/$NAS_INGEST_PATH/$folder" ]]; then
|
||||||
|
echo "Subdirectory $folder is missing, creating..."
|
||||||
|
# Create the missing subdir
|
||||||
|
mkdir -p "$NAS_MOUNT_POINT/$NAS_INGEST_PATH/$folder"
|
||||||
|
# $? is the exit status of the last commmand, with 0 being success
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
echo "Successfully created $NAS_MOUNT_POINT/$NAS_INGEST_PATH/$folder"
|
||||||
|
else
|
||||||
|
echo "Failed to create $NAS_MOUNT_POINT/$NAS_INGEST_PATH/$folder"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Cleanup non-RAW images on camera.
|
||||||
|
clean_sd() {
|
||||||
|
echo "Traversing to Camera..."
|
||||||
|
cd "$SD_MOUNT_POINT/$SD_SRC_PATH"
|
||||||
|
echo "Removing JPG files..."
|
||||||
|
rm *.JPG
|
||||||
|
echo "Cleanup completed!"
|
||||||
|
cd -
|
||||||
|
}
|
||||||
|
|
||||||
|
# Camera->Mac Ingest
|
||||||
|
ingest_mac() {
|
||||||
|
# Check if the SD card is mounted
|
||||||
|
if mount | grep -q "/Volumes/NO NAME"; then
|
||||||
|
# Get the SD Card mount point, this is static though
|
||||||
|
SD_MOUNT_POINT="/Volumes/NO NAME"
|
||||||
|
echo "SD Card Mounted at $SD_MOUNT_POINT."
|
||||||
|
else
|
||||||
|
echo "ERR: SD Card Not mounted!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
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."
|
||||||
|
fi
|
||||||
|
echo "Ingest complete!"
|
||||||
|
open "$MAC_INGEST_PATH"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Mac->NAS Ingest
|
||||||
|
ingest_nas() {
|
||||||
|
# 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)?$')
|
||||||
|
echo "NAS Mounted at $NAS_MOUNT_POINT."
|
||||||
|
else
|
||||||
|
echo "ERR: NAS Not mounted!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
create_folders_nas
|
||||||
|
echo "Beginning copy..."
|
||||||
|
|
||||||
|
# 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/"
|
||||||
|
else
|
||||||
|
echo "No JPGs, skipping."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Copy ARW files
|
||||||
|
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/"
|
||||||
|
else
|
||||||
|
echo "No ARWs, skipping."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Copy MP4 files
|
||||||
|
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/"
|
||||||
|
else
|
||||||
|
echo "No MP4s, skipping."
|
||||||
|
fi
|
||||||
|
echo "Ingest complete!"
|
||||||
|
open "$NAS_MOUNT_POINT/$NAS_INGEST_PATH"
|
||||||
|
}
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
# Prompt Loop
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
# Initial Prompt
|
|
||||||
# Bash allows for linebreaks in string literals and will
|
# Bash allows for linebreaks in string literals and will
|
||||||
# break lines accordingly in the shell
|
# break lines accordingly in the shell
|
||||||
echo -e "
|
while true; do
|
||||||
[ Camera Ingest Script ]
|
echo ""
|
||||||
|
echo "[ Camera Ingest Script ]"
|
||||||
|
echo ""
|
||||||
|
echo "Please enter an option from below:"
|
||||||
|
echo ""
|
||||||
|
echo "[1] Camera->Mac Ingest"
|
||||||
|
echo "[2] Mac->NAS Ingest"
|
||||||
|
echo "[X] Cleanup non-RAW images on camera."
|
||||||
|
echo ""
|
||||||
|
echo "[0] Exit"
|
||||||
|
|
||||||
This script is being run from: '$(pwd)'
|
# Wait for input
|
||||||
|
read -p "Option: " opt
|
||||||
|
|
||||||
Please enter an option from below:
|
# Execute the correct commands based on input.
|
||||||
|
case "$opt" in
|
||||||
[1] Create and open folders.
|
1)
|
||||||
[2] Cleanup non-RAW images on camera.
|
# Camera->Mac Ingest
|
||||||
[3] Camera->Mac Ingest
|
clear
|
||||||
[4] Mac->NAS Ingest
|
ingest_mac
|
||||||
|
;;
|
||||||
[0] Exit
|
2)
|
||||||
"
|
# Mac->NAS Ingest
|
||||||
|
clear
|
||||||
|
ingest_nas
|
||||||
# Wait for input
|
;;
|
||||||
read -p " Option: " opt
|
3)
|
||||||
|
# Cleanup non-RAW images on camera.
|
||||||
# Execute the correct commands based on input.
|
clear
|
||||||
case "$opt" in
|
echo "Temporarily disabled!"
|
||||||
1)
|
# clean_sd
|
||||||
# Create and open folders.
|
;;
|
||||||
clear
|
0)
|
||||||
echo "Sike, this does nothing right now."
|
# Exit the script
|
||||||
;;
|
echo "!! Quitting !!"
|
||||||
2)
|
sleep 0.8s
|
||||||
# Cleanup non-RAW images on camera.
|
clear
|
||||||
clear
|
exit
|
||||||
echo "Traversing to Camera..."
|
;;
|
||||||
cd "$SD_MOUNT_POINT/$SD_SRC_PATH"
|
*)
|
||||||
echo "Removing JPG files..."
|
clear
|
||||||
rm *.JPG
|
echo "!! Invalid Option !!"
|
||||||
echo "Cleanup completed!"
|
;;
|
||||||
cd -
|
esac
|
||||||
;;
|
done
|
||||||
3)
|
|
||||||
# Camera->Mac Ingest
|
|
||||||
clear
|
|
||||||
echo "Beginning copy..."
|
|
||||||
echo "Copying JPGs..."
|
|
||||||
rsync -avz --progress "$SD_MOUNT_POINT$SD_SRC_PATH/"*.JPG "$MAC_INGEST_PATH/JPG/"
|
|
||||||
echo "Copying ARWs..."
|
|
||||||
rsync -avz --progress "$SD_MOUNT_POINT$SD_SRC_PATH/"*.ARW "$MAC_INGEST_PATH/ARW/"
|
|
||||||
echo "Ingest complete!"
|
|
||||||
open $MAC_INGEST_PATH
|
|
||||||
;;
|
|
||||||
4)
|
|
||||||
# Mac->NAS Ingest
|
|
||||||
;;
|
|
||||||
0)
|
|
||||||
# Exit the script
|
|
||||||
echo "!! Quitting !!"
|
|
||||||
sleep 0.4s
|
|
||||||
clear
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
clear
|
|
||||||
echo "!! Invalid Option !!"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Loop the script
|
|
||||||
exec ./backup.sh
|
|
Loading…
Reference in New Issue
Block a user