#!/usr/bin/env bash set -euo pipefail # ====== CONFIG ====== # Pick a nearby Tier-1. Examples (use ONE): # rsync://mirror.csclub.uwaterloo.ca/archlinux/ # rsync://mirror.constant.com/archlinux/ UPSTREAM="${UPSTREAM:-rsync://masterdistfiles.gentoo.org/gentoo/}" # Local paths LIVE="${LIVE:-/brimstone2/mirror/gentoo}" # served path (symlink target) STAGE="${STAGE:-/brimstone3/mirror-stage/gentoo}" # staging path LOGDIR="${LOGDIR:-/var/log/mirrors}" LOCK="${LOCK:-/var/log/archmirror.lock}" # rsync knobs RSYNC_OPTS=( -rtlH --safe-links --delete-delay --delay-updates --partial --partial-dir=.rsync-partial --timeout=600 --contimeout=60 ) # Niceness (be kind to disks) IONICE=(ionice -c2 -n7) NICE=(nice -n 15) mkdir -p "$STAGE" "$LIVE" "$LOGDIR" exec 9>"$LOCK" flock -n 9 || { echo "[$(date -Is)] another archmirror-sync is running, exiting"; exit 0; } log() { echo "[$(date -Is)] $*"; } log "starting sync from $UPSTREAM" # First pass "${IONICE[@]}" "${NICE[@]}" rsync "${RSYNC_OPTS[@]}" \ "$UPSTREAM" "$STAGE" | tee -a "$LOGDIR/arch-sync.log" # Quick second pass to catch files updated mid-run "${IONICE[@]}" "${NICE[@]}" rsync "${RSYNC_OPTS[@]}" \ "$UPSTREAM" "$STAGE" | tee -a "$LOGDIR/arch-sync.log" # Atomic flip: make LIVE point at STAGE (symlink strategy) # If LIVE is a directory you want to replace, serve via a symlink path like /srv/mirror/arch -> /srv/mirror-stage/arch ln -sfn "$STAGE" "$LIVE" # Optional: write a local "lastsync" like Arch does, helps some clients date -u +%s > "$LIVE/lastsync" log "sync complete; flipped LIVE -> $STAGE"