diff options
author | Erich Eckner <git@eckner.net> | 2020-04-23 15:47:20 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2020-04-23 15:47:20 +0200 |
commit | ec1281b7f2070f257d9e2d7c0ae972e3368b0f55 (patch) | |
tree | e7a85393826f8e5f9d82183161ac5b09acd89bcd | |
download | arch-mirror-ec1281b7f2070f257d9e2d7c0ae972e3368b0f55.tar.xz |
initial commit
-rwxr-xr-x | arch-spiegeln | 138 | ||||
-rw-r--r-- | arch-spiegeln.conf.example | 13 | ||||
-rw-r--r-- | arch-spiegeln.service | 8 | ||||
-rw-r--r-- | arch-spiegeln.timer | 10 | ||||
-rw-r--r-- | sync.php | 9 |
5 files changed, 178 insertions, 0 deletions
diff --git a/arch-spiegeln b/arch-spiegeln new file mode 100755 index 0000000..31fe055 --- /dev/null +++ b/arch-spiegeln @@ -0,0 +1,138 @@ +#!/bin/bash + +#if [ "$(whoami)" != 'http' ]; then +# exec su http -s /bin/bash -c "$0" +#fi + +mirror_dir='/srv/http/arch' +mirror_dir='/tmp' + +upstream_mirrors=( + 'rsync://jeti100.ioq.uni-jena.de/archlinux-all/' + '/archlinux/#rsync://ftp.gwdg.de/pub/linux/archlinux/' + '/archlinuxarm/#rsync://ftp.halifax.rwth-aachen.de/archlinux-arm/' +) + +close_mirrors=( + 'arch.eckner.net' +) + +[ -r '/etc/arch-spiegeln.conf' ] \ +&& . '/etc/arch-spiegeln.conf' + +mkdir -p "${mirror_dir}/.locks" +exec 9> "${mirror_dir}/.locks/arch-spiegeln.lock" +flock -n 9 || exit 0 + +if ! stty &>/dev/null; then + quiet="-q" +fi + +#rsync_sources=( +# $( +# $lastsync $url $vollständig $basis $lokalität (kleiner=lokaler) + { + printf '%s ME 1 / 0\n' $( + cat "${mirror_dir}/lastsync" + ) + for close_mirror in "${close_mirrors[@]}"; do + { + dig +short "${close_mirror}" A \ + | grep -x '[0-9]\+\(\.[0-9]\+\)\{3\}' + dig +short "${close_mirror}" AAAA \ + | grep -x '[0-9a-f:]\+' + } \ + | while read -r addr; do + printf '%s %s 1 / 1\n' \ + $( + curl -Ss --resolve "${close_mirror}:443:${addr}" \ + "https://${close_mirror}/lastsync" + ) \ + $( + printf '%s\n' "${addr}" \ + | sed ' + s/^[0-9a-f:]\+$/[\0]/ + s@^\S\+$@rsync://\0/archlinux/@ + ' + ) + done + done + for upstream_mirror in "${upstream_mirrors[@]}"; do + if [ -n "${upstream_mirror%%*#*}" ]; then + basis='/' + else + basis="${upstream_mirror%%#*}" + upstream_mirror="${upstream_mirror#${basis}#}" + fi + tmp_file=$(mktemp) + if ! rsync "${upstream_mirror}lastsync" "${tmp_file}" 2>/dev/null; then + if [ -z "${upstream_mirror##*archlinux*arm*}" ]; then + date +%s >"${tmp_file}" + else + continue + fi + fi + printf '%s %s 1 %s 2\n' \ + $( + cat "${tmp_file}" + ) \ + "${upstream_mirror}" \ + "${basis}" + rm "${tmp_file}" + done + curl -Ss 'https://www.archlinux.org/mirrors/status/json/' \ + | sed -n ' + s@^[^[]*"urls": \[@@ + T + s@][^[]*$@@ + T + p + ' \ + | sed ' + s/}, {/},\n{/g + ' \ + | grep -F '"protocol": "rsync"' \ + | { + date -u +'%FT%TZ CUTCUTCUT' -d@$(($(date +%s)-3600)) + sed ' + s@^.*, "last_sync": "\([^"]\+\)",.*$@\1 \0@ + ' + } \ + | sort -k1r,1 \ + | sed ' + / CUTCUTCUT/,$ d + s@^\S\+ {"url": "\([^"]\+\)".*$@\1 0 /archlinux/ 2@ + t + d + ' \ + | shuf -n10 >/dev/null + } \ + | sort -k1n,1 -k5n,5 -k3nr,3 \ + | uniq --group=append -f2 \ + | sed -n ' + N + s/\n$// + t ok + D + b + :ok + p + ' \ + | while read -r _ url vollst basis lokal; do + echo "$url $vollst $basis $lokal" + done +# ) +#) + +#printf '%s\n' "${rsync_sources[@]}" +exit + +for rsync_source in "${rsync_sources[@]}"; do + + rsync -rtlvH --safe-links --delete-after --progress -h ${quiet} --timeout=600 --contimeout=60 -p \ + --delay-updates --no-motd --temp-dir=/srv/http/.tmp \ + --exclude .tmp \ + "${rsync_source}" \ + '/srv/http/arch/' + +done diff --git a/arch-spiegeln.conf.example b/arch-spiegeln.conf.example new file mode 100644 index 0000000..8147c95 --- /dev/null +++ b/arch-spiegeln.conf.example @@ -0,0 +1,13 @@ +#!/bin/bash + +mirror_dir='/srv/http/arch' + +# complete upstream mirrors +upstream_mirrors=( + 'rsync://jeti100.ioq.uni-jena.de/archlinux-all/' +) + +# geographically close mirrors identical to ours +close_mirrors=( + 'arch.eckner.net' +) diff --git a/arch-spiegeln.service b/arch-spiegeln.service new file mode 100644 index 0000000..52ba7e7 --- /dev/null +++ b/arch-spiegeln.service @@ -0,0 +1,8 @@ +[Unit] +Description=update arch mirror +JoinsNamespaceOf=php-fpm.service + +[Service] +PrivateTmp=True +User=http +ExecStart=/usr/bin/arch-spiegeln diff --git a/arch-spiegeln.timer b/arch-spiegeln.timer new file mode 100644 index 0000000..600a27a --- /dev/null +++ b/arch-spiegeln.timer @@ -0,0 +1,10 @@ +[Unit] +Description=repeatedly update arch mirror + +[Timer] +AccuracySec=1us +RandomizedDelaySec=10min +OnCalendar=*-*-* *:00/10:00 + +[Install] +WantedBy=timers.target diff --git a/sync.php b/sync.php new file mode 100644 index 0000000..751dcf7 --- /dev/null +++ b/sync.php @@ -0,0 +1,9 @@ +<?php + +exec('screen -d -m /usr/bin/arch-spiegeln'); + +$f = fopen('/srv/http/arch/lastsync','r'); +$s = trim(fgets($f)); +fclose($f); + +print 'Mirror update initiated. (Last update was at ' . date('c', $s) . ')' . "\n"; |