autobackup_pick (764B)
1 #!/bin/sh 2 # Copyright 2023 Jacob R. Edwards <jacob@jacobedwards.org> 3 # Licensed under OpenBSD's ISC license; see LICENSE 4 # 5 # Pick mirror to backup to (used by autobackup_recieve). 6 # It outputs the oldest mirror. 7 8 printenv DEBUG >/dev/null && 9 set -x 10 11 get() { 12 awk -v host="$host" -v base="$base" \ 13 'host == $1 && $NF == "[0]" { 14 $1 = base 15 last = $0 16 } 17 18 END { 19 if (!last) 20 print base, " @ 0000-00-00 [0]" 21 else 22 print last 23 }' 24 } 25 26 host="${1:?no host}" 27 shift 28 29 for base in "${@:?no base directories}" 30 do 31 if ! test -d "$base"/mirrors 32 then 33 echo "warning: '$base' not setup as a mirror (lacks the mirrors directory)" 1>&2 34 elif ! test -f "$base"/mirrors/log 35 then 36 echo "$base 0000-00-00 [0]" 37 else 38 get < "$base"/mirrors/log 39 fi 40 done | sort -k3 | sed 's/ .*//;q'