#!/usr/bin/env bash # # GitTorrent Tracker cron-job -- GTP/0.1 # # This should run periodically to update the reference objects and prune # the peer lists of the repositories being tracked. # # The cron job should be given the path to the tracker root directory as # its only argument. ROOTDIR="$1" REPODIR="repo.git" TIMENOW="$(date "+%s")" TIMEAGE=1200 # 20 min. TIMECUT=$((TIMENOW - TIMEAGE)) # set -x cd "$ROOTDIR" || exit 1 for repo_hash in */; do repo_complete=0 repo_incomplete=0 [ -e "$repo_hash/stats.lock" ] && continue touch "$repo_hash/stats.lock" cd "$repo_hash" echo GIT_DIR="$REPODIR" cg update for peer_id in */; do # Skip the git repository [ "$peer_id" = "repo.git/" ] && continue # Prune old peers peer_age=$(stat -f "%m" "$peer_id/timestamp") if [ "$TIMECUT" -gt "$peer_age" ]; then rm -rf "$peer_id" continue fi # Update the stats if [ -e "$peer_id/complete" ]; then repo_complete=$((repo_complete + 1)) else repo_incomplete=$((repo_incomplete + 1)) fi done echo "8:completei${repo_complete}e10:incompletei${repo_incomplete}e" > stats.lock mv stats.lock stats cd .. done