45a8d6163e
Standalone Python tool. Hits git.churchofmalware.org public API every
12h (00:00/12:00), downloads any repo HEAD whose SHA hasn't already
been snapshotted to pCloud, with local-staging fallback when the FUSE
mount is unavailable. Matrix notification stub for when the home
server is back.
Devil's-advocate findings folded into the design:
- shutil.copy2 + size verify + unlink, not os.rename, for FUSE safety
- no pCloud daemon auto-start (no user unit; DISPLAY=:0 unreliable);
relies on Persistent timer + pending flush for recovery
- two-call API path retained because the repo list response does not
include commit.sha
Audit-driven security fixes:
- repo names whitelist-validated (^[a-zA-Z0-9._-]+$)
- urllib.parse.quote on all interpolated URL segments
- same-file no-op guard in place_into_pcloud
- existence check moved to main() so cached files don't generate
spurious notify entries
13 pytest tests passing.
56 lines
2.0 KiB
Bash
56 lines
2.0 KiB
Bash
#!/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}"
|