summaryrefslogtreecommitdiff
path: root/Biz/Kidcam/deploy.sh
diff options
context:
space:
mode:
authorBen Sima <ben@bensima.com>2025-12-26 13:34:32 -0500
committerBen Sima <ben@bensima.com>2025-12-26 13:34:32 -0500
commit27d2e3b42d290e72f8ee5735fcd5c73dcaed4517 (patch)
treedbe31f28a638332e8abd5610bb80e816b2cf45f4 /Biz/Kidcam/deploy.sh
parent84397b5bb87071dacd82b192d1354382768eb54d (diff)
feat(kidcam): complete implementationusr/ben/kidcam
- Detector.py: YOLOv8-nano person detection - Streamer.py: GStreamer HLS video streaming - Notifier.py: Telegram bot notifications - Core.py: State machine orchestration - deploy.sh: Ubuntu deployment script - kidcam.service: systemd unit - Documentation (README, project overview) Includes tests, type hints, follows repo conventions. Fixed Worker.hs missing engineOnToolTrace (jr now builds). Added Python deps: opencv, ultralytics, python-telegram-bot. Amp-Thread-ID: https://ampcode.com/threads/T-019b5bc1-b00a-701f-ab4f-04738e8a733c Co-authored-by: Amp <amp@ampcode.com>
Diffstat (limited to 'Biz/Kidcam/deploy.sh')
-rwxr-xr-xBiz/Kidcam/deploy.sh218
1 files changed, 218 insertions, 0 deletions
diff --git a/Biz/Kidcam/deploy.sh b/Biz/Kidcam/deploy.sh
new file mode 100755
index 0000000..a272482
--- /dev/null
+++ b/Biz/Kidcam/deploy.sh
@@ -0,0 +1,218 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+# Kidcam Deployment Script for Ubuntu 20.04 (Jetson Nano)
+
+readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+readonly PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
+readonly KIDCAM_USER="kidcam"
+readonly INSTALL_DIR="/opt/kidcam"
+readonly CONFIG_DIR="/etc/kidcam"
+readonly VENV_DIR="${INSTALL_DIR}/venv"
+
+log_info() {
+ echo "[INFO] $*" >&2
+}
+
+log_error() {
+ echo "[ERROR] $*" >&2
+}
+
+log_success() {
+ echo "[SUCCESS] $*" >&2
+}
+
+check_system() {
+ log_info "Checking system requirements..."
+
+ if [[ "$(uname -s)" != "Linux" ]]; then
+ log_error "This script requires Linux"
+ exit 1
+ fi
+
+ if [[ "$(uname -m)" != "aarch64" ]]; then
+ log_error "This script is designed for aarch64 (ARM64) architecture"
+ log_error "Found: $(uname -m)"
+ exit 1
+ fi
+
+ if ! grep -q "Ubuntu" /etc/os-release; then
+ log_error "This script is designed for Ubuntu"
+ log_error "Found: $(cat /etc/os-release | grep PRETTY_NAME)"
+ exit 1
+ fi
+
+ if [[ $EUID -ne 0 ]]; then
+ log_error "This script must be run as root (use sudo)"
+ exit 1
+ fi
+
+ log_success "System requirements verified"
+}
+
+create_user() {
+ if id "${KIDCAM_USER}" &>/dev/null; then
+ log_info "User '${KIDCAM_USER}' already exists"
+ else
+ log_info "Creating user '${KIDCAM_USER}'..."
+ useradd --system --no-create-home --shell /usr/sbin/nologin \
+ --comment "Kidcam service account" "${KIDCAM_USER}"
+ usermod -aG video "${KIDCAM_USER}"
+ log_success "User '${KIDCAM_USER}' created"
+ fi
+}
+
+install_system_dependencies() {
+ log_info "Installing system dependencies..."
+
+ apt-get update
+ apt-get install -y \
+ python3 \
+ python3-pip \
+ python3-venv \
+ python3-dev \
+ libopencv-dev \
+ python3-opencv \
+ gstreamer1.0-tools \
+ gstreamer1.0-plugins-base \
+ gstreamer1.0-plugins-good \
+ gstreamer1.0-plugins-bad \
+ gstreamer1.0-plugins-ugly \
+ gstreamer1.0-libav \
+ libgstreamer1.0-dev \
+ libgstreamer-plugins-base1.0-dev \
+ v4l-utils \
+ build-essential \
+ cmake \
+ pkg-config
+
+ log_success "System dependencies installed"
+}
+
+setup_directories() {
+ log_info "Setting up directories..."
+
+ mkdir -p "${INSTALL_DIR}"
+ mkdir -p "${CONFIG_DIR}"
+ mkdir -p "${INSTALL_DIR}/_/tmp"
+
+ log_info "Copying project files..."
+ rsync -av --exclude='_/' --exclude='.git' --exclude='*.pyc' \
+ "${PROJECT_ROOT}/" "${INSTALL_DIR}/"
+
+ chown -R "${KIDCAM_USER}:${KIDCAM_USER}" "${INSTALL_DIR}"
+ chown -R "${KIDCAM_USER}:${KIDCAM_USER}" "${CONFIG_DIR}"
+ chmod 755 "${INSTALL_DIR}"
+ chmod 750 "${CONFIG_DIR}"
+
+ log_success "Directories configured"
+}
+
+setup_python_environment() {
+ log_info "Setting up Python virtual environment..."
+
+ if [[ ! -d "${VENV_DIR}" ]]; then
+ sudo -u "${KIDCAM_USER}" python3 -m venv "${VENV_DIR}"
+ log_success "Virtual environment created"
+ else
+ log_info "Virtual environment already exists"
+ fi
+
+ log_info "Installing Python packages..."
+ sudo -u "${KIDCAM_USER}" "${VENV_DIR}/bin/pip" install --upgrade pip wheel setuptools
+
+ # Install packages with careful dependency management
+ sudo -u "${KIDCAM_USER}" "${VENV_DIR}/bin/pip" install \
+ ultralytics \
+ python-telegram-bot \
+ opencv-python \
+ torch torchvision --index-url https://download.pytorch.org/whl/cpu \
+ numpy \
+ pillow
+
+ log_success "Python packages installed"
+}
+
+create_config() {
+ local config_file="${CONFIG_DIR}/config.env"
+
+ if [[ -f "${config_file}" ]]; then
+ log_info "Config file already exists at ${config_file}"
+ log_info "Skipping config creation. Review existing configuration."
+ else
+ log_info "Creating example configuration..."
+ cat > "${config_file}" <<'EOF'
+# Kidcam Configuration
+# Copy this file to /etc/kidcam/config.env and edit with your values
+
+# Camera device (default: /dev/video0)
+CAMERA_DEVICE=/dev/video0
+
+# RTSP stream port (default: 8554)
+STREAM_PORT=8554
+
+# Person detection confidence threshold (0.0-1.0, default: 0.5)
+DETECTION_CONFIDENCE=0.5
+
+# Cooldown period in minutes after detection (default: 5)
+COOLDOWN_MINUTES=5
+
+# Telegram Bot Configuration
+# Get your bot token from @BotFather on Telegram
+TELEGRAM_BOT_TOKEN=your-bot-token-here
+
+# Get your chat ID by messaging your bot and checking:
+# https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates
+TELEGRAM_CHAT_ID=your-chat-id-here
+
+# Python path for imports
+PYTHONPATH=/opt/kidcam
+EOF
+
+ chown "${KIDCAM_USER}:${KIDCAM_USER}" "${config_file}"
+ chmod 640 "${config_file}"
+
+ log_success "Example config created at ${config_file}"
+ log_info "IMPORTANT: Edit ${config_file} with your Telegram credentials"
+ fi
+}
+
+install_systemd_service() {
+ log_info "Installing systemd service..."
+
+ cp "${SCRIPT_DIR}/kidcam.service" /etc/systemd/system/
+ chmod 644 /etc/systemd/system/kidcam.service
+
+ # Update ExecStart to use virtualenv python
+ sed -i "s|ExecStart=/usr/bin/python3|ExecStart=${VENV_DIR}/bin/python3|" \
+ /etc/systemd/system/kidcam.service
+
+ systemctl daemon-reload
+ systemctl enable kidcam.service
+
+ log_success "Systemd service installed and enabled"
+}
+
+main() {
+ log_info "Starting Kidcam deployment..."
+
+ check_system
+ create_user
+ install_system_dependencies
+ setup_directories
+ setup_python_environment
+ create_config
+ install_systemd_service
+
+ log_success "Deployment complete!"
+ echo ""
+ log_info "Next steps:"
+ echo " 1. Edit /etc/kidcam/config.env with your Telegram credentials"
+ echo " 2. Test camera access: v4l2-ctl --list-devices"
+ echo " 3. Start service: sudo systemctl start kidcam"
+ echo " 4. Check logs: sudo journalctl -u kidcam -f"
+ echo ""
+ log_info "For more information, see ${INSTALL_DIR}/Biz/Kidcam/README.md"
+}
+
+main "$@"