diff --git a/.gitignore b/.gitignore index 82f9275..67240d7 100644 --- a/.gitignore +++ b/.gitignore @@ -160,3 +160,5 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + +.claude/ \ No newline at end of file diff --git a/README.md b/README.md index 30048da..f493e62 100644 --- a/README.md +++ b/README.md @@ -1,59 +1,286 @@ # MultiCam Recording Software -software developed for testing purposes and data collection +A multi-camera recording solution for testing purposes and data collection. +## Table of Contents +- [Prerequisites](#prerequisites) +- [Installation](#installation) +- [Development](#development) +- [Deployment](#deployment) -## Pre-requisites +## Prerequisites -### Gstreamer/V4l2 +### System Requirements +- Linux-based operating system +- GStreamer 1.0 or higher +- Python 3.6 or higher +- V4L2 compatible cameras + +### GStreamer Dependencies + +Install the required GStreamer packages: ```bash sudo apt install -y libx264-dev libjpeg-dev \ -libglib2.0-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \ -gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-plugins-base gstreamer1.0-plugins-good \ -gstreamer1.0-plugins-bad gstreamer1.0-libav libgstreamer-plugins-bad1.0-dev \ -gstreamer1.0-plugins-ugly gstreamer1.0-gl \ -v4l-utils + libglib2.0-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \ + gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-plugins-base \ + gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-libav \ + libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-ugly \ + gstreamer1.0-gl v4l-utils ``` -### Python +## Installation + +### Automated Installation (Recommended) + +The easiest way to install MultiCam is using the automated installer: -Install Python ```bash -sudo apt update -sudo apt upgrade -sudo apt install python3 python3-pip +# Download and extract MultiCam +# Then run the installer +./install.sh ``` -Install Python Packages +**Installation Options:** + ```bash -cd backend/ -pip install -r requirements.txt +# Default installation (to /opt/multicam as current user) +./install.sh + +# Install to custom directory +./install.sh -d /home/$USER/multicam + +# System-wide installation with dedicated user +./install.sh --system-install + +# Custom installation with specific user +./install.sh -d /custom/path -u myuser + +# Create a dedicated system user +./install.sh --create-user + +# Show help +./install.sh --help ``` +The installer will: +- Create the installation directory +- Copy all necessary files +- Set up a Python virtual environment +- Install Python dependencies +- Create configuration files +- Set proper permissions +- Create system symlinks (if possible) + +### Manual Installation + +If you prefer to install manually: + +1. **Update your system:** + ```bash + sudo apt update && sudo apt upgrade + ``` + +2. **Install Python and pip:** + ```bash + sudo apt install python3 python3-pip python3-venv + ``` + +3. **Choose installation directory and copy files:** + ```bash + sudo mkdir -p /opt/multicam + sudo cp -r * /opt/multicam/ + sudo chown -R $USER:$USER /opt/multicam + ``` + +4. **Set up Python environment:** + ```bash + cd /opt/multicam + python3 -m venv .env + source .env/bin/activate + pip install -r requirements.txt + chmod +x run.sh + ``` + ## Development -### Running Backend +### Running MultiCam + +After installation, you can run MultiCam in several ways: + +**If installed with the installer:** +```bash +# From installation directory +cd /opt/multicam # or your custom directory +./run.sh + +# Or using the system symlink (if created) +multicam +``` + +**For development:** +```bash +# From the source directory +python run.py +# or +./run.sh +``` + +### Testing the Installation + +Test your installation: + +```bash +# Check if MultiCam starts without errors +cd /opt/multicam && ./run.sh --test # if supported +# or +cd /opt/multicam && timeout 10 ./run.sh +``` + +## Deployment + +### System Service Setup + +MultiCam can be configured to run as a systemd service that automatically starts on boot. + +#### Automated Service Installation (Recommended) + +After installing MultiCam, use the service installer to create a systemd service: + +```bash +# From the installation directory +cd /opt/multicam # or your installation directory +sudo ./install_service.sh +``` + +The service installer will: +- **Auto-detect** your installation (installed vs development mode) +- Create a properly configured systemd service file +- Use the correct paths and user from your installation +- Install it with appropriate permissions +- Enable the service to start on boot +- Optionally start the service immediately + +**Service Installer Options:** +```bash +sudo ./install_service.sh # Install the service +sudo ./install_service.sh --help # Show help information +sudo ./install_service.sh --uninstall # Remove the service +``` + +**Installation Detection:** +- If run from an installed location (with `.install_config`), uses installation settings +- If run from source directory, uses current directory and user +- Automatically configures paths, users, and permissions + +#### Manual Installation + +If you prefer to set up the service manually: + +1. Create a systemd service file at `/etc/systemd/system/multicam.service`: + + ```ini + [Unit] + Description=MultiCam Recording Service + Documentation=https://github.com/your-repo/MultiCam-Record + After=network.target graphical-session.target + Wants=network.target + + [Service] + Type=simple + User=your-username + Group=your-username + WorkingDirectory=/opt/multicam + ExecStart=/opt/multicam/run.sh + ExecReload=/bin/kill -HUP $MAINPID + Restart=always + RestartSec=10 + TimeoutStartSec=30 + TimeoutStopSec=30 + + # Security settings + NoNewPrivileges=true + PrivateTmp=true + ProtectSystem=strict + ReadWritePaths=/opt/multicam + + # Logging + StandardOutput=journal + StandardError=journal + SyslogIdentifier=multicam + + [Install] + WantedBy=multi-user.target + ``` + +2. Enable and start the service: + ```bash + sudo systemctl daemon-reload + sudo systemctl enable multicam.service + sudo systemctl start multicam.service + ``` + +#### Service Management + +Once installed, use these commands to manage the service: ```bash -python run.py # dev mode +# Check service status +sudo systemctl status multicam.service + +# Start the service +sudo systemctl start multicam.service + +# Stop the service +sudo systemctl stop multicam.service + +# Restart the service +sudo systemctl restart multicam.service + +# View service logs +sudo journalctl -u multicam.service -f + +# Disable service (prevent auto-start) +sudo systemctl disable multicam.service ``` -### Create Services for Booting on Startup +## Uninstallation + +### Complete Removal -#### MultiCam service +To completely remove MultiCam from your system: ```bash -[Unit] -Description=MultiCam Service -After=network.target +# If installed using the installer +sudo /opt/multicam/install.sh --uninstall + +# Or from the original source directory +sudo ./install.sh --uninstall +``` + +This will: +- Stop and remove the systemd service +- Remove the installation directory +- Remove system symlinks +- Remove the dedicated user (if created during installation) + +### Manual Removal + +If you need to remove MultiCam manually: + +```bash +# Stop and disable the service +sudo systemctl stop multicam.service +sudo systemctl disable multicam.service +sudo rm /etc/systemd/system/multicam.service +sudo systemctl daemon-reload + +# Remove installation directory +sudo rm -rf /opt/multicam -[Service] -User=ubuntu -Group=www-data -WorkingDirectory=path_to_multicam_record/MultiCam-Record/src -ExecStart=/usr/bin/python3 path_to_multicam_record/MultiCam-Record/src/run.py +# Remove symlinks +sudo rm -f /usr/local/bin/multicam -[Install] -WantedBy=multi-user.target +# Remove dedicated user (if created) +sudo userdel multicam ``` diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..13cd323 --- /dev/null +++ b/install.sh @@ -0,0 +1,374 @@ +#!/bin/bash + +# MultiCam Recording Software Installer +# This script installs the MultiCam software to a predictable location + +set -e # Exit on any error + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Default configuration +DEFAULT_INSTALL_DIR="/opt/multicam" +DEFAULT_USER="multicam" +CREATE_USER=false +INSTALL_DIR="" +INSTALL_USER="" + +# Function to print colored output +print_status() { + echo -e "${GREEN}[INFO]${NC} $1" +} + +print_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +print_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +print_question() { + echo -e "${BLUE}[QUESTION]${NC} $1" +} + +# Show help +show_help() { + echo "MultiCam Recording Software Installer" + echo "======================================" + echo + echo "Usage: $0 [OPTIONS]" + echo + echo "Options:" + echo " -d, --dir DIR Installation directory (default: $DEFAULT_INSTALL_DIR)" + echo " -u, --user USER User to run the service (default: current user)" + echo " --create-user Create a dedicated system user for the service" + echo " --system-install Install system-wide with dedicated user (same as --create-user -d $DEFAULT_INSTALL_DIR)" + echo " -h, --help Show this help message" + echo + echo "Examples:" + echo " $0 # Install to $DEFAULT_INSTALL_DIR as current user" + echo " $0 -d /home/\$USER/multicam # Install to user's home directory" + echo " $0 --system-install # System-wide installation with dedicated user" + echo " $0 -d /custom/path -u myuser # Custom directory and user" + echo +} + +# Parse command line arguments +parse_args() { + while [[ $# -gt 0 ]]; do + case $1 in + -d|--dir) + INSTALL_DIR="$2" + shift 2 + ;; + -u|--user) + INSTALL_USER="$2" + shift 2 + ;; + --create-user) + CREATE_USER=true + shift + ;; + --system-install) + INSTALL_DIR="$DEFAULT_INSTALL_DIR" + INSTALL_USER="$DEFAULT_USER" + CREATE_USER=true + shift + ;; + -h|--help) + show_help + exit 0 + ;; + *) + print_error "Unknown option: $1" + show_help + exit 1 + ;; + esac + done + + # Set defaults if not specified + if [[ -z "$INSTALL_DIR" ]]; then + INSTALL_DIR="$DEFAULT_INSTALL_DIR" + fi + + if [[ -z "$INSTALL_USER" ]]; then + if [[ "$CREATE_USER" == true ]]; then + INSTALL_USER="$DEFAULT_USER" + else + INSTALL_USER="$(whoami)" + fi + fi +} + +# Check if running as root when needed +check_permissions() { + local needs_root=false + + # Check if we need root for directory creation + local parent_dir=$(dirname "$INSTALL_DIR") + if [[ ! -w "$parent_dir" ]] && [[ ! -d "$INSTALL_DIR" ]]; then + needs_root=true + fi + + # Check if we need root for user creation + if [[ "$CREATE_USER" == true ]]; then + needs_root=true + fi + + if [[ "$needs_root" == true ]] && [[ $EUID -ne 0 ]]; then + print_error "This installation requires root privileges." + print_status "Please run with sudo: sudo $0 $*" + exit 1 + fi +} + +# Create system user if requested +create_system_user() { + if [[ "$CREATE_USER" == true ]]; then + if id "$INSTALL_USER" &>/dev/null; then + print_status "User '$INSTALL_USER' already exists." + else + print_status "Creating system user '$INSTALL_USER'..." + useradd --system --home "$INSTALL_DIR" --shell /bin/bash \ + --comment "MultiCam Recording Service" "$INSTALL_USER" + fi + fi +} + +# Create installation directory +create_install_dir() { + print_status "Creating installation directory: $INSTALL_DIR" + + if [[ ! -d "$INSTALL_DIR" ]]; then + mkdir -p "$INSTALL_DIR" + fi + + # Set ownership + if [[ "$CREATE_USER" == true ]] || [[ "$(whoami)" != "$INSTALL_USER" ]]; then + chown -R "$INSTALL_USER:$INSTALL_USER" "$INSTALL_DIR" + fi + + chmod 755 "$INSTALL_DIR" +} + +# Copy files to installation directory +install_files() { + print_status "Installing MultiCam files..." + + local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + + # Files and directories to copy + local items_to_copy=( + "src/" + "run.py" + "run.sh" + "requirements.txt" + "README.md" + ) + + for item in "${items_to_copy[@]}"; do + if [[ -e "$script_dir/$item" ]]; then + print_status "Copying $item..." + cp -r "$script_dir/$item" "$INSTALL_DIR/" + else + print_warning "Item not found: $item (skipping)" + fi + done + + # Make run.sh executable + chmod +x "$INSTALL_DIR/run.sh" + + # Set ownership + if [[ "$CREATE_USER" == true ]] || [[ "$(whoami)" != "$INSTALL_USER" ]]; then + chown -R "$INSTALL_USER:$INSTALL_USER" "$INSTALL_DIR" + fi +} + +# Create Python virtual environment +setup_python_env() { + print_status "Setting up Python virtual environment..." + + local venv_dir="$INSTALL_DIR/.env" + + # Create virtual environment as the target user + if [[ "$(whoami)" == "$INSTALL_USER" ]]; then + python3 -m venv "$venv_dir" + else + sudo -u "$INSTALL_USER" python3 -m venv "$venv_dir" + fi + + # Install requirements + print_status "Installing Python dependencies..." + if [[ -f "$INSTALL_DIR/requirements.txt" ]]; then + if [[ "$(whoami)" == "$INSTALL_USER" ]]; then + "$venv_dir/bin/pip" install -r "$INSTALL_DIR/requirements.txt" + else + sudo -u "$INSTALL_USER" "$venv_dir/bin/pip" install -r "$INSTALL_DIR/requirements.txt" + fi + else + print_warning "requirements.txt not found, skipping Python dependencies installation" + fi +} + +# Create configuration file with installation paths +create_config() { + print_status "Creating installation configuration..." + + local config_file="$INSTALL_DIR/.install_config" + + cat > "$config_file" << EOF +# MultiCam Installation Configuration +# This file is generated automatically by the installer + +INSTALL_DIR="$INSTALL_DIR" +INSTALL_USER="$INSTALL_USER" +PYTHON_VENV="$INSTALL_DIR/.env" +CREATED_USER="$CREATE_USER" +INSTALL_DATE="$(date)" +EOF + + chmod 644 "$config_file" + if [[ "$(whoami)" != "$INSTALL_USER" ]]; then + chown "$INSTALL_USER:$INSTALL_USER" "$config_file" + fi +} + +# Create symlinks for easy access +create_symlinks() { + print_status "Creating system symlinks..." + + # Create symlink to main script + if [[ -w "/usr/local/bin" ]]; then + ln -sf "$INSTALL_DIR/run.py" "/usr/local/bin/multicam" + chmod +x "/usr/local/bin/multicam" + print_status "Created symlink: /usr/local/bin/multicam" + else + print_warning "Cannot create symlink in /usr/local/bin (no write access)" + fi +} + +# Show installation summary +show_summary() { + echo + print_status "Installation Summary:" + echo " Installation directory: $INSTALL_DIR" + echo " Service user: $INSTALL_USER" + echo " Python virtual env: $INSTALL_DIR/.env" + if [[ "$CREATE_USER" == true ]]; then + echo " Created system user: Yes" + else + echo " Created system user: No" + fi + echo + + print_status "Next Steps:" + echo " 1. Test the installation:" + echo " cd $INSTALL_DIR && ./run.sh" + echo + echo " 2. Install as a system service:" + echo " cd $INSTALL_DIR && sudo ./install_service.sh" + echo + + if [[ -L "/usr/local/bin/multicam" ]]; then + echo " 3. Or run from anywhere using:" + echo " multicam" + echo + fi + + print_status "Installation completed successfully!" +} + +# Uninstall function +uninstall() { + if [[ "$1" == "--uninstall" ]]; then + print_warning "Uninstalling MultiCam Recording Software..." + + # Read configuration if it exists + local config_file="$INSTALL_DIR/.install_config" + if [[ -f "$config_file" ]]; then + source "$config_file" + fi + + # Stop and remove service if it exists + if systemctl is-enabled multicam.service &>/dev/null; then + print_status "Stopping and disabling service..." + systemctl stop multicam.service 2>/dev/null || true + systemctl disable multicam.service 2>/dev/null || true + rm -f /etc/systemd/system/multicam.service + systemctl daemon-reload + fi + + # Remove symlinks + if [[ -L "/usr/local/bin/multicam" ]]; then + rm -f "/usr/local/bin/multicam" + print_status "Removed symlink: /usr/local/bin/multicam" + fi + + # Remove installation directory + if [[ -d "$INSTALL_DIR" ]]; then + rm -rf "$INSTALL_DIR" + print_status "Removed installation directory: $INSTALL_DIR" + fi + + # Remove user if we created it + if [[ -f "$config_file" ]] && [[ "$CREATED_USER" == "true" ]]; then + if id "$INSTALL_USER" &>/dev/null; then + userdel "$INSTALL_USER" 2>/dev/null || true + print_status "Removed system user: $INSTALL_USER" + fi + fi + + print_status "Uninstallation completed!" + exit 0 + fi +} + +# Main installation function +main() { + echo "MultiCam Recording Software Installer" + echo "======================================" + echo + + # Handle uninstall + uninstall "$1" + + # Parse arguments + parse_args "$@" + + # Check permissions + check_permissions "$@" + + # Show configuration + print_status "Installation Configuration:" + echo " Installation directory: $INSTALL_DIR" + echo " Service user: $INSTALL_USER" + echo " Create system user: $CREATE_USER" + echo + + # Confirm installation + read -p "Do you want to proceed with the installation? (y/N): " -n 1 -r + echo + + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + print_status "Installation cancelled." + exit 0 + fi + + # Perform installation steps + create_system_user + create_install_dir + install_files + setup_python_env + create_config + create_symlinks + show_summary +} + +# Run main function with all arguments +main "$@" \ No newline at end of file diff --git a/install_service.sh b/install_service.sh new file mode 100755 index 0000000..d3c1923 --- /dev/null +++ b/install_service.sh @@ -0,0 +1,272 @@ +#!/bin/bash + +# MultiCam Recording Service Installation Script +# This script creates and installs a systemd service for MultiCam Recording Software + +set -e # Exit on any error + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# Configuration +SERVICE_NAME="multicam" +SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service" + +# Detect installation directory and configuration +detect_installation() { + local config_file + local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + + # Check if we're in an installed location + if [[ -f "$script_dir/.install_config" ]]; then + # We're in an installed directory, load config + source "$script_dir/.install_config" + SCRIPT_DIR="$INSTALL_DIR" + INSTALL_USER_CONFIG="$INSTALL_USER" + else + # We're in development directory, use current location + SCRIPT_DIR="$script_dir" + INSTALL_USER_CONFIG="$(whoami)" + fi + + RUN_SCRIPT="${SCRIPT_DIR}/run.sh" +} + +# Function to print colored output +print_status() { + echo -e "${GREEN}[INFO]${NC} $1" +} + +print_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +print_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +# Check if running as root +check_root() { + if [[ $EUID -eq 0 ]]; then + print_error "This script should not be run as root directly." + print_status "Please run as a regular user. The script will prompt for sudo when needed." + exit 1 + fi +} + +# Check if systemd is available +check_systemd() { + if ! command -v systemctl &> /dev/null; then + print_error "systemctl not found. This system doesn't appear to use systemd." + exit 1 + fi +} + +# Check if run.sh exists and is executable +check_run_script() { + if [[ ! -f "$RUN_SCRIPT" ]]; then + print_error "run.sh not found in $SCRIPT_DIR" + print_status "Please make sure you're running this script from the MultiCam project directory." + exit 1 + fi + + if [[ ! -x "$RUN_SCRIPT" ]]; then + print_warning "run.sh is not executable. Making it executable..." + chmod +x "$RUN_SCRIPT" + fi +} + +# Create the systemd service file content +create_service_content() { + local service_user="$INSTALL_USER_CONFIG" + + cat << EOF +[Unit] +Description=MultiCam Recording Service +Documentation=https://github.com/your-repo/MultiCam-Record +After=network.target graphical-session.target +Wants=network.target + +[Service] +Type=simple +User=$service_user +Group=$service_user +WorkingDirectory=$SCRIPT_DIR +ExecStart=$RUN_SCRIPT +ExecReload=/bin/kill -HUP \$MAINPID +Restart=always +RestartSec=10 +TimeoutStartSec=30 +TimeoutStopSec=30 + +# Environment +Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +Environment=HOME=/home/$service_user + +# Security settings +NoNewPrivileges=true +PrivateTmp=true +ProtectSystem=strict +ReadWritePaths=$SCRIPT_DIR + +# Logging +StandardOutput=journal +StandardError=journal +SyslogIdentifier=multicam + +[Install] +WantedBy=multi-user.target +EOF +} + +# Install the service +install_service() { + print_status "Creating systemd service file..." + + # Create temporary file with service content + local temp_service=$(mktemp) + create_service_content > "$temp_service" + + # Copy to systemd directory (requires sudo) + print_status "Installing service file (requires sudo)..." + sudo cp "$temp_service" "$SERVICE_FILE" + sudo chmod 644 "$SERVICE_FILE" + sudo chown root:root "$SERVICE_FILE" + + # Clean up temp file + rm "$temp_service" + + print_status "Reloading systemd daemon..." + sudo systemctl daemon-reload + + print_status "Service installed successfully!" +} + +# Enable and start service +enable_service() { + print_status "Enabling ${SERVICE_NAME} service..." + sudo systemctl enable "$SERVICE_NAME.service" + + echo + read -p "Do you want to start the service now? (y/N): " -n 1 -r + echo + + if [[ $REPLY =~ ^[Yy]$ ]]; then + print_status "Starting ${SERVICE_NAME} service..." + sudo systemctl start "$SERVICE_NAME.service" + + # Check status + sleep 2 + if sudo systemctl is-active --quiet "$SERVICE_NAME.service"; then + print_status "Service started successfully!" + else + print_error "Service failed to start. Checking status..." + sudo systemctl status "$SERVICE_NAME.service" + fi + else + print_status "Service enabled but not started." + print_status "You can start it manually with: sudo systemctl start ${SERVICE_NAME}.service" + fi +} + +# Show service management commands +show_commands() { + echo + print_status "Service Management Commands:" + echo " Start service: sudo systemctl start ${SERVICE_NAME}.service" + echo " Stop service: sudo systemctl stop ${SERVICE_NAME}.service" + echo " Restart service: sudo systemctl restart ${SERVICE_NAME}.service" + echo " Check status: sudo systemctl status ${SERVICE_NAME}.service" + echo " View logs: sudo journalctl -u ${SERVICE_NAME}.service -f" + echo " Disable service: sudo systemctl disable ${SERVICE_NAME}.service" + echo +} + +# Uninstall service (if requested) +uninstall_service() { + if [[ "$1" == "--uninstall" ]]; then + print_warning "Uninstalling ${SERVICE_NAME} service..." + + # Stop and disable service + sudo systemctl stop "$SERVICE_NAME.service" 2>/dev/null || true + sudo systemctl disable "$SERVICE_NAME.service" 2>/dev/null || true + + # Remove service file + sudo rm -f "$SERVICE_FILE" + sudo systemctl daemon-reload + + print_status "Service uninstalled successfully!" + exit 0 + fi +} + +# Main function +main() { + echo "MultiCam Recording Service Installer" + echo "======================================" + echo + + # Handle uninstall + uninstall_service "$1" + + # Show help + if [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]]; then + echo "Usage: $0 [OPTIONS]" + echo + echo "Options:" + echo " --help, -h Show this help message" + echo " --uninstall Uninstall the service" + echo + echo "This script will:" + echo " 1. Auto-detect MultiCam installation (installed vs development)" + echo " 2. Create a systemd service file for MultiCam Recording" + echo " 3. Install it to /etc/systemd/system/" + echo " 4. Enable the service to start on boot" + echo " 5. Optionally start the service immediately" + echo + exit 0 + fi + + # Detect installation + detect_installation + + # Run checks + check_root + check_systemd + check_run_script + + # Show current configuration + print_status "Configuration:" + echo " Service name: ${SERVICE_NAME}" + echo " Working directory: ${SCRIPT_DIR}" + echo " Executable: ${RUN_SCRIPT}" + echo " Service user: ${INSTALL_USER_CONFIG}" + if [[ -f "${SCRIPT_DIR}/.install_config" ]]; then + echo " Installation type: Installed" + else + echo " Installation type: Development" + fi + echo + + # Confirm installation + read -p "Do you want to proceed with the installation? (y/N): " -n 1 -r + echo + + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + print_status "Installation cancelled." + exit 0 + fi + + # Install and enable service + install_service + enable_service + show_commands + + print_status "Installation complete!" +} + +# Run main function with all arguments +main "$@" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2532ca7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +eventemitter==0.2.0 +natsort==8.4.0 \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..ab5cf46 --- /dev/null +++ b/run.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) + +cd ${SCRIPT_DIR} + +.env/bin/python3 run.py diff --git a/src/__init__.py b/src/__init__.py index ca94a85..c036cf2 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -11,6 +11,8 @@ from .util import createDirectory, get_current_timestamp, sys_less_than_x_mb_left, load_multicam_config CURRENT_USER = os.getenv('USER') +if CURRENT_USER == None: + CURRENT_USER = 'dwe' VIDEO_DIRECTORY = f'/home/{CURRENT_USER}/Videos/DeepWaterVideos/' def list_diff(listA, listB): @@ -88,7 +90,7 @@ def monitor(): current_time = time.time() record_period = config.recording_length_seconds - record_interval_minutes = config.recording_interval_minutes + record_interval_seconds = config.recording_interval_seconds width = config.resolution_width framerate = config.framerate @@ -108,13 +110,13 @@ def monitor(): # the recording period is over if is_recording and current_recording_length >= record_period: - logging.info(f'Record period is over, starting next recording in {record_interval_minutes} minutes') + logging.info(f'Record period is over, starting next recording in {record_interval_seconds} seconds') stop_streams() recording_end_time = time.time() is_recording = False # the recording should start now - if not is_recording and current_recording_length >= record_interval_minutes * 60: + if not is_recording and current_recording_length >= record_interval_seconds: logging.info(f'Recording period starting now, which will end in {record_period} seconds') start_streams() recording_start_time = time.time() diff --git a/src/config.json b/src/config.json index d66f1c2..22c05c3 100644 --- a/src/config.json +++ b/src/config.json @@ -1,6 +1,6 @@ { "resolution_width": 1920, "framerate": 30, - "recording_length_seconds": 30, - "recording_interval_minutes": 1 -} \ No newline at end of file + "recording_length_seconds": 60, + "recording_interval_seconds": 30 +} diff --git a/src/util.py b/src/util.py index 17a590a..8c92834 100644 --- a/src/util.py +++ b/src/util.py @@ -9,7 +9,7 @@ class MulticamSettings: # Default settings recording_length_seconds: int = 30 - recording_interval_minutes: float = 20 + recording_interval_seconds: int = 60 framerate: int = 30 resolution_width: int = 1920 @@ -36,7 +36,7 @@ def example(): logging.info(f"Resolution: {multicam_settings.resolution_width}") logging.info(f"Framerate: {multicam_settings.framerate}") logging.info(f"Recording length (seconds): {multicam_settings.recording_length_seconds}") - logging.info(f"Recording interval (minutes): {multicam_settings.recording_interval_minutes}") + logging.info(f"Recording interval (seconds): {multicam_settings.recording_interval_seconds}") else: logging.info("Failed to load settings.")