summaryrefslogtreecommitdiff
path: root/Makefile
blob: c30e931d558206b04abe98c29620cc753f53aa62 (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
ifneq (0,$(shell id -u))
.DEFAULT_GOAL = install
%:
	sudo $(MAKE) -$(MAKEFLAGS) $@
else
config_dir = /etc/btrfs/remotes
bindir = /usr/local/bin
unitdir = /etc/systemd/system
main_unit_name = push-btrfs
remotes = $(notdir $(basename $(wildcard $(config_dir)/*.json)))
timers = $(addprefix $(main_unit_name)@, $(addsuffix .timer, $(remotes)))
services = $(addprefix $(main_unit_name)@, $(addsuffix .service, $(remotes)))
ifeq ($(remotes),)
$(error You must put at least one *.json configuration file into <file:///$(config_dir)>).
endif
enable_unit = $(main_unit_name).timer
unit_files = $(wildcard src/*.service src/*.timer)
plain_units = $(enable_unit) $(shell printf '%s\n' $(notdir $(unit_files)) | grep -v '@')
template_units = $(timers) $(services)
units = $(plain_units) $(template_units)
binaries = $(addprefix src/,push-btrfs retain-snapshots)



install:
	install -t $(bindir) -- $(binaries)
	install -m644 -t $(unitdir) -- $(unit_files)
	systemctl daemon-reload
	systemctl reset-failed $(units) 2>/dev/null || true
	systemctl enable --now $(enable_unit)

status start stop restart:
	systemctl $@ $(units)





go:
	for remote in $(remotes); do bash$(if $(verbose), -x) $(main_unit_name) $$remote$(if $(verbose),;, &) done; wait
endif