aboutsummaryrefslogtreecommitdiff
blob: 07463651b50112212068af324d3cf15828c45a46 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# Copyright 2014-2020 Gentoo Authors; Distributed under the GPL v2

DATADIR="/data/gmirror-distfiles"
LOGDIR="${DATADIR}/log"
RSYNC="/usr/bin/rsync"
RSYNC_ARGS="--no-motd --recursive --times --links --ignore-errors --timeout=300 --quiet"
RSYNC_ARGS_DELETE="--delete --delete-after"
[[ -d ${LOGDIR} ]] || mkdir ${LOGDIR}

# get the helper files
${RSYNC} ${RSYNC_ARGS} ${RSYNC_ARGS_DELETE} \
	woodpecker.gentoo.org::distfiles-local/ \
	${DATADIR}/distfiles-local
# Do NOT delete old whitelist entries; they must explicitly be set to empty if
# you want to remove them.
${RSYNC} ${RSYNC_ARGS} \
	woodpecker.gentoo.org::distfiles-whitelist/ \
	${DATADIR}/distfiles-whitelist
# Copy distfiles-local files to distfiles dir so that emirrordist can process
# them
# Do NOT --delete, let emirrordist handle the deletion logic
# TODO: we could make this a hardlink for speed?
${RSYNC} ${RSYNC_ARGS} \
	${DATADIR}/distfiles{-local/*,}

# build one master file due to bug 500030
cat $(/usr/bin/find ${DATADIR}/distfiles-whitelist -type f ) > \
	${DATADIR}/tmp/whitelist-master.txt

# Clear out the success/fail.log so that we can report on it
# (emirrordist appends)
> ${LOGDIR}/failure.log
if [[ $(/bin/date '+%k') -eq 0 ]]; then
	> ${LOGDIR}/success.log
fi

# human readable time format, 1814400 seconds equals 3 weeks
DELAY=1814400
# WARNING: This is sensitive to *DBM that is built with python
/usr/bin/emirrordist \
	--distfiles=${DATADIR}/distfiles/ \
	--delete --jobs=10 --repo=gentoo \
	--deletion-delay=${DELAY} \
	--failure-log=${LOGDIR}/failure.log \
	--success-log=${LOGDIR}/success.log \
	--scheduled-deletion-log=${LOGDIR}/deletion.log \
	--deletion-db=${LOGDIR}/deletion-db.gdbm \
	--distfiles-db=${LOGDIR}/distfile-db.gdbm \
	--recycle-db=${LOGDIR}/recycle-db.gdbm \
	--recycle-dir=${DATADIR}/distfiles-archive/ \
	--temp-dir=${DATADIR}/tmp/ \
	--whitelist-from=${DATADIR}/tmp/whitelist-master.txt \
	--distfiles-local=${DATADIR}/distfiles-local \
	--symlinks \
	--layout-conf=/usr/local/bin/mastermirror/layout.conf.new \
	--mirror

INDEXNAME=.INDEX.$(date -u +%Y%m%d%H%M%S).txt
INDEXFILE=${DATADIR}/${INDEXNAME}
( cd ${DATADIR}/distfiles && find [0-9a-f][0-9a-f] -mindepth 1 ) |
	sort >"${INDEXFILE}.tmp" && \
	mv "${INDEXFILE}.tmp" "${INDEXFILE}" && \
	ln -sf "${INDEXNAME}" "${DATADIR}"/INDEX && \
	find "$DATADIR" \
		-maxdepth 1 \
		-mindepth 1 \
		-name '.INDEX.*.txt' \
		! -mtime -7 \
		-delete

/bin/date -u '+%s' > ${DATADIR}/distfiles/timestamp.mirmon