~speguero/sirubo

ref: ece84fd1d0547c0a573cdd36f0ac22274af8fe1f sirubo/Makefile -rw-r--r-- 1.5 KiB
ece84fd1 — Steven Peguero makefile: use var to reference conf, detect dirs 6 months ago
                                                                                
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
fname_bin=sirubo
fpath_bin=/usr/local/bin/$(fname_bin)
dpath_conf=/usr/local/etc
fpath_conf=$(dpath_conf)/$(fname_bin).conf
fpath_ruleset=$(dpath_conf)/$(fname_bin).ruleset
fname_service_linux=$(fname_bin).service
fpath_service_linux=/etc/systemd/system/$(fname_bin).service
fpath_service_openbsd=/etc/rc.d/$(fname_bin)
dpath_doc=/usr/local/share/doc/$(fname_bin)
fpath_doc=/usr/local/share/doc/$(fname_bin)/README
os := $(shell uname -s)

install:

	@# Configuration

	if ! [ -d "$(dpath_conf)" ]; then \
		mkdir "$(dpath_conf)"; \
		chown 0:0 "$(dpath_conf)"; \
		chmod u=rwx,go=rx "$(dpath_conf)"; \
	fi

	touch "$(fpath_conf)"
	chown 0:0 "$(fpath_conf)"
	chmod u=rw,go= "$(fpath_conf)"

	@# Program
	
	cp -vf "$(fname_bin)" "$(fpath_bin)"
	chown 0:0 "$(fpath_bin)"
	chmod ugo=rx "$(fpath_bin)"

	@# Documentation

	if ! [ -d "$(dpath_doc)" ]; then \
		mkdir "$(dpath_doc)"; \
		chown 0:0 "$(dpath_doc)"; \
		chmod u=rwx,go=rx "$(dpath_doc)"; \
	fi

	cp -vf "README" "$(fpath_doc)"
	chown 0:0 "$(fpath_doc)"
	chmod ugo=r "$(fpath_doc)"

uninstall:

ifeq ($(os), Linux)
	-systemctl -q stop "$(fname_service_linux)"
	-systemctl -q disable "$(fname_service_linux)"
	systemctl -q daemon-reload
	-nft delete table inet "$(fname_bin)"
	rm -f "$(fpath_service_linux)"
endif

ifeq ($(os), OpenBSD)
	-rcctl disable "$(fname_bin)"
	-pfctl -a "$(fname_bin)" -F rules > /dev/null 2>&1
	rm -f "$(fpath_service_openbsd)"
endif

	rm -f "$(fpath_bin)"
	rm -rf "$(dpath_doc)"

clean: uninstall

	rm -f "$(fpath_conf)"
	-rm -f "$(fpath_ruleset)"
	-rm -f "$(fpath_ruleset).backup"