Compare commits

...

2 Commits

2 changed files with 153 additions and 47 deletions

View File

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

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

@ -1,41 +1,141 @@
#!/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
DATE=$(date +"%Y-%m-%d_%H-%M")
current_date=$(date +"%Y-%m-%d_%H-%M")
# Form the filename
FILENAME="TL-$DATE.jpg"
out_filename="TL-$current_date.jpg"
# Concat the file path parts into one variable
output_path="${output_dir}/${out_filename}"
# Functions
# Capture an image and save it locally
capture() {
# Capture an image for the timelapse and save it to /tmp/TL-YYYY-MM-DD_HH-MM.jpg
echo "Capturing image and saving it to $IMG_DIR/$FILENAME"
fswebcam -r "$RESOLUTION" -d "$DEVICE" "$IMG_DIR/$FILENAME" -F 1 -S 5
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
}
# Sync images from local to a remote mounted storage device
sync() {
echo "Syncing $IMG_DIR to $NAS_MOUNT_DIR$SYNC_DES_PATH..."
rsync -av --progress --remove-source-files "$IMG_DIR/" "$NAS_MOUNT_DIR$SYNC_DES_PATH/" $1
if [[ $? -eq 0 ]]; then
echo "Success"
# 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 "Unable to complete sync. Exiting"
echo "Sync Directory: $sync_dir"
fi
fi
##################################################
# Functions
##################################################
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() {
echo -e "Capturing image and saving it to $output_path"
fswebcam -r "$resolution" -d "$device" "$output_path" -F $frames -S $skips
}
sync() {
echo "Syncing $output_dir to $remote_dir..."
rsync -av --progress --remove-source-files "$output_path" "$remote_dir/" $1
if [[ $? -eq 0 ]]; then
echo -e "Success"
else
echo -e "Unable to complete sync. Exiting"
exit 1
fi
}
# Actually run everything
# Calling functions
# If needed, check for root
if [[ $root_only == true ]]; then
check_for_root
fi
capture
sync
# If needed, sync the image to remote storage
if [[ $remote_sync == true ]]; then
sync
fi