From e6360fe304fb49dcca4f09028a033eb14d65e887 Mon Sep 17 00:00:00 2001 From: atomlong Date: Tue, 14 Sep 2021 15:07:39 +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 6c1dafc..79b19ed 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,14 +11,14 @@ else GROUP = root endif EXISTCRON = 0 -ifneq ("$(wildcard /run/systemd/system)", "") +ifneq ("$(wildcard /usr/lib/systemd/system)", "") SCHED = systemd # ifneq ("$(wildcard /usr/lib/systemd/system)","") # SYSDDIR = /lib/systemd/system # else ifneq ("$(wildcard /lib/systemd/system)","") # SYSDDIR = /usr/lib/systemd/system # endif - 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 @@ -50,12 +50,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) @@ -68,7 +70,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:) @@ -82,7 +85,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.33.0.windows.2