This repository has been archived by the owner on Aug 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
82 lines (74 loc) · 2.28 KB
/
Makefile
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
BINDIR ?= /opt/adguard
CONFDIR ?= /etc/adguard
SYMLINK ?= /usr/local/sbin/dnsp
define setup_files
@$(1) -m744 dnsproxy-helper.sh $(2)
@$(1) -m744 dnsproxy-setup.sh $(2)
@$(1) -m644 dnsproxy.yml $(3)
endef
define service_files
@$(1)$(2) adguard-dnsproxy-setup.service $(3)
@$(1)$(2) adguard-dnsproxy-setup.timer $(3)
@$(1)$(2) adguard-dnsproxy.service $(3)
@$(1)systemctl daemon-reload
endef
all: install start
install:
ifneq ($(BINDIR), /opt/adguard)
ifeq ($(BINDIR), /usr/sbin)
$(error "That path is not allowed.")
endif
@$(foreach file,$(wildcard *.sh *.service),sed -i "s|/opt/adguard|$(BINDIR)|g" $(file);)
endif
ifneq ($(CONFDIR), /etc/adguard)
ifeq ($(CONFDIR), /etc)
$(error "That path is not allowed.")
endif
@$(foreach file,$(wildcard *.sh),sed -i "s|/etc/adguard|$(CONFDIR)|g" $(file);)
endif
ifeq ($(shell id -u), 0)
@mkdir -p $(BINDIR) $(CONFDIR)
$(call setup_files,install -p,$(BINDIR),$(CONFDIR))
$(call service_files,,install -p -m644,/etc/systemd/system)
@ln -sf $(BINDIR)/dnsproxy $(SYMLINK)
else
@sudo mkdir -p $(BINDIR) $(CONFDIR)
$(call setup_files,sudo install -p,$(BINDIR),$(CONFDIR))
$(call service_files,sudo ,install -p -m644,/etc/systemd/system)
@sudo ln -sf $(BINDIR)/dnsproxy $(SYMLINK)
endif
start:
ifeq ($(shell id -u), 0)
@systemctl enable --now adguard-dnsproxy-setup.service
@systemctl enable --now adguard-dnsproxy-setup.timer
ifneq ($(wildcard $(BINDIR)/dnsproxy),)
@systemctl enable --now adguard-dnsproxy.service
endif
else
@sudo systemctl enable --now adguard-dnsproxy-setup.service
@sudo systemctl enable --now adguard-dnsproxy-setup.timer
ifneq ($(wildcard $(BINDIR)/dnsproxy),)
@sudo systemctl enable --now adguard-dnsproxy.service
endif
endif
stop:
ifeq ($(shell id -u), 0)
@systemctl disable --now adguard-dnsproxy-setup.timer
@systemctl disable adguard-dnsproxy-setup.service
@systemctl disable --now adguard-dnsproxy.service
else
@sudo systemctl disable --now adguard-dnsproxy-setup.timer
@sudo systemctl disable adguard-dnsproxy-setup.service
@sudo systemctl disable --now adguard-dnsproxy.service
endif
uninstall: stop
ifeq ($(shell id -u), 0)
@rm -rf $(BINDIR) $(CONFDIR) $(SYMLINK)
$(call service_files,,rm -f)
else
@sudo rm -rf $(BINDIR) $(CONFDIR) $(SYMLINK)
$(call service_files,sudo ,rm -f)
endif
clean:
@git clean -df
@git checkout -- .