forked from mkorthof/freenom-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
104 lines (97 loc) · 2.77 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
CONF = freenom.conf
SCRIPT = freenom.sh
SYSDDIR = /etc/systemd/user
CRONDIR = /etc/cron.d
INSTDIR = /usr/local/bin
CONFDIR = /usr/local/etc
LISTUNITS := $(shell systemctl list-unit-files --no-legend --no-page "freenom-*" 2>/dev/null|cut -d" " -f1)
ifneq ("$(shell grep ^staff: /etc/group)", "")
GROUP = staff
else
GROUP = root
endif
ifneq ("$(LISTUNITS)", "")
SCHED = systemd
else ifneq ("$(wildcard $(CRONDIR))", "")
SCHED = cron
endif
EXISTCONF = 0
ifneq ("$(wildcard /etc/$(CONF))", "")
CONFDIR = /etc
EXISTCONF = 1
endif
ifneq ("$(wildcard $(CONFDIR)/$(CONF))", "")
EXISTCONF = 1
endif
.PHONY: all clean distclean install uninstall test
install:
ifeq ("$(wildcard $(CONF))","")
$(error ERROR: Installation File \"$(CONF)\" not found)
endif
ifeq ("$(wildcard $(SCRIPT))","")
$(error ERROR: Installation File \"$(SCRIPT)\" not found)
endif
ifeq ("$(EXISTCONF)", "0")
install -C -m 644 -o root -g root $(CONF) $(CONFDIR)
$(info Edit "$(CONFDIR)/$(CONF)" to set your email and password)
else
$(info File "$(CONFDIR)/$(CONF)" already exists)
endif
ifeq ("$(wildcard $(INSTDIR)/$(SCRIPT))","")
echo install -C -m 755 -o root -g $(GROUP) $(SCRIPT) $(INSTDIR)
else
$(info File "$(INSTDIR)/$(SCRIPT)" already exists)
endif
exit:
ifeq ("$(SCHED)", "systemd")
$(info )
ifeq ("$(wildcard systemd/*)","")
$(error ERROR: Installation directory and files \"systemd/*\" not found)
endif
install -C -D -m 644 -o root -g root systemd/* $(SYSDDIR)
systemctl daemon-reload
$(info To schedule domain renewals and updates, use these commands:)
$(info * systemd enable --now [email protected])
$(info * systemd enable --now [email protected])
$(info * systemd enable --now [email protected])
$(info )
$(info + replace example.tk with your domain)
$(info )
else ifeq ("$(SCHED)", "cron")
ifeq ("$(wildcard cron.d/freenom)","")
$(error ERROR: Installation File "cron.d/freenom/*" not found)
else
install -C -m 644 -o root -g root cron.d/freenom $(CRONDIR)/freenom
$(info )
$(info Edit "$(CRONDIR)/freenom" to schedule domain renewals and updates)
$(info * replace example.tk with your domain and uncomment line(s))
endif
$(info )
$(info See README.md for details)
$(info )
endif
uninstall:
ifeq ("$(EXISTCONF)","1")
rm $(CONFDIR)/$(CONF)
endif
ifneq ("$(wildcard $(INSTDIR)/$(SCRIPT))","")
rm $(INSTDIR)/$(SCRIPT)
endif
ifeq ("$(SCHED)", "systemd")
ifneq ("$(wildcard $(SYSDDIR)/freenom-*)","")
@systemctl disable $(LISTUNITS)
@cd systemd && for u in *; do \
if [ -n "$${u}" ] && [ -e "$(SYSDDIR)/$${u}" ]; then \
rm "${SYSDDIR}/$$u"; \
fi \
done
@systemctl daemon-reload
endif
else ifeq ("$(SCHED)", "cron")
ifneq ("$(wildcard $(CRONDIR)/freenom)","")
rm $(CRONDIR)/freenom
endif
endif
all: install
clean: uninstall
distclean: uninstall