[PATCH] tools: Makefile modifies scripts to look in SYSCONFDIR if set (was Re: wireguard-tools: hard coded config paths in wg-quick)

Calvin Ardi calvin at isi.edu
Sat Jul 21 04:34:24 CEST 2018


Hi Jason,

On Tue, Jun 26, 2018 at 01:49:56AM +0200, Jason A. Donenfeld wrote:
> Hi Calvin,
> 
> That's a good suggestion, and probably something best handled by a
> small sed or replacement command in the homebrew formula, where you
> invoke the "brew path" command. Would you like to implement this and
> CC @zx2c4 on the github PR?
> 
> Regards,
> Jason
> 

I use MacPorts, so I'm not familiar with Homebrew, although I wouldn't
mind taking a look at the Homebrew formula in the future.

I created a patch for the Makefile that will use sed to edit in-place
`wg-quick` and its bash completion during `make install` to reflect a
customized SYSCONFDIR, if set.

I originally edited the files prior to install, but I think it's
preferable (and perhaps cleaner?) to edit the files after they've been
installed (keeping the original source intact).

The resulting changes should work for both darwin and freebsd platforms.
It would be great if this (plus any needed changes) was merged upstream,
but I'm okay for it to exist as a patch in the respective Portfile or
formula.

Thanks,
--calvin

---
 src/tools/Makefile | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/tools/Makefile b/src/tools/Makefile
index a7cdaaa..0ac7fcf 100644
--- a/src/tools/Makefile
+++ b/src/tools/Makefile
@@ -16,6 +16,9 @@ WITH_BASHCOMPLETION ?=
 WITH_WGQUICK ?=
 WITH_SYSTEMDUNITS ?=
 
+# cross-platform sed for in-place editing
+SED := $(shell sed --version >/dev/null 2>&1 && echo "sed -i --" || echo "sed -i ''")
+
 ifeq ($(WITH_BASHCOMPLETION),)
 ifneq ($(strip $(wildcard $(BASHCOMPDIR))),)
 WITH_BASHCOMPLETION := yes
@@ -79,10 +82,14 @@ install: wg
 	install -v -d "$(DESTDIR)$(BASHCOMPDIR)" && install -v -m 0644 completion/wg.bash-completion "$(DESTDIR)$(BASHCOMPDIR)/wg"
 	@[ "$(WITH_WGQUICK)" = "yes" ] || exit 0; \
 	install -v -m 0755 wg-quick/$(PLATFORM).bash "$(DESTDIR)$(BINDIR)/wg-quick" && install -v -m 0700 -d "$(DESTDIR)$(SYSCONFDIR)/wireguard"
+	@[ "$(WITH_WGQUICK)" = "yes" -a "$(SYSCONFDIR)" != "/etc" ] || exit 0; \
+	$(SED) -e 's#^\(CONFIG_SEARCH_PATHS=.*\)\(/usr/local/etc\)#\1$(SYSCONFDIR)#' "$(DESTDIR)$(BINDIR)/wg-quick"
 	@[ "$(WITH_WGQUICK)" = "yes" ] || exit 0; \
 	install -v -m 0644 man/wg-quick.8 "$(DESTDIR)$(MANDIR)/man8/wg-quick.8"
 	@[ "$(WITH_WGQUICK)" = "yes" -a "$(WITH_BASHCOMPLETION)" = "yes" ] || exit 0; \
 	install -v -m 0644 completion/wg-quick.bash-completion "$(DESTDIR)$(BASHCOMPDIR)/wg-quick"
+	@[ "$(WITH_WGQUICK)" = "yes" -a "$(WITH_BASHCOMPLETION)" = "yes" -a "$(SYSCONFDIR)" != "/etc" ] || exit 0; \
+	$(SED) -e 's#\(search_paths+=.*\)\(/usr/local/etc\)#\1$(SYSCONFDIR)#' "$(DESTDIR)$(BASHCOMPDIR)/wg-quick"
 	@[ "$(WITH_WGQUICK)" = "yes" -a "$(WITH_SYSTEMDUNITS)" = "yes" ] || exit 0; \
 	install -v -d "$(DESTDIR)$(SYSTEMDUNITDIR)" && install -v -m 0644 systemd/wg-quick at .service "$(DESTDIR)$(SYSTEMDUNITDIR)/wg-quick at .service"
 
-- 
2.18.0


More information about the WireGuard mailing list