summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 154fb7a8e680c553882386d7ee2f01690f0f8f5a (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
all: deploy

tv-cluster := cd mkdir nomic rmdir wu
deploy-cd:; ./deploy cd
deploy-mkdir:; ./deploy mkdir
deploy-nomic:; ./deploy nomic root@nomic-local
deploy-rmdir:; ./deploy rmdir
deploy-wu:; ./deploy wu root@localhost

ifndef cluster
cluster := $(LOGNAME)
endif
hosts := $($(cluster)-cluster)
ifeq ($(hosts),)
$(error bad cluster: $(cluster))
else
.ONESHELL:

.PHONY: deploy $(addprefix deploy-,$(hosts))
deploy:
	exec parallel \
		-j 0 \
		--no-notice \
		--rpl '{u} s/^.* deploy-(.*)/\1/' \
		--tagstring '{u}' \
		--line-buffer \
		$(MAKE) deploy-{} ::: $(hosts)

.PHONY: rotate-consul-encrypt
rotate-consul-encrypt:
	umask 0377
	mkencrypt() { dd status=none if=/dev/random bs=1 count=16 | base64; }
	json=$$(printf '{"encrypt":"%s"}\n' $$(mkencrypt))
	cmd='
		f=secrets/{}/rsync/etc/consul/encrypt.json
		rm -f "$$f"
		echo "$$json" > "$$f"
	'
	export json
	exec parallel \
		-j 0 \
		--no-notice \
		--rpl '{u} s/^.* deploy-(.*)/\1/' \
		--tagstring '{u}' \
		--line-buffer \
		--quote \
		sh -eufc "$$cmd" ::: $(hosts)
endif