#!/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="${SCRIPT_DIR}/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" # Touch log file to ensure it exists touch "$LOG_FILE" 2>/dev/null || true echo "✓ Log file: $LOG_FILE" # 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"