summaryrefslogtreecommitdiffstats
path: root/syncrepo
blob: ddc2cff5da47ae9f55d1aa9572b71c57bd5131a0 (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
28
29
30
31
#!/bin/bash

home="$(dirname "$(readlink -f $0)")"
target="${home}/repo"
tmp="${home}/tmp"
lock='/tmp/mirrorsync.lck'
source='pkgbuild.com::packages/'
repo_mtime_url="http://rsync.archlinux.org/repo_mtime"

[ ! -d "${target}" ] && mkdir -p "${target}"
[ ! -d "${tmp}" ] && mkdir -p "${tmp}"
[ -f "${lock}" ] && exit 1
touch "${lock}"
trap "rm -f '${lock}'" EXIT INT TERM

if diff -b <(curl -s "$repo_mtime_url") "$target/repo_mtime" >/dev/null; then
	exit 0
fi

rsync -rtlvH --safe-links --delete-after --progress -h \
	--delay-updates --no-motd --bwlimit=1000 \
	--temp-dir="${tmp}" \
	--exclude='*.links.tar.gz' \
	--exclude='*.old' \
	--exclude='/other' \
	--exclude='/sources' \
	--exclude='/iso' \
	${source} \
	"${target}"

echo "Last sync was $(date -d @$(cat ${target}/lastsync))"