wireguard.lists.zx2c4.com archive mirror
 help / color / mirror / Atom feed
* wireguard-tools: hard coded config paths in wg-quick
@ 2018-06-24 15:51 Calvin Ardi
  2018-06-25 23:49 ` Jason A. Donenfeld
  0 siblings, 1 reply; 3+ messages in thread
From: Calvin Ardi @ 2018-06-24 15:51 UTC (permalink / raw)
  To: wireguard

Hi,

The wg-quick bash scripts have their CONFIG_SEARCH_PATHS hard coded to
two locations [1]:

  CONFIG_SEARCH_PATHS=( /etc/wireguard /usr/local/etc/wireguard )

In my use case with MacPorts (and perhaps with Homebrew, if customized
differently), mostly everything lives in /opt/local by default, so users
would initially add their configs to /opt/local/etc/wireguard.

Since the Makefile supports setting and using SYSCONFDIR [2, 3], I
suggest that the CONFIG_SEARCH_PATHS have the value of SYSCONFDIR added
to it--I don't know of a "clean" way to do this besides patching the
scripts in the Makefile during the `make install'

More than happy to help with a patch (creating, testing, or otherwise).

Thanks,
--calvin

[1] https://git.zx2c4.com/WireGuard/tree/src/tools/wg-quick/darwin.bash#n43
[2] https://git.zx2c4.com/WireGuard/tree/src/tools/Makefile#n8
[3] https://git.zx2c4.com/WireGuard/tree/src/tools/Makefile#n81

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: wireguard-tools: hard coded config paths in wg-quick
  2018-06-24 15:51 wireguard-tools: hard coded config paths in wg-quick Calvin Ardi
@ 2018-06-25 23:49 ` Jason A. Donenfeld
  2018-07-21  2:34   ` [PATCH] tools: Makefile modifies scripts to look in SYSCONFDIR if set (was Re: wireguard-tools: hard coded config paths in wg-quick) Calvin Ardi
  0 siblings, 1 reply; 3+ messages in thread
From: Jason A. Donenfeld @ 2018-06-25 23:49 UTC (permalink / raw)
  To: calvin; +Cc: WireGuard mailing list

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] tools: Makefile modifies scripts to look in SYSCONFDIR if set (was Re: wireguard-tools: hard coded config paths in wg-quick)
  2018-06-25 23:49 ` Jason A. Donenfeld
@ 2018-07-21  2:34   ` Calvin Ardi
  0 siblings, 0 replies; 3+ messages in thread
From: Calvin Ardi @ 2018-07-21  2:34 UTC (permalink / raw)
  To: Jason A. Donenfeld; +Cc: WireGuard mailing list

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@.service "$(DESTDIR)$(SYSTEMDUNITDIR)/wg-quick@.service"
 
-- 
2.18.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-07-21  2:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-24 15:51 wireguard-tools: hard coded config paths in wg-quick Calvin Ardi
2018-06-25 23:49 ` Jason A. Donenfeld
2018-07-21  2:34   ` [PATCH] tools: Makefile modifies scripts to look in SYSCONFDIR if set (was Re: wireguard-tools: hard coded config paths in wg-quick) Calvin Ardi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).