summaryrefslogtreecommitdiff
path: root/Makefile
blob: 8bc2a2a1385271c36a0c257a8b54ee4e247b0326 (plain) (blame)
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
.POSIX:
NAME         = papo.im
NAME_UC      = $(NAME)
URL          = $(NAME)
TLD          = $(URL)
LIST         = list@$(URL)

OFFSITE_SSH  = 00000@aa0000.rsync.net



.SUFFIXES:
.SUFFIXES: .in .gpg .md .html

.in:
	sed \
		-e 's:@OFFSITE_SSH@:$(OFFSITE_SSH):g' \
		-e 's:@VERSION@:$(VERSION):g'         \
		-e 's:@DATE@:$(DATE):g'               \
		-e 's:@NAME@:$(NAME):g'               \
		-e 's:@LIST@:$(LIST):g'               \
		-e 's:@URL@:$(URL):g'                 \
		-e 's:@TLD@:$(TLD):g'                 \
		< $< > $@
	if [ -x $< ]; then chmod +x $@; fi

.gpg:
	gpg -d < $< > $@

.md.html:
	sh aux/commonmark.sh -N'$(NAME_UC)' -t$(*F) -l en < $< > $@



prod-secrets.txt.gpg = \
	src/secrets/borg-passphrase.txt.gpg    \
	src/secrets/root@$(TLD).id_rsa.txt.gpg \

all-secrets.txt.gpg = \
	$(prod-secrets.txt.gpg)       \
	src/secrets/rsync.net.txt.gpg \
	src/secrets/VPS-root.txt.gpg  \

prod-secrets.txt = $(prod-secrets.txt.gpg:.gpg=)
all-secrets.txt  =  $(all-secrets.txt.gpg:.gpg=)


derived-assets = \
	mkdir-public.sentinel       \
	system.sentinel             \
	public                      \
	aux/preamble.md             \
	CHANGELOG.html              \



all: $(derived-assets)

$(derived-assets) src/config/conf.env: Makefile


src/config/tld.txt: Makefile
	echo '$(TLD)' > $@

system.sentinel: src/guix/system.scm src/config/tld.txt src/config/conf.env \
		src/keys/SSH/root@$(URL).id_rsa.pub.stripped
	guix build -v3 -f src/guix/system.scm
	touch $@

.SUFFIXES: .stripped
src/keys/SSH/root@$(TLD).id_rsa.pub.stripped: \
		src/keys/SSH/root@$(TLD).id_rsa.pub.txt
	cut -d' ' -f8- < $*.txt > $@


## Run all tests.  Each test suite is isolated, so that a parallel
## build can run tests at the same time.  The required artifacts
## are created if required.
check:


clean:
	rm -rf $(derived-assets) $(all-secrets.txt)


mkdir-public.sentinel:
	mkdir -p public/
	touch $@

public/CHANGELOG.html: mkdir-public.sentinel CHANGELOG.html
	cp $(@F) $@

public/TODOs.html:
public/ci: mkdir-public.sentinel
	sh src/scripts/report.sh -o $@


## Generates the `public/` directory, which contains all static HTML files.
public: public/CHANGELOG.html public/TODOs.html public/ci

$(all-secrets.txt.gpg):
	gpg -ae `src/keys/gpg-recipients.sh` < $* > $@

## Import the GPG keys to allow encrypting secrets to them.
import:
	sh src/keys/gpg-import.sh


## Print the latest 500 lines of the application and keeps tailing it.
logs:
	ssh $(TLD) tail -n500 /var/log/$(NAME).log

## Print *all* logs available on the server.
all-logs:
	ssh $(TLD) \
		'gunzip -c /var/log/$(NAME).log.*; cat /var/log/$(NAME).log' | \
			sort


## Decrypt $(prod-secrets.txt) in `src/secrets/` and put them in their
## correct location in the server.
upload-secrets: $(prod-secrets.txt)
	ssh $(TLD) sudo -u secrets-keeper 'rm -f /opt/secrets/*'
	rsync \
		--rsync-path='sudo -u secrets-keeper rsync' \
		--chmod=000                                 \
		-avzP                                       \
		$(prod-secrets.txt) $(TLD):/opt/secrets/
	rm -f $(prod-secrets.txt)

## Generate the `.ssh/authorized_keys` file and upload it to $(OFFSITE_SSH).
upload-keys:
	cat src/keys/SSH/*.txt | \
		ssh $(OFFSITE_SSH) dd of=.ssh/authorized_keys

## Deploy everything that is deployable from the repository when
## open in the local development machine.
deploy: upload-secrets upload-keys
	@printf '\nRunning `git push` to update the deployment.\n'
	git push


MAKEFILE = Makefile
## Show this help.
help:
	cat $(MAKEFILE) | sh aux/makehelp.sh


ALWAYS: