wireguard-tools: hard coded config paths in wg-quick
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
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
PATCH 1/1 tools: Makefile modifies scripts to look in SYSCONFDIR if set (was Re: wireguard-tools: hard coded config paths in wg-quick)
Hi Jason,
Quoted 10 lines · Jason A. Donenfeld
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(+)
src/tools/Makefile +7 -0
@@ -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/[email protected] "$(DESTDIR)$(SYSTEMDUNITDIR)/[email protected]"
Signature · 1 line
2.18.0