Added variables, moved setup to tl-control

This commit is contained in:
Skylar Grant 2024-06-25 10:00:32 -04:00
parent 24151bd87b
commit aacaa068b0
2 changed files with 39 additions and 45 deletions

View File

@ -1,13 +1,15 @@
#!/bin/bash #!/bin/bash
# Customizable variables # Customizable variables
# Device # Paths
DEVICE="/dev/video0" IMG_DIR="/tmp/TL"
# Temporary output directory
TO_SYNC_DIR="/tmp/TL/to-sync"
SYNCED_DIR="/tmp/TL/synced"
# NAS Info
NAS_MOUNT_DIR="/mnt/media" NAS_MOUNT_DIR="/mnt/media"
NAS_SYNC_DIR="/TL/synced" SYNC_DES_PATH="/TL/synced"
# Command variables
RESOLUTION="1920x1080"
DEVICE="/dev/video0"
FRAMES="1"
SKIPS="5"
# Pre-script configurations # Pre-script configurations
# Generate the date for the filename # Generate the date for the filename
@ -16,43 +18,24 @@ DATE=$(date +"%Y-%m-%d_%H-%M")
FILENAME="TL-$DATE.jpg" FILENAME="TL-$DATE.jpg"
# Functions # Functions
# Capture an image and save it locally
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() {
# Capture an image for the timelapse and save it to /tmp/TL-YYYY-MM-DD_HH-MM.jpg # Capture an image for the timelapse and save it to /tmp/TL-YYYY-MM-DD_HH-MM.jpg
fswebcam -r 1920x1080 -d /dev/video0 $TO_SYNC_DIR/$FILENAME.jpg -F 1 -S 5 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() {
local src="$TO_SYNC_DIR/" echo "Syncing $IMG_DIR to $SYNC_DES_PATH..."
# Sync TL images from Pi to NAS rsync -av --progress --remove-source-files "$IMG_DIR/" "$NAS_MOUNT_DIR$SYNC_DES_PATH/" $1
rsync -avz if [[ $? -eq 0 ]]; then
echo "Success"
else
echo "Unable to complete sync. Exiting"
exit 1
fi
} }
setup_dirs # Actually run everything
capture capture
sync

View File

@ -4,12 +4,12 @@
# Configuration Variables # Configuration Variables
INSTALL_DIR="/usr/local/bin" INSTALL_DIR="/usr/local/bin"
FILE_LIST=("tl-capture" "tl-clean" "tl-control") FILE_LIST=("tl-capture" "tl-clean" "tl-control")
SYNC_SRC_PATH="/tmp/TL/to-sync" IMG_DIR="/tmp/TL"
SYNC_DES_PATH="/mnt/media/TL/to-process" SYNC_DES_PATH="/mnt/media/TL/to-process"
# Cron # Cron
CRON_DIR="/etc/cron.d" CRON_DIR="/etc/cron.d"
CRON_FILE="$CRON_DIR/timelapse" CRON_FILE="$CRON_DIR/timelapse"
CRON_FREQUENCY="*/15 * * * *" # Set by prompt CRON_FREQUENCY="" # Set by prompt
CRON_LOG_PATH="/var/log/${FILE_LIST[0]}.log" CRON_LOG_PATH="/var/log/${FILE_LIST[0]}.log"
CRON_JOB="root $INSTALL_DIR/${FILE_LIST[0]} >> $CRON_LOG_PATH 2>&1" CRON_JOB="root $INSTALL_DIR/${FILE_LIST[0]} >> $CRON_LOG_PATH 2>&1"
@ -25,6 +25,17 @@ fi
# Start Time Lapse # Start Time Lapse
start_tl() { start_tl() {
# Check if image directory exists and create if not
if [[ ! -d $IMG_DIR ]]; then
echo "Image directory doesn't exist, creating it now..."
mkdir -p $IMG_DIR
if [[ $? -eq 0 ]]; then
echo "Success!"
else
echo "Unable to create directory, exiting!"
exit 1
fi
fi
read -p "Image interval in minutes (1-59): " interval read -p "Image interval in minutes (1-59): " interval
# Make sure the interval is valid 1-59 # Make sure the interval is valid 1-59
if [[ "$interval" =~ ^[1-9]$|^[1-5][0-9]$ ]]; then if [[ "$interval" =~ ^[1-9]$|^[1-5][0-9]$ ]]; then
@ -68,8 +79,8 @@ stop_tl() {
# NAS Sync # NAS Sync
sync_nas() { sync_nas() {
echo "Syncing $SYNC_SRC_PATH to $SYNC_DES_PATH..." echo "Syncing $IMG_DIR to $SYNC_DES_PATH..."
rsync -av --progress --remove-source-files "$SYNC_SRC_PATH" "$SYNC_DES_PATH" $1 rsync -av --progress --remove-source-files "$IMG_DIR" "$SYNC_DES_PATH" $1
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
echo "Success" echo "Success"
else else