#!/bin/bash set -euo pipefail # Resolve paths TOOL_DIR="$HOME/tools/coe-mirror" PCLOUD_TARGET="$HOME/pCloudDrive/Hacking/Nightmare_Eclipse" PENDING_DIR="$HOME/.local/share/coe-mirror/pending" LOG_DIR="$HOME/.local/share/coe-mirror" USER_UNIT_DIR="$HOME/.config/systemd/user" # Check if pCloud mount exists (warning only, not fatal) if ! mountpoint -q "$HOME/pCloudDrive" 2>/dev/null; then echo "WARNING: pCloud mount not detected at ~/pCloudDrive — install will proceed but coe-mirror will queue everything locally until the mount appears." fi # Create directories mkdir -p "$PENDING_DIR" "$LOG_DIR" "$USER_UNIT_DIR" if mountpoint -q "$HOME/pCloudDrive" 2>/dev/null; then mkdir -p "$PCLOUD_TARGET" fi # Install runtime dependency (requests) if missing. Dev deps (pytest, requests-mock) # are only needed by the test suite — install them separately in a venv if you plan to test. if python3 -c "import requests" 2>/dev/null; then echo "Runtime dep 'requests' already importable system-wide; skipping pip install." else echo "Installing runtime dependency: requests" if ! pip install --user requests 2>&1 | tail -5; then echo "ERROR: pip install --user failed (PEP 668 externally-managed environment?)." echo "To install in a virtualenv instead:" echo " python3 -m venv $TOOL_DIR/.venv" echo " $TOOL_DIR/.venv/bin/pip install requests" echo " # then edit systemd/coe-mirror.service ExecStart to point at the venv python" exit 1 fi fi # Copy unit files cp "$TOOL_DIR/systemd/coe-mirror.service" "$USER_UNIT_DIR/" cp "$TOOL_DIR/systemd/coe-mirror.timer" "$USER_UNIT_DIR/" # Reload and enable systemctl --user daemon-reload systemctl --user enable --now coe-mirror.timer # Show next scheduled run echo "" echo "Next scheduled run:" systemctl --user list-timers coe-mirror.timer --no-pager | head -5 # Summary echo "" echo "=== Installation Summary ===" echo "Installed. Timer: coe-mirror.timer (enabled & active)." echo "pCloud target: $PCLOUD_TARGET (exists? $([ -d "$PCLOUD_TARGET" ] && echo "yes" || echo "no"))" echo "Pending dir: $PENDING_DIR" echo "Log: ~/.local/share/coe-mirror/coe-mirror.log" echo "" echo "To trigger immediately: systemctl --user start coe-mirror.service" echo "To uninstall: systemctl --user disable --now coe-mirror.timer && rm $USER_UNIT_DIR/coe-mirror.{service,timer}"