summaryrefslogtreecommitdiff
path: root/Makefile
blob: e1af5a930f30e83ab3b12df100c9032aafe20781 (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
all: control equivs-stamp

ARCH := $(shell dpkg-architecture -q DEB_BUILD_ARCH)
ifndef VERSION
VERSION := $(shell TZ=UTC date -Is | tr -d :- | tr T . | sed 's/+.*//')
endif
export VERSION
PKG ?= $(notdir $(PWD))

PKG_FILE ?= $(PKG)_$(VERSION)_$(ARCH).deb
export PKG_FILE

$(PKG_FILE): control
	equivs-build control

equivs-stamp: control
	$(MAKE) $(PKG_FILE)
	$(MAKE) install-remove-equivs
	rm $(PKG_FILE)
	touch $@

.PHONY: install-remove-equivs
install-remove-equivs:
ifneq (0,$(shell id -u))
	sudo $(MAKE) PKG_FILE=$(PKG_FILE) MAKEFLAGS=$(MAKEFLAGS) $@
else
	dpkg -i $(PKG_FILE)
	f=$(PKG_FILE); dpkg -r $${f%%_*}
endif
#.

DD_USER = dyndns
DD_GROUP = dyndns

.PHONY: install all

install: equivs-stamp
ifneq ($(shell id -u),0)
	sudo $(MAKE) MAKEFLAGS=$(MAKEFLAGS) $@
else
	: apt install pdns
	getent passwd $(DD_USER) || useradd --system --create-home $(DD_USER)
	false
	chown root:$(DD_GROUP) /etc/powerdns
	chown pdns:$(DD_GROUP) /etc/powerdns/powerdns.sqlite3
	chmod g+rwx /etc/powerdns
	chmod g+rw /etc/powerdns/powerdns.sqlite3
	$(MAKE) ~$(DD_USER)/.ssh/authorized_keys
	install src/samizdat-ssh-command /usr/local/bin/
	install src/dyndns-command.sh ~$(DD_USER)/samizdat-default-command
endif

define dyndns_authorized_keys_contents
command="/usr/local/bin/samizdat-ssh-command /etc/powerdns/dyndns-command.sh",no-port-forwarding * Samizdat - YES WE CAN
endef

~$(DD_USER)/.ssh/authorized_keys:
	: writing file $@  $(file >$@,$(dyndns_authorized_keys_contents))

control: control.sh depends.control .git/refs/heads/master
	./control.sh depends.control > $@