summaryrefslogtreecommitdiff
path: root/.local/bin/setup
blob: b3e04c2401d4ba851a5f01f1d85b7012888ab2d8 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/make -f

HOME = $(shell cd "$(dir $(lastword $(MAKEFILE_LIST)))" && git rev-parse --show-toplevel)
export HOME
$(foreach v,$(filter XDG_%,$(.VARIABLES)),$(eval undefine $v))

LANG = C
export LANG
$(foreach v,$(filter LC_%,$(.VARIABLES)),$(eval undefine $v))

CFLAGS += -std=c99 -Wall -Wextra -Werror -Wno-unused-parameter

dirs = \
	$(HOME)/packages/pkgdest \
	$(HOME)/packages/srcdest \
	$(HOME)/packages/srcpkgdest \
	$(HOME)/packages/logdest \
	$(HOME)/packages/builddir

all: \
	$(HOME)/.local/bin/autobuild \
	$(HOME)/.ssh/id_rsa \
	$(HOME)/.ssh/id_rsa.pub \
	$(HOME)/.gnupg/private-keys-v1.d \
	$(HOME)/packages/abslibre \
	$(dirs)

$(HOME)/.local/bin/autobuild: %: %.c
	cd $(@D) && $(LINK.c) $(notdir $^) $(LOADLIBES) $(LDLIBS) -o $(@F) && chmod 6755 $(@F)

$(HOME)/.ssh/id_% $(HOME)/.ssh/id_%.pub:
	ssh-keygen -N '' -f $(@D)/id_$*

# We really don't want gpg `agent-socket` to be
# `${XDG_RUNTIME_DIR}/gnupg/S.gpg-agent` if `$(HOME) != $(shell echo
# ~$(USER))`.  So just adjust XDG_RUNTIME_DIR, right?  Nope!  GnuPG
# 2.2 willfully ignores XDG_RUNTIME_DIR and instead hard-codes the
# value that systemd sets XDG_RUNTIME_DIR to.
#
# However, if `$(GNUPGHOME) != $(HOME)/.gnupg`, then GnuPG will
# instead set `agent-socket` it to
# `${XDG_RUNTIME_DIR}/gnupg/d.XXXXXXXXXXXXXXXXXXXXXXXX/S.gpg-agent`
# where XXX is a hash of GNUPGHOME.  Perfect!  This is actually really
# robust behavior, that it should probably use all the time.
# Unfortunately, we need to set HOME to some BS value to trigger it.
#
# GnuPG: Broken by default™
$(HOME)/.gnupg/private-keys-v1.d: | $(HOME)/.config/git/config
	chmod 700 $(@D)
	printf '%s\n' \
		'Key-Type: default' \
		'Subkey-Type: default' \
		"Name-Real: $$(git config user.name)" \
		"Name-Email: $$(git config user.email)" \
		'Expire-Date: 0' \
		'%no-protection' \
		'%commit' \
	| HOME=/var/empty GNUPGHOME=$(HOME)/.gnupg gpg --gen-key --batch

$(HOME)/packages/abslibre:
	createworkdir

$(dirs): %:
	mkdir -p -- $@

.DELETE_ON_ERROR: