Compare commits

..

No commits in common. "aac1bc5c881b85f1d430bfb74d633e1c2717099e" and "aa10b1ea0d2a0f78cc00f9d372e1f9e9da006b51" have entirely different histories.

2 changed files with 43 additions and 149 deletions

View File

@ -133,27 +133,6 @@ create_folders_mac() {
fi fi
} }
# Check if the SD card is mounted
check_sd() {
if mount | grep -q "${SD_MOUNT_POINT[$INGEST_MODE]}"; then
touch /tmp/mounted
else
echo "ERR: SD Card Not mounted!"
exit 1
fi
}
# Check if the NAS is mounted
check_nas() {
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
}
# Cleanup images on camera SD. # Cleanup images on camera SD.
# TODO: Update this for the new combined script # TODO: Update this for the new combined script
clean_sd() { clean_sd() {
@ -244,7 +223,6 @@ ingest_mac() {
# Mac->NAS Sync # Mac->NAS Sync
ingest_nas() { ingest_nas() {
check_nas
local dry_run="" local dry_run=""
# Detect if dry run # Detect if dry run
if [[ $1 -eq 1 ]]; then if [[ $1 -eq 1 ]]; then
@ -267,7 +245,22 @@ ingest_nas() {
# Check for Connections # Check for Connections
###################################################################################### ######################################################################################
check_sd # Check if the SD card is mounted
if mount | grep -q "${SD_MOUNT_POINT[$INGEST_MODE]}"; then
touch /tmp/mounted
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 # Mode Prompt
@ -329,7 +322,8 @@ while true; do
4) 4)
# !! Delete ALL media on SD card!! # !! Delete ALL media on SD card!!
clear clear
clean_sd # clean_sd
echo "Untested and not working yet!"
;; ;;
5) 5)
# !! Delete ALL ingested media on Mac!! # !! Delete ALL ingested media on Mac!!

148
timelapse/tl-capture Executable file → Normal file
View File

@ -1,141 +1,41 @@
#!/bin/bash #!/bin/bash
# Default status for variables
PROGRAM_NAME=$(basename "$0")
remote_sync=false # --remote
root_only=false # --root
output_dir="/tmp" # -o
remote_dir="/tmp" # --sync-dir
device="/dev/video0" # fswebcam -d
frames=1 # fswebcam -F
skips=5 # fswebcam -S
# Customizable variables
# Paths
IMG_DIR="/tmp/TL"
NAS_MOUNT_DIR="/mnt/media"
SYNC_DES_PATH="/tl/to-process"
# Command variables
RESOLUTION="1920x1080"
DEVICE="/dev/video0"
FRAMES="1"
SKIPS="5"
# Pre-script configurations
# Generate the date for the filename # Generate the date for the filename
current_date=$(date +"%Y-%m-%d_%H-%M") DATE=$(date +"%Y-%m-%d_%H-%M")
# Form the filename # Form the filename
out_filename="TL-$current_date.jpg" FILENAME="TL-$DATE.jpg"
# Concat the file path parts into one variable
output_path="${output_dir}/${out_filename}"
usage() {
echo -e "usage: $PROGRAM_NAME -r resolution [-o output_dir] [-d device] [-F frames] [-S skips] [--root] [--remote --sync-dir remote_dir]"
echo -e " -r resolution Image resolution, e.g. 1920x1080"
echo -e " -o output_dir Path to image storage directory, default /tmp"
echo -e " -d device Device path to webcam, default /dev/video0"
echo -e " -F frames Number of image frames to capture, default 1"
echo -e " -S skips Number of frames to skip before capturing, default 5"
echo -e " --root Checks if the script is running as root"
echo -e " --remote Enable remote syncing of images, must specify --sync-dir as well"
echo -e " --sync-dir remote_dir Path to remote sync destination"
exit 1
}
# Parse arguments
while [[ "$#" -gt 0 ]]; do
case "$1" in
-r)
resolution="$2"
shift 2
;;
-o)
output_dir="$2"
shift 2
;;
-d)
device="$2"
shift 2
;;
-F)
frames="$2"
shift 2
;;
-S)
skips="$2"
shift 2
;;
--root)
root_only=true
shift
;;
--remote)
remote_sync=true
shift
;;
--sync-dir)
remote_dir="$2"
shift 2
;;
-h|--help)
usage
;;
*)
echo "Unknown option: $1"
usage
;;
esac
done
# Check for required arguments
if [ -z "$resolution" ]; then
echo "Error: resolution is required"
usage
fi
# Implement the behavior based on the flags and options
echo "Resolution: $resolution"
echo "Output Directory: $output_dir"
echo "Device: $device"
echo "Frames: $frames"
echo "Skips: $skips"
echo "Running as Root: $root_only"
echo "Remote Sync: $remote_sync"
if [ "$remote_sync" = true ]; then
if [ -z "$sync_dir" ]; then
echo "Error: --sync-dir must be specified when --remote is used"
usage
else
echo "Sync Directory: $sync_dir"
fi
fi
##################################################
# Functions # Functions
################################################## # Capture an image and save it locally
check_for_root() {
# Check for root/sudo
if [ "$EUID" -ne 0 ]; then
echo "This script must be run as root or with sudo."
exit 1
else
echo "Running as root or with sudo."
fi
}
capture() { capture() {
echo -e "Capturing image and saving it to $output_path" # Capture an image for the timelapse and save it to /tmp/TL-YYYY-MM-DD_HH-MM.jpg
fswebcam -r "$resolution" -d "$device" "$output_path" -F $frames -S $skips echo "Capturing image and saving it to $IMG_DIR/$FILENAME"
fswebcam -r "$RESOLUTION" -d "$DEVICE" "$IMG_DIR/$FILENAME" -F 1 -S 5
} }
# Sync images from local to a remote mounted storage device
sync() { sync() {
echo "Syncing $output_dir to $remote_dir..." echo "Syncing $IMG_DIR to $NAS_MOUNT_DIR$SYNC_DES_PATH..."
rsync -av --progress --remove-source-files "$output_path" "$remote_dir/" $1 rsync -av --progress --remove-source-files "$IMG_DIR/" "$NAS_MOUNT_DIR$SYNC_DES_PATH/" $1
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
echo -e "Success" echo "Success"
else else
echo -e "Unable to complete sync. Exiting" echo "Unable to complete sync. Exiting"
exit 1 exit 1
fi fi
} }
# Calling functions # Actually run everything
# If needed, check for root
if [[ $root_only == true ]]; then
check_for_root
fi
capture capture
# If needed, sync the image to remote storage
if [[ $remote_sync == true ]]; then
sync sync
fi