forked from markfeit/duplicacy-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
186 lines (146 loc) · 3.72 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#
# Makefie for Duplicacy Scripts
#
# Configure the following to taste.
# Suitable for general use:
# Root of backup
ROOT=/
# Where the scripts and data should be installed
DEST=/opt/duplicacy
# Suitable for experimentation in /tmp
#ROOT=/tmp
#DEST=/tmp/duplicacy-scripts
DUPLICACY_BINARY=duplicacy
DIST_CLEAN += $(DUPLICACY_BINARY)
# Where to link the binary for command-line use
BINARY_LINK=/usr/local/bin
# No user-serviceable parts below this point.
GIT_URL=https://github.com/markfeit/duplicacy-scripts.git
GIT_BRANCH=origin/master
BIN=$(DEST)/bin
ETC=$(DEST)/etc
LIB=$(DEST)/lib
PREFS=$(DEST)/prefs
VAR=$(DEST)/var
CACHE=$(VAR)/cache
HOLE=$(VAR)/hole
LOG=$(VAR)/log
UPDATE=$(VAR)/update
default:
@echo Nothing to do.
$(DEST):
mkdir -p $@
ROOT_LINK=$(DEST)/root
$(ROOT_LINK): $(DEST)
rm -f $@
ln -s "$(shell cd $(ROOT) && pwd -P)" $@
$(DEST)/%:
mkdir -p $@
# File that points Duplicacy at its local storage
LOCATION_FILE=$(ROOT)/.duplicacy
$(LOCATION_FILE): $(ROOT)
rm -f $@
echo "$(shell cd $(DEST)/prefs && pwd)" > $@
# Duplicacy binary.
$(BIN)/$(DUPLICACY_BINARY): $(DUPLICACY_BINARY) $(BIN)
rm -f $@
cp -fp $< $@
chmod 555 $@
if [ "$(DUPLICACY_BINARY)" != "duplicacy" ] ; \
then \
rm -f $@ ; \
ln -s $(DUPLICACY_BINARY) $@ ; \
fi
ifeq ($(TEST_BUILD),)
LINKED_BINARY=$(BINARY_LINK)/duplicacy
$(LINKED_BINARY): $(BIN)/$(DUPLICACY_BINARY)
if [ -w "$(BINARY_LINK)" ]; then rm -f $@ ; fi
if [ -w "$(BINARY_LINK)" ]; then ln -s $< $@ ; fi
endif
# Crontab
CRONTAB=$(LIB)/crontab
$(CRONTAB)::
mkdir -p $(LIB)
sed -e 's|__BIN__|$(BIN)|g' lib/crontab > $@
# Prime updating with a full copy of the sources unless we're already
# doing an update from that directory.
$(UPDATE)::
ifeq ($(NO_GIT),)
rm -rf $@
mkdir -p $@
cp -r $(shell ls -a | egrep -v -e '^(\.+|test)$$') $@
(cd "$@" && git remote set-url origin "$(GIT_URL)")
else
@true
endif
# If files in etc differ from what was installed, install them as
# *-upgrade and let the user sort it out.
install: clean \
$(BIN) $(BIN)/duplicacy \
$(ETC) \
$(LIB) \
$(CRONTAB) \
$(PREFS) \
$(LOCATION_FILE) \
$(LINKED_BINARY) \
$(CACHE) $(HOLE) $(LOG) $(UPDATE) \
$(ROOT_LINK)
cp -rfp bin/* $(BIN)
for FILE in etc/* ; \
do \
BASE=$$(basename "$${FILE}") ; \
if [ ! -e "$(ETC)/$${BASE}" ] ; \
then \
cp -fp "$${FILE}" "$(ETC)" ; \
else \
[ -e "$(ETC)/$${BASE}" ] \
&& diff "$${FILE}" "$(ETC)/$${BASE}" > /dev/null \
&& continue ; \
[ -e "$(ETC)/$$BASE" ] \
&& cp -fp "$${FILE}" "$(ETC)/$${BASE}-upgrade" \
|| cp -fp "$${FILE}" "$(ETC)" ; \
fi ; \
done
rm -rf "$(PREFS)/logs"
ln -s "../var/hole" "$(PREFS)/logs"
rm -rf "$(PREFS)/cache"
ln -s "../var/cache" "$(PREFS)/cache"
ifeq ($(TEST_BUILD),)
crontab -l | $(BIN)/crontab-install | crontab -
endif
# $(LINKED_BINARY) is a special case that gets handled in the
# uninstall target.
TO_UNINSTALL += $(BIN) $(LIB) $(LOCATION_FILE)
update:
git fetch
if [ $$(git diff $(GIT_BRANCH) | wc -l) -gt 0 ]; \
then \
git merge $(GIT_BRANCH) \
&& $(MAKE) NO_GIT=1 install ; \
fi
uninstall:
ifeq ($(TEST_BUILD),)
crontab -l | $(BIN)/crontab-remove | crontab -
endif
rm -rf $(TO_UNINSTALL)
if [ -w "$(BINARY_LINK)" ]; then rm -f "$(LINKED_BINARY)" ; fi
@echo "NOTE: Configuration, cache and logs were left in place."
# Install a test copy
TEST_DIR=test
TEST_DEST=$(TEST_DIR)/duplicacy
TEST_ROOT=$(TEST_DIR)/root
$(TEST_ROOT) $(TEST_DEST):
rm -rf $@
mkdir -p $@
test: $(TEST_ROOT) $(TEST_DEST)
$(MAKE) \
DEST=$(TEST_DEST) \
ROOT=$(TEST_ROOT) \
TEST_BUILD=1 \
install
TO_CLEAN += $(TEST_DIR) $(TEST_ROOT)
clean:
rm -rf $(TO_CLEAN)
find . -name "*~" | xargs rm -f
distclean: clean
rm -rf $(DIST_CLEAN)