Compare commits

..

No commits in common. "aacaa068b054b3ed8e806a60a7736c3bde15d999" and "ec3112cfedb8350f133df058b243e4e608106536" have entirely different histories.

4 changed files with 56 additions and 54 deletions

View File

@ -11,7 +11,7 @@ fi
# Configuration variables # Configuration variables
# Install directory # Install directory
INSTALL_DIR="/usr/local/bin" INSTALL_DIR="/usr/local/bin"
FILE_LIST=("tl-capture" "tl-control") FILE_LIST=("tl-capture" "tl-clean" "tl-control")
# Copy the executable files # Copy the executable files
for file in ${FILE_LIST[@]}; do for file in ${FILE_LIST[@]}; do

View File

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

3
timelapse/tl-clean Normal file
View File

@ -0,0 +1,3 @@
#!/bin/bash
SYNCED_DIR="/tmp/TL/synced"
rm "$SYNCED_DIR/".*

View File

@ -4,14 +4,15 @@
# 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")
IMG_DIR="/tmp/TL"
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="" # Set by prompt CRON_FREQUENCY="*/15 * * * *" # Every 15 minutes
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="$CRON_FREQUENCY root $INSTALL_DIR/${FILE_LIST[0]} >> $CRON_LOG_PATH 2>&1"
# Paths
SYNC_SRC_PATH="/tmp/TL/to-sync"
SYNC_DES_PATH="/mnt/media/TL/to-process"
# Check for root/sudo # Check for root/sudo
if [ "$EUID" -ne 0 ]; then if [ "$EUID" -ne 0 ]; then
@ -25,25 +26,6 @@ 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
# Make sure the interval is valid 1-59
if [[ "$interval" =~ ^[1-9]$|^[1-5][0-9]$ ]]; then
CRON_FREQUENCY="*/$interval * * * *"
else
echo "Invalid interval!"
return 1
fi
echo "Creating cron file: $CRON_FILE" echo "Creating cron file: $CRON_FILE"
touch "$CRON_FILE" touch "$CRON_FILE"
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
@ -55,7 +37,7 @@ start_tl() {
echo -e "Writing job to file: $CRON_FILE\n$CRON_JOB" echo -e "Writing job to file: $CRON_FILE\n$CRON_JOB"
cat <<EOF > $CRON_FILE cat <<EOF > $CRON_FILE
# Take an image every 15 minutes and save it for a time lapse # Take an image every 15 minutes and save it for a time lapse
$CRON_FREQUENCY $CRON_JOB $CRON_JOB
EOF EOF
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
echo "Success" echo "Success"
@ -79,8 +61,8 @@ stop_tl() {
# NAS Sync # NAS Sync
sync_nas() { sync_nas() {
echo "Syncing $IMG_DIR to $SYNC_DES_PATH..." echo "Syncing $SYNC_SRC_PATH to $SYNC_DES_PATH..."
rsync -av --progress --remove-source-files "$IMG_DIR" "$SYNC_DES_PATH" $1 rsync -av --progress --remove-source-files "$SYNC_SRC_PATH" "$SYNC_DES_PATH" $1
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
echo "Success" echo "Success"
else else