wireguard.lists.zx2c4.com archive mirror
 help / color / mirror / Atom feed
From: Calvin Ardi <calvin@isi.edu>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: WireGuard mailing list <wireguard@lists.zx2c4.com>
Subject: [PATCH] tools: Makefile modifies scripts to look in SYSCONFDIR if set (was Re: wireguard-tools: hard coded config paths in wg-quick)
Date: Fri, 20 Jul 2018 19:34:24 -0700	[thread overview]
Message-ID: <20180721023424.GK31263@isi.edu> (raw)
In-Reply-To: <CAHmME9rTmU6LTtadmDs__btxBC7S8K_GVKnn47F5TEZ6n3WF-Q@mail.gmail.com>

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

      reply	other threads:[~2018-07-21  2:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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   ` Calvin Ardi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180721023424.GK31263@isi.edu \
    --to=calvin@isi.edu \
    --cc=Jason@zx2c4.com \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).