custom-scripts/timelapse/tl-capture

58 lines
1.4 KiB
Plaintext
Raw Normal View History

2024-06-24 21:40:34 +00:00
#!/bin/bash
# Customizable variables
# Device
2024-06-24 22:28:23 +00:00
DEVICE="/dev/video0"
2024-06-24 21:40:34 +00:00
# Temporary output directory
2024-06-24 22:28:23 +00:00
TO_SYNC_DIR="/tmp/TL/to-sync"
SYNCED_DIR="/tmp/TL/synced"
2024-06-24 21:40:34 +00:00
# NAS Info
2024-06-24 22:28:23 +00:00
NAS_MOUNT_DIR="/mnt/media"
NAS_SYNC_DIR="/TL/synced"
2024-06-24 21:40:34 +00:00
# Pre-script configurations
# Generate the date for the filename
DATE=$(date +"%Y-%m-%d_%H-%M")
# Form the filename
FILENAME="TL-$DATE.jpg"
# Functions
setup_dirs() {
# Check if To-Sync Directory exists and create it if not
if [[ ! -d $TO_SYNC_DIR ]]; then
echo "To-Sync directory doesn't exist, creating it now..."
mkdir -p $TO_SYNC_DIR
if [[ $? -eq 0 ]]; then
echo "Success!"
else
echo "Unable to create directory, exiting!"
exit 1
fi
fi
# Check of Synced Directory exists and create it if not
if [[ ! -d $SYNCED_DIR ]]; then
echo "Synced directory doesn't exist, creating it now..."
mkdir -p $SYNCED_DIR
if [[ $? -eq 0 ]]; then
echo "Success!"
else
echo "Unable to create directory, exiting!"
exit 1
fi
fi
}
capture() {
# Capture an image for the timelapse and save it to /tmp/TL-YYYY-MM-DD_HH-MM.jpg
fswebcam -r 1920x1080 -d /dev/video0 /tmp/TL/to-sync/TL-${date}.jpg -F 1 -S 5
}
sync() {
local src="$TO_SYNC_DIR/"
# Sync TL images from Pi to NAS
rsync -avz
2024-06-24 21:43:33 +00:00
}
2024-06-24 22:29:23 +00:00
setup_dirs
2024-06-24 21:43:33 +00:00
capture