From c031e08d71ece1fb2619b5f20723c33d730e4bba Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 6 Feb 2023 13:16:55 +0100 Subject: [PATCH] Add a default path for the config file --- Makefile | 13 +++++++++---- cmd/soju/main.go | 2 +- cmd/sojuctl/main.go | 2 +- config/config.go | 2 ++ 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 8d7d6a3..7cca0e0 100644 --- a/Makefile +++ b/Makefile @@ -5,13 +5,18 @@ GOFLAGS ?= PREFIX ?= /usr/local BINDIR ?= bin MANDIR ?= share/man +SYSCONFDIR ?= etc + +config_path := $(DESTDIR)/$(SYSCONFDIR)/soju/config +goflags := $(GOFLAGS) \ + -ldflags="-X 'git.sr.ht/~emersion/soju/config.DefaultPath=$(config_path)'" all: soju sojuctl doc/soju.1 soju: - $(GO) build $(GOFLAGS) ./cmd/soju + $(GO) build $(goflags) ./cmd/soju sojuctl: - $(GO) build $(GOFLAGS) ./cmd/sojuctl + $(GO) build $(goflags) ./cmd/sojuctl doc/soju.1: doc/soju.1.scd $(SCDOC) doc/soju.1 @@ -20,10 +25,10 @@ clean: install: mkdir -p $(DESTDIR)$(PREFIX)/$(BINDIR) mkdir -p $(DESTDIR)$(PREFIX)/$(MANDIR)/man1 - mkdir -p $(DESTDIR)/etc/soju + mkdir -p $(DESTDIR)/$(SYSCONFDIR)/soju mkdir -p $(DESTDIR)/var/lib/soju cp -f soju sojuctl $(DESTDIR)$(PREFIX)/$(BINDIR) cp -f doc/soju.1 $(DESTDIR)$(PREFIX)/$(MANDIR)/man1 - [ -f $(DESTDIR)/etc/soju/config ] || cp -f config.in $(DESTDIR)/etc/soju/config + [ -f $(config_path) ] || cp -f config.in $(config_path) .PHONY: soju sojuctl clean install diff --git a/cmd/soju/main.go b/cmd/soju/main.go index b2999d7..e8897ca 100644 --- a/cmd/soju/main.go +++ b/cmd/soju/main.go @@ -108,7 +108,7 @@ func loadConfig() (*config.Server, *soju.Config, error) { func main() { var listen []string flag.Var((*stringSliceFlag)(&listen), "listen", "listening address") - flag.StringVar(&configPath, "config", "", "path to configuration file") + flag.StringVar(&configPath, "config", config.DefaultPath, "path to configuration file") flag.BoolVar(&debug, "debug", false, "enable debug logging") flag.Parse() diff --git a/cmd/sojuctl/main.go b/cmd/sojuctl/main.go index e727c72..09308e3 100644 --- a/cmd/sojuctl/main.go +++ b/cmd/sojuctl/main.go @@ -31,7 +31,7 @@ func init() { func main() { var configPath string - flag.StringVar(&configPath, "config", "", "path to configuration file") + flag.StringVar(&configPath, "config", config.DefaultPath, "path to configuration file") flag.Parse() var cfg *config.Server diff --git a/config/config.go b/config/config.go index ee207b3..e3f9c7e 100644 --- a/config/config.go +++ b/config/config.go @@ -11,6 +11,8 @@ import ( "git.sr.ht/~emersion/go-scfg" ) +var DefaultPath string + type IPSet []*net.IPNet func (set IPSet) Contains(ip net.IP) bool {