summaryrefslogtreecommitdiff
path: root/gentoo-lastsync.sh
blob: e388c0e09e81457b40f8585ae2058f2526421921 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env bash
set -euo pipefail

# Upstream (Arch Geo CDN points to a Tier-1 close to you)
UPSTREAM="rsync://masterdistfiles.gentoo.org/gentoo/"

# Your mirror (the VIP that Arch probes)
MIRROR="https://stygian.failzero.net/mirror/gentoo/lastsync"

# Log file
LOGFILE="/var/log/mirrors/delay.log"
mkdir -p "$(dirname "$LOGFILE")"

# Fetch timestamps (seconds since epoch)
u=$(curl -fsS "$UPSTREAM" || echo 0)
m=$(curl -fsS "$MIRROR" || echo 0)

if [[ "$u" =~ ^[0-9]+$ && "$m" =~ ^[0-9]+$ ]]; then
    delay_min=$(( (u - m) / 60 ))
    echo "$(date -Is) upstream=$u mirror=$m delay=${delay_min}m" >> "$LOGFILE"
else
    echo "$(date -Is) error fetching lastsync" >> "$LOGFILE"

curl -fsS https://geo.mirror.pkgbuild.com/lastsync > "$LIVE/lastsync" \
  || date -u +%s > "$LIVE/lastsync"

fi