aboutsummaryrefslogtreecommitdiffstats
path: root/ssh/Makefile
blob: be4b0d51005306330209f26ef765362919a3a5d5 (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
.POSIX:

DYNAMIC_ADDRESSES != \
	for f in ../.secrets/ssh/hostfetch/* ../.work/ssh/hostfetch/* hostfetch/*; do \
		test ! -x "$$f" || printf '%s\n' "$$f"; \
	done | sort -u | sed -n 's|^.*/\([^/]*[^/~]\)$$|\1|p'

install:
	-rm -f -- .ssh-config
	test ! -e .ssh-config && test ! -L .ssh-config
	printf '# %s\n' 'THIS FILE IS GENERATED from ~/.dotfiles/ssh/Makefile' \
	                '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' > .ssh-config
	chmod -- 600 .ssh-config
	if test -f config; then \
		../cat-with-head -- config >> .ssh-config; \
	fi
	set config.d/* && if test -f "$$1"; then \
		../cat-nonbackups-with-head -- "$$@" >> .ssh-config; \
	fi
	if test -f ../.secrets/ssh/config; then \
		../cat-with-head -- ../.secrets/ssh/config >> .ssh-config; \
	fi
	set ../.secrets/ssh/config.d/* && if test -f "$$1"; then \
		../cat-nonbackups-with-head -- "$$@" >> .ssh-config; \
	fi
	if test -f ../.work/ssh/config; then \
		../cat-with-head -- ../.work/ssh/config >> .ssh-config; \
	fi
	set ../.work/ssh/config.d/* && if test -f "$$1"; then \
		../cat-nonbackups-with-head -- "$$@" >> .ssh-config; \
	fi
	set -e; \
	for name in $(DYNAMIC_ADDRESSES); do \
		if test -x "../.secrets/ssh/hostfetch/$$name"; then \
			addr="$$("../.secrets/ssh/hostfetch/$$name")"; \
		elif test -x "../.work/ssh/hostfetch/$$name"; then \
			addr="$$("../.work/ssh/hostfetch/$$name")"; \
		else \
			addr="$$("hostfetch/$$name")"; \
		fi; \
		test -n "$$addr"; \
		sed "s/%$${name}%/$${addr}/g" -- "$$@" < .ssh-config > .ssh-config~; \
		mv -- .ssh-config~ .ssh-config; \
	done
	mkdir -p -- ~/.ssh
	test ! -e ~/.ssh/config || test -L ~/.ssh/config
	test ! -e ~/.ssh/config || test -f ~/.ssh/config
	ln -sf -- ~/.dotfiles/ssh/.ssh-config ~/.ssh/config
	set ~/.dotfiles/.secrets/ssh/keys/* && if test -f "$$1"; then \
		ln -sf -- "$$@" ~/.ssh/; \
	fi
	set ~/.dotfiles/.work/ssh/keys/* && if test -f "$$1"; then \
		ln -sf -- "$$@" ~/.ssh/; \
	fi
	mkdir -p -- ~/.config/bash/aliases.d
	test ! -e ~/.config/bash/aliases.d/openssh || test -L ~/.config/bash/aliases.d/openssh
	ln -sf -- ~/.dotfiles/openssh/bash-aliases ~/.config/bash/aliases.d/openssh

uninstall:
	+! ../check-installed ssh
	+! ../check-installed openssh
	-unlink -- ~/.ssh/config
	-unlink -- ~/.ssh/known_hosts
	-unlink -- ~/.ssh/known_hosts.old
	-cd ../.work/ssh/keys/ && set * && if test -f "$$1"; then \
		cd ~/.ssh/ && \
		rm -f -- "$$@"; \
	fi
	-rmdir -- ~/.ssh
	-rm -f -- .ssh-config
	-unlink -- ~/.config/bash/aliases.d/openssh
	-rmdir -- ~/.config/bash/aliases.d