#!/bin/bash
#
# Slackware repository sync script
# Syncs Slackware 15.0 and current for all architectures
#

set -e

# ---- CONFIG ----
#MIRROR="rsync://mirrors.slackware.com/slackware"
MIRROR="rsync://slackware.cs.utah.edu/slackware"
BASE="/srv/repo/slackware"
LOGDIR="$BASE/logs"
DATE="$(date '+%Y-%m-%d %H:%M:%S')"

RSYNC_OPTS="-av --delete --numeric-ids --delete-delay"

REPOS=(
  "slackware-15.0"
  "slackware64-15.0"
  "slackwarearm-15.0"
  "slackwareaarch64-15.0"
  "slackware-current"
  "slackware64-current"
  "slackwarearm-current"
  "slackwareaarch64-current"
)

# ---- INIT ----
mkdir -p "$LOGDIR"

echo "[$DATE] Starting Slackware repo sync" | tee -a "$LOGDIR/sync.log"

# ---- SYNC LOOP ----
for repo in "${REPOS[@]}"; do
    echo "[$(date '+%Y-%m-%d %H:%M:%S')] Syncing $repo" | tee -a "$LOGDIR/sync.log"

    rsync $RSYNC_OPTS \
        "$MIRROR/$repo/" \
        "$BASE/$repo/" \
        >> "$LOGDIR/$repo.log" 2>&1

    echo "[$(date '+%Y-%m-%d %H:%M:%S')] Finished $repo" | tee -a "$LOGDIR/sync.log"
done

echo "[$(date '+%Y-%m-%d %H:%M:%S')] All syncs completed" | tee -a "$LOGDIR/sync.log"
