feat: Add Raspberry Pi webcam capture and upload demo with install/uninstall scripts, config, and README.

This commit is contained in:
sebseb7
2025-12-18 14:14:38 +01:00
parent c1f9c689b7
commit a8e1da9559
5 changed files with 469 additions and 0 deletions

94
demo/install.sh Normal file
View File

@@ -0,0 +1,94 @@
#!/bin/bash
# install.sh - Set up PicUpper webcam capture on Raspberry Pi
# Creates cron job for 1 picture per minute
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CAPTURE_SCRIPT="${SCRIPT_DIR}/capture-upload.sh"
CONFIG_FILE="${SCRIPT_DIR}/picupper.conf"
LOG_FILE="/var/log/picupper.log"
echo "=== PicUpper Installer ==="
echo ""
# Check dependencies
echo "Checking dependencies..."
if ! command -v fswebcam &>/dev/null; then
echo "❌ fswebcam not installed"
echo " Run: sudo apt update && sudo apt install -y fswebcam"
exit 1
fi
echo "✓ fswebcam"
if ! command -v curl &>/dev/null; then
echo "❌ curl not installed"
echo " Run: sudo apt update && sudo apt install -y curl"
exit 1
fi
echo "✓ curl"
# Check config
if [[ ! -f "$CONFIG_FILE" ]]; then
echo ""
echo "❌ Configuration file not found!"
echo " Please create it first:"
echo " cp picupper.conf.example picupper.conf"
echo " nano picupper.conf"
exit 1
fi
echo "✓ Config file exists"
# Check API key is configured
# shellcheck source=/dev/null
source "$CONFIG_FILE"
if [[ -z "${API_KEY:-}" || "$API_KEY" == "your-api-key-here" ]]; then
echo ""
echo "❌ API key not configured in picupper.conf"
echo " Edit the file and set your API key"
exit 1
fi
echo "✓ API key configured"
# Make scripts executable
chmod +x "$CAPTURE_SCRIPT"
chmod +x "${SCRIPT_DIR}/uninstall.sh" 2>/dev/null || true
echo "✓ Scripts are executable"
# Create log file if needed
if [[ ! -f "$LOG_FILE" ]]; then
sudo touch "$LOG_FILE"
sudo chown "$USER:$USER" "$LOG_FILE"
echo "✓ Log file created: $LOG_FILE"
else
echo "✓ Log file exists: $LOG_FILE"
fi
# Set up cron job
CRON_JOB="* * * * * $CAPTURE_SCRIPT >> $LOG_FILE 2>&1"
echo ""
echo "Setting up cron job for 1 picture per minute..."
# Check if cron job already exists
if crontab -l 2>/dev/null | grep -q "$CAPTURE_SCRIPT"; then
echo "⚠ Cron job already exists, skipping"
else
# Add to crontab
(crontab -l 2>/dev/null || true; echo "$CRON_JOB") | crontab -
echo "✓ Cron job added"
fi
echo ""
echo "=== Installation Complete ==="
echo ""
echo "Your Raspberry Pi will now capture a picture every minute."
echo ""
echo "Useful commands:"
echo " View logs: tail -f $LOG_FILE"
echo " Test capture: $CAPTURE_SCRIPT --test"
echo " Run manually: $CAPTURE_SCRIPT"
echo " Uninstall: ${SCRIPT_DIR}/uninstall.sh"
echo ""
echo "To change frequency, edit crontab: crontab -e"