This repository was archived by the owner on Jan 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathMakefile
148 lines (137 loc) · 4.35 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
CONF = freenom.conf
SCRIPT = freenom.sh
SYSDDIR = /lib/systemd/system
CRONDIR = /etc/cron.d
INSTDIR = /usr/local/bin
CONFDIR = /usr/local/etc
ifneq ("$(shell grep ^staff: /etc/group)", "")
GROUP = staff
else
GROUP = root
endif
EXISTCRON = 0
ifneq ("$(wildcard /run/systemd/system)", "")
SCHED = systemd
LISTUNITS := $(shell systemctl list-unit-files --no-legend --no-page "freenom-*" 2>/dev/null|cut -d" " -f1)
else ifneq ("$(shell which cron 2>/dev/null)", "")
EXISTCRON = 1
SCHED = cron
endif
ifeq ("$(SYSDDIR)", "")
ifeq ("$(EXISTCRON)", "1")
SCHED = cron
else
$(info No scheduler found (cron/systemd))
endif
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 docker
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")
$(shell install -C -m 644 -o root -g $(GROUP) $(CONF) $(CONFDIR))
$(info Remember to edit "$(CONF)" and set your email and password)
else
$(info File "$(CONFDIR)/$(CONF)" already exists)
endif
ifeq ("$(wildcard $(INSTDIR)/$(SCRIPT))","")
$(shell install -C -m 755 -o root -g $(GROUP) $(SCRIPT) $(INSTDIR))
else
$(info File "$(INSTDIR)/$(SCRIPT)" already exists)
endif
ifeq ("$(SCHED)", "systemd")
ifeq ("$(wildcard systemd/*)","")
$(error ERROR: Installation path "systemd/*" not found)
endif
ifneq ("$(LISTUNITS)", "")
$(info Systemd unit files already installed)
else
$(shell install -C -D -m 644 -o root -g root systemd/* $(SYSDDIR))
$(shell systemctl daemon-reload)
ifeq ("$(wildcard $(SYSDDIR)/freenom-*)","")
$(info To schedule domain renewals and updates, use these commands:)
$(info - systemctl enable --now freenom-renew-all.timer)
$(info - systemctl enable --now [email protected])
$(info - systemctl enable --now [email protected])
$(info $() $() * replace 'example.tk' and/or 'mysubdom' with your domain)
endif
endif
else ifeq ("$(SCHED)", "cron")
ifeq ("$(wildcard cron.d/freenom)","")
$(error ERROR: Installation path "cron.d/freenom/*" not found)
else
$(shell install -C -m 644 -o root -g root cron.d/freenom $(CRONDIR)/freenom)
$(info Edit "$(CRONDIR)/freenom" to schedule domain renewals and updates)
$(info $() $() * replace example.tk with your domain and uncomment line(s))
$(info See README.md for details)
endif
endif
uninstall:
ifeq ("$(EXISTCONF)","1")
$(shell rm $(CONFDIR)/$(CONF))
endif
ifneq ("$(wildcard $(INSTDIR)/$(SCRIPT))","")
$(shell rm $(INSTDIR)/$(SCRIPT))
endif
ifneq ("$(LISTUNITS)", "")
$(shell systemctl disable $(LISTUNITS))
endif
ifneq ("$(wildcard $(SYSDDIR)/freenom-*)","")
@cd systemd && for u in *; do \
if [ -n "$${u}" ] && [ -e "$(SYSDDIR)/$${u}" ]; then \
rm "${SYSDDIR}/$$u"; \
fi \
done
$(shell systemctl daemon-reload)
endif
ifneq ("$(wildcard $(CRONDIR)/freenom)","")
$(shell rm $(CRONDIR)/freenom)
endif
LABEL = \nLABEL org.opencontainers.image.source="https://github.com/mkorthof/freenom-script" \
\nLABEL org.opencontainers.image.description="Domain Renewal and DynDNS for Freenom.com"
define DOCKERFILE_DEBIAN
FROM debian:stable-slim \
$(if $(CI), $(LABEL))
ARG DEBIAN_FRONTEND=noninteractive
ARG DEBCONF_NOWARNINGS="yes"
COPY freenom.sh /usr/local/bin/
COPY freenom.conf /usr/local/etc/
RUN apt-get -yq update && apt-get -yq install --no-install-recommends curl ca-certificates bind9-dnsutils && rm -rf /var/lib/apt/lists/*
USER nobody
ENTRYPOINT [ "/usr/local/bin/freenom.sh" ]
endef
define DOCKERFILE_ALPINE
FROM alpine:latest \
$(if $(CI), $(LABEL))
COPY freenom.sh /usr/local/bin/
COPY freenom.conf /usr/local/etc/
RUN apk update && apk add --no-cache bash curl ca-certificates bind-tools
USER nobody
ENTRYPOINT [ "/usr/local/bin/freenom.sh" ]
endef
export DOCKERFILE_DEBIAN
export DOCKERFILE_ALPINE
docker:
ifeq ("$(wildcard $(CONF))","")
$(error ERROR: Installation File "$(CONF)" not found)
endif
ifeq ("$(wildcard $(SCRIPT))","")
$(error ERROR: Installation File "$(SCRIPT)" not found)
endif
@echo "$$DOCKERFILE_DEBIAN" | docker build -t freenom-script:latest -f- .
@echo "$$DOCKERFILE_ALPINE" | docker build -t freenom-script:alpine -f- .
all: install
clean: uninstall
distclean: uninstall