#!/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 dependencies echo "Installing dependencies..." if ! pip install --user requests requests-mock pytest 2>&1 | tail -5; then echo "ERROR: pip install --user failed (PEP 668 externally-managed environment?)." echo "To install in a virtualenv instead, run:" echo " python3 -m venv ~/tools/coe-mirror/.venv" echo " source ~/tools/coe-mirror/.venv/bin/activate" echo " pip install requests requests-mock pytest" exit 1 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}"