Initial testing
This commit is contained in:
parent
d04c38a6ed
commit
0ba691f82a
41
timelapse/install.sh
Normal file
41
timelapse/install.sh
Normal file
@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 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
|
||||
|
||||
# Configuration variables
|
||||
# Install directory
|
||||
INSTALL_DIR="/usr/local/bin"
|
||||
FILE_LIST=("tl-capture" "tl-clean" "tl-control")
|
||||
|
||||
# Copy the executable files
|
||||
for file in ${FILE_LIST[@]}; do
|
||||
echo "Copying $file to $INSTALL_DIR..."
|
||||
cp "./$file" $INSTALL_DIR
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo "Done."
|
||||
else
|
||||
echo "Unable to copy the file. Exiting"
|
||||
exit 1
|
||||
fi
|
||||
echo "Setting executable status on $file..."
|
||||
chmod +x "$INSTALL_DIR/$file"
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo "Done."
|
||||
else
|
||||
echo "Unable to set the executable bit. Exiting"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
# Set up the cron job
|
||||
|
||||
|
||||
# Wrap up
|
||||
echo "Install complete, press any key to exit..."
|
||||
read -n 1 -s
|
55
timelapse/tl-capture
Normal file
55
timelapse/tl-capture
Normal file
@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
# Customizable variables
|
||||
# Device
|
||||
$DEVICE="/dev/video0"
|
||||
# Temporary output directory
|
||||
$TO_SYNC_DIR="/tmp/TL/tosync"
|
||||
$SYNCED_DIR="/tmp/TL/synced"
|
||||
# NAS Info
|
||||
$NAS_MOUNT_DIR="/mnt/media"
|
||||
$NAS_SYNC_DIR="/TL/synced"
|
||||
|
||||
# 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
|
||||
}
|
3
timelapse/tl-clean
Normal file
3
timelapse/tl-clean
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
SYNCED_DIR="/tmp/TL/synced"
|
||||
rm "$SYNCED_DIR/".*
|
135
timelapse/tl-control
Normal file
135
timelapse/tl-control
Normal file
@ -0,0 +1,135 @@
|
||||
#!/bin/bash
|
||||
# Interactive front end for timelapse on Pi via webcam
|
||||
|
||||
# Configuration Variables
|
||||
# Cron
|
||||
CRON_DIR="/etc/cron.d"
|
||||
CRON_FILE="$CRON_DIR/timelapse"
|
||||
CRON_FREQUENCY="*/15 * * * *" # Every 15 minutes
|
||||
CRON_LOG_PATH="/var/log/${FILE_LIST[0]}.log"
|
||||
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="/media/mnt/TL/to-process"
|
||||
|
||||
# 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
|
||||
|
||||
# Functions
|
||||
|
||||
# Start Time Lapse
|
||||
start_tl() {
|
||||
echo "Creating cron file: $CRON_FILE"
|
||||
touch "$CRON_FILE"
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo "Success"
|
||||
else
|
||||
echo "Unable to create the file. Exiting"
|
||||
exit 1
|
||||
fi
|
||||
echo -e "Writing job to file: $CRON_FILE\n$CRON_JOB"
|
||||
cat <<EOF > $CRON_FILE
|
||||
# Take an image every 15 minutes and save it for a time lapse
|
||||
$CRON_JOB
|
||||
EOF
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo "Success"
|
||||
else
|
||||
echo "Unable to write to the file. Exiting"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Stop Time Lapse
|
||||
stop_tl() {
|
||||
echo "Removing cron file: $CRON_FILE"
|
||||
rm $CRON_FILE
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo "Success"
|
||||
else
|
||||
echo "Unable to remove to the file. Exiting"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# NAS Sync
|
||||
sync_nas() {
|
||||
echo "Syncing $SYNC_SRC_PATH to $SYNC_DES_PATH..."
|
||||
rsync -av --progress --remove-source-files "$SYNC_SRC_PATH" "$SYNC_DES_PATH" $1
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo "Success"
|
||||
else
|
||||
echo "Unable to complete sync. Exiting"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Delete synced images
|
||||
clean_pi() {
|
||||
echo "Are you sure??"
|
||||
read -n 1 -S
|
||||
echo "Sike!"
|
||||
}
|
||||
|
||||
# Menu Prompt
|
||||
while true; do
|
||||
# Empty the screen
|
||||
# clear
|
||||
# Print the prompt
|
||||
echo "[ Time Lapse Control Panel ]"
|
||||
echo ""
|
||||
echo "[1] Start Time Lapse"
|
||||
echo "[2] Stop Time Lapse"
|
||||
echo "[3] Dry Run Sync to NAS"
|
||||
echo "[4] Sync to NAS"
|
||||
echo "[5] !! Delete ALL synced images !!"
|
||||
echo ""
|
||||
echo "[0] Exit"
|
||||
|
||||
# Wait for input
|
||||
read -p "Option: " opt
|
||||
|
||||
# Execute the correct commands based on input.
|
||||
case "$opt" in
|
||||
1)
|
||||
# Start Time Lapse
|
||||
clear
|
||||
start_tl
|
||||
;;
|
||||
2)
|
||||
# Stop Time Lapse
|
||||
clear
|
||||
stop_tl
|
||||
;;
|
||||
3)
|
||||
# Dry Run NAS Sync
|
||||
clear
|
||||
sync_nas --dry-run
|
||||
# echo "Untested and not working yet!"
|
||||
;;
|
||||
4)
|
||||
# NAS Sync
|
||||
clear
|
||||
sync_nas
|
||||
;;
|
||||
5)
|
||||
# !! Delete ALL synced images on Pi !!
|
||||
clear
|
||||
clean_pi
|
||||
;;
|
||||
0)
|
||||
# Exit
|
||||
clear
|
||||
exit
|
||||
;;
|
||||
*)
|
||||
# clear
|
||||
echo "!! Invalid Option !!"
|
||||
;;
|
||||
esac
|
||||
done
|
Loading…
Reference in New Issue
Block a user