-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
80 lines (62 loc) · 1.93 KB
/
Makefile
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
73
74
75
76
77
78
79
80
.SUFFIXES:
.PHONY: FORCE
.DELETE_ON_ERROR:
PATH:=/usr/bin:/bin
SHELL:=/bin/bash -o pipefail
# TODAY: today's date, YYYY-MM-DD
TODAY:=$(shell date +%Y/%m/%d)
UPDIR:=${TODAY}.tmp
#_:=$(shell mkdir -p ${UPDIR})
DIR:=$(abspath $(dir $(firstword $(MAKEFILE_LIST))))
# LATEST: most recently *completed* sync directory, if any
# if LATEST is not empty (i.e., a prior directory exists), then use
# LATEST as a hard link source to save bandwidth and local space
# Hmm... why can't I just use the latest symlink here?
LATEST:=$(lastword $(sort $(filter-out %.tmp,$(wildcard 201[0-9]/[0-9][0-9]/[0-9][0-9]))))
ifneq ("${TODAY}","")
RSYNC_LINK_DEST=--link-dest=${DIR}/${LATEST}
endif
default:
@echo "Ain't no $@ target; try 'make update'" 1>&2; exit 1
vars:
@echo TODAY=${TODAY}
@echo DIR=${DIR}
@echo UPDIR=${UPDIR}
@echo LATEST=${LATEST}
@echo RSYNC_LINK_DEST=${RSYNC_LINK_DEST}
update: ${TODAY}/log;
${TODAY}/log: ${UPDIR}/log
if [ -d "${TODAY}" ]; then chmod -R u+wX ${TODAY}; rm -fr "${TODAY}"; fi
mv ${UPDIR} ${TODAY}
ln -fnsv ${TODAY} latest
.PRECIOUS: ${UPDIR}/log
${UPDIR}/log: sources vars FORCE
@if [ -d "${TODAY}" ]; then \
echo "${TODAY}/: Directory exists -- already completed?" 1>&2; \
exit 1; \
fi
@mkdir -pv ${UPDIR}
@( \
set -e; \
perl -lne 'next if m/^\#/ or not m/\w/; s/\n/ /; print' <$< \
| while read f; do \
(set -x; stdbuf -o0 -e0 rsync --no-motd -HRavP ${RSYNC_LINK_DEST}/$${f%%/*} ftp.ncbi.nlm.nih.gov::$$f ${UPDIR}/$${f%%/*} 2>&1) \
done; \
) >$@
.PHONY: _rsync_not_running
_rsync_not_running:
ps -ef | grep 'rsync.*ncbi' >/dev/null
.PHONY: cleanup
cleanup: cleanup.log
cleanup.log: _rsync_not_running FORCE
(make fix-perms; make remove-temps; make hardlink) >$@ 2>&1
fix-perms:
find 201? -type d -print0 | xargs -0r chmod -c u+rwX,go+rX,go-w
remove-temps:
find 201? -name \*tmp\* -type d -print0 | xargs -0r /bin/rm -fr
hardlink:
(set -x; \
df -h .; \
hardlink -vfptoO .; \
df -h . \
) 2>&1 | tee $@.log