#!/bin/bash # Setup auto-cleanup service for fetch_ml # This creates a systemd timer that runs cleanup daily set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_DIR="$(dirname "$SCRIPT_DIR")" # Colors GREEN='\033[0;32m' BLUE='\033[0;34m' NC='\033[0m' log_info() { echo -e "${BLUE}[INFO]${NC} $1" } log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } log_info "Setting up auto-cleanup service..." # Check if running on macOS or Linux if [[ "$OSTYPE" == "darwin"* ]]; then log_info "Detected macOS - setting up launchd agent" # Create launchd plist cat > ~/Library/LaunchAgents/com.fetchml.cleanup.plist << EOF Label com.fetchml.cleanup ProgramArguments $PROJECT_DIR/scripts/cleanup.sh --force StartInterval 86400 RunAtLoad StandardOutPath /tmp/fetchml-cleanup.log StandardErrorPath /tmp/fetchml-cleanup.error.log EOF # Load the launchd agent launchctl load ~/Library/LaunchAgents/com.fetchml.cleanup.plist log_success "Auto-cleanup service installed for macOS" log_info "Logs will be in /tmp/fetchml-cleanup.log" elif [[ "$OSTYPE" == "linux-gnu"* ]]; then log_info "Detected Linux - setting up systemd timer" # Copy service files sudo cp "$SCRIPT_DIR/auto-cleanup.service" /etc/systemd/system/ sudo cp "$SCRIPT_DIR/auto-cleanup.timer" /etc/systemd/system/ # Reload systemd and enable timer sudo systemctl daemon-reload sudo systemctl enable auto-cleanup.timer sudo systemctl start auto-cleanup.timer log_success "Auto-cleanup service installed for Linux" log_info "Check status with: systemctl status auto-cleanup.timer" else echo "Unsupported OS: $OSTYPE" exit 1 fi log_info "Auto-cleanup will run daily" log_info "To uninstall:" if [[ "$OSTYPE" == "darwin"* ]]; then echo " launchctl unload ~/Library/LaunchAgents/com.fetchml.cleanup.plist" echo " rm ~/Library/LaunchAgents/com.fetchml.cleanup.plist" else echo " sudo systemctl stop auto-cleanup.timer" echo " sudo systemctl disable auto-cleanup.timer" echo " sudo rm /etc/systemd/system/auto-cleanup.*" fi