aboutsummarylogtreecommitdiffstats
path: root/0001-Makefile-Support-staged-installs-with-DESTDIR.patch
blob: cbdb66c8331e4bde7e3cff1ee3964b5e095214bb (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
From 2cc15262d098737a6c99475336b4a3861f5227f7 Mon Sep 17 00:00:00 2001
From: atom long <atom.long@hotmail.com>
Date: Tue, 7 Mar 2023 23:22:47 +0800
Subject: [PATCH 1/2] Makefile: Support staged installs with DESTDIR Use 
 `DESTDIR` in install related targets to support [*staged installs*][1].

    make DESTDIR=/tmp/stage install

[1]: https://www.gnu.org/software/make/manual/html_node/DESTDIR.html
---
 Makefile | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index 810601a..932eb3c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,9 @@
 CONF = freenom.conf
 SCRIPT = freenom.sh
-SYSDDIR = /lib/systemd/system
-CRONDIR = /etc/cron.d
-INSTDIR = /usr/local/bin
-CONFDIR = /usr/local/etc
+SYSDDIR = $(DESTDIR)/usr/lib/systemd/system
+CRONDIR = $(DESTDIR)/etc/cron.d
+INSTDIR = $(DESTDIR)/usr/local/bin
+CONFDIR = $(DESTDIR)/usr/local/etc
 
 ifneq ("$(shell grep ^staff: /etc/group)", "")
   GROUP = staff
@@ -11,9 +11,9 @@ else
   GROUP = root
 endif
 EXISTCRON = 0
-ifneq ("$(wildcard /run/systemd/system)", "")
+ifneq ("$(wildcard /usr/lib/systemd/system)", "")
   SCHED = systemd
-  LISTUNITS := $(shell systemctl list-unit-files --no-legend --no-page "freenom-*" 2>/dev/null|cut -d" " -f1)
+  LISTUNITS := $(shell ls $(SYSDDIR)/freenom-* 2>/dev/null)
 else ifneq ("$(shell which cron 2>/dev/null)", "")
   EXISTCRON = 1
   SCHED = cron
@@ -45,12 +45,14 @@ ifeq ("$(wildcard $(SCRIPT))","")
 	$(error ERROR: Installation File "$(SCRIPT)" not found)
 endif
 ifeq ("$(EXISTCONF)", "0")
+	$(shell mkdir -p $(CONFDIR))
 	$(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 mkdir -p $(INSTDIR))
 	$(shell install -C -m 755 -o root -g $(GROUP) $(SCRIPT) $(INSTDIR))
 else
 	$(info File "$(INSTDIR)/$(SCRIPT)" already exists)
@@ -63,7 +65,8 @@ ifeq ("$(SCHED)", "systemd")
   ifneq ("$(LISTUNITS)", "")
 	$(info Systemd unit files already installed)
   else
-	$(shell install -C -D -m 644 -o root -g root systemd/* $(SYSDDIR))
+	$(shell mkdir -p $(SYSDDIR))
+	$(shell install -C -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:)
@@ -77,7 +80,7 @@ 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)
+	$(shell install -C -D -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)
-- 
2.39.2